spike.motorpair
Motor pair mock API
Classes
|
MotorPair mocking class |
- class spike.motorpair.MotorPair(left_port, right_port)
MotorPair mocking class
Class is accessed simultaneously by the user side thread and the ground truth update thread. It is therefore protected by a mutex
- __init__(left_port, right_port)
Contructor
- Parameters:
left_port (string ('A','B','C','D','E' or 'F')) – The port on which the left motor is located
right_port (string ('A','B','C','D','E' or 'F')) – The port on which the right motor is located
- move(amount, unit='cm', steering=0, speed=None)
Start both motors simultaneously to move a Driving Base.
Steering = “0” makes the Driving Base go straight. Negative numbers make the Driving Base turn left. Positive numbers make the Driving Base turn right.
The program will not continue until the specified value is reached.
If the value of steering is equal to “-100” or “100,” the Driving Base will perform a rotation on itself (i.e., “tank move”) at the default speed of each motor.
If the value of steering is outside of the allowed range, the value will be set to “-100” or “100,” depending on whether the value is positive or negative.
If speed is outside of the allowed range, the value will be set to “-100” or “100,” depending on whether the value is positive or negative.
If the speed is negative, the Driving Base will move backward instead of forward. Likewise, if the “amount” is negative, the Driving Base will move backward instead of forward. If both the speed and the “amount” are negative, the Driving Base will move forward.
When the specified unit is “cm” or “in,” the “amount” of the unit parameter is equal to the horizontal distance that the Driving Base will travel before stopping. The relationship between the motor rotations and distance traveled can be adjusted by calling set_motor_rotation().
When the “unit” is “rotations” or “degrees,” the “amount” parameter value specifies how much the motor axle will turn before stopping.
When the “unit” is “seconds,” the “amount” parameter value specifies the duration that the motors will run before stopping.
- Parameters:
amount (float) – The quantity to move in relation to the specified unit of measurement.
unit (string (cm,in,rotations,degrees,seconds)) – The unit of measurement specified for the “amount” parameter.
speed (int [-100,100]) – The speed at which the Driving Base will move while performing a curve.
steering (int [-100,100]) – The steering direction (-100 to 100). “0” makes the Driving Base move straight. Negative numbers make the Driving Base turn left. Positive numbers make the Driving Base turn right.
- Raises:
TypeError – amount, left_speed or right_speed is not a number or unit is not a string.
ValueError – unit is not one of the allowed values.
- start(steering=0, speed=None)
Start both motors simultaneously to move a Driving Base.
Steering = “0” makes the Driving Base go straight. Negative numbers make the Driving Base turn left. Positive numbers make the Driving Base turn right.
The program flow is not interrupted. This is most likely interrupted by sensor input and a condition.
If the value of steering is equal to “-100” or “100,” the Driving Base will perform a rotation on itself (i.e., “tank move”) at the default speed of each motor.
If the value of “steering” is outside of the allowed range, the value will be set to “-100” or “100,” depending on whether the value is positive or negative.
If speed is outside of the allowed range, the value will be set to “-100” or “100,” depending on whether the value is positive or negative.
If the speed is negative, the Driving Base will move backward instead of forward. Likewise, if the “amount” is negative, the Driving Base will move backward instead of forward. If both the speed and the “amount” are negative, the Driving Base will move forward.
- Parameters:
speed (int [-100,100]) – The speed at which the Driving Base will move while performing a curve.
steering (int [-100,100]) – The steering direction (-100 to 100). “0” makes the Driving Base move straight. Negative numbers make the Driving Base turn left. Positive numbers make the Driving Base turn right.
- Raises:
TypeError – steering or speed is not an integer
- stop()
Stops both motors simultaneously, which will stop a Driving Base.
The motors will either actively hold their current position or coast freely depending on the option that’s been selected by set_stop_action().
- move_tank(amount, unit='cm', left_speed=None, right_speed=None)
Moves the Driving Base using differential (tank) steering.
The speed of each motor can be controlled independently for differential (tank) drive Driving Bases.
When the specified unit is “cm” or “in,” the “amount” of the unit parameter is equal to the horizontal distance that the Driving Base will travel before stopping. The relationship between the motor rotations and distance traveled can be adjusted by calling set_motor_rotation().
When the “unit” is “rotations” or “degrees,” the “amount” parameter value specifies how much the motor axle will turn before stopping.
When the “unit” is “seconds,” the “amount” parameter value specifies the duration that the motors will run before stopping.
If left_speed or right_speed is outside of the allowed range, the value will be set to “-100” or “100” depending on whether the value is positive or negative.
If one of the speeds (i.e., left_speed or right_speed) is negative, the negative-speed motor will run backward instead of forward. If the “amount” parameter value is negative, both motors will rotate backward instead of forward. If both of the speed values (i.e., left_speed and right_speed) are negative and the “amount” parameter value is negative, both motors will rotate forward.
The program will not continue until the specified value is reached.
- Parameters:
amount (float) – The quantity to move in relation to the specified unit of measurement.
unit (string (cm,in,rotations,degrees,seconds)) – The unit of measurement specified for the “amount” parameter.
left_speed (int [-100,100]) – The speed of the left motor.
right_speed (int [-100,100]) – The speed of the right motor.
- Raises:
TypeError – amount, left_speed or right_speed is not a number or unit is not a string.
ValueError – unit is not one of the allowed values.
- start_tank(left_speed=None, right_speed=None)
Starts moving the Driving Base using differential (tank) steering.
The speed of each motor can be controlled independently for differential (tank) drive Driving Bases.
If left_speed or right_speed is outside of the allowed range, the value will be set to “-100” or “100” depending on whether the value is positive or negative.
If the speed is negative, the motors will move backward instead of forward.
The program flow is not interrupted. This is most likely interrupted by sensor input and a condition.
- Parameters:
left_speed (int [-100,100]) – The speed of the left motor.
right_speed (int [-100,100]) – The speed of the right motor.
- Raises:
TypeError – left_speed or right_speed is not an integer
- start_at_power(power, steering=0)
Starts moving the Driving Base without speed control.
The motors can also be driven without speed control. This is useful when using your own control algorithm (e.g., a proportional line-follower).
If the steering is outside of the allowed range, the value will be set to “-100” or “100” depending on whether the value is positive or negative.
If the power is outside of the allowed range, the value will be set to “-100” or “100” depending on whether the value is positive or negative.
If the power is negative, the Driving Base will move backward instead of forward.
The program flow is not interrupted. This can most likely be interrupted by sensor input and a condition.
- Parameters:
power (int [-100,100]) – The amount of power to send to the motors.
steering (int [-100,100]) – The steering direction (-100 to 100). “0” makes the Driving Base move straight. Negative numbers make the Driving Base turn left. Positive numbers make the Driving Base turn right.
- Raises:
TypeError – steering or power is not an integer
- start_tank_at_power(left_power, right_power)
Starts moving the Driving Base using differential (tank) steering without speed control.
The motors can also be driven without speed control. This is useful when using your own control algorithm (e.g., a proportional line-follower).
If the left_power or right_power is outside of the allowed range, the value will be rounded to “-100” or “100” depending on whether the value is positive or negative.
If the power is a negative value, the corresponding motor will move backward instead of forward.
The program flow is not interrupted. This can most likely be interrupted by sensor input and a condition.
- Parameters:
left_power (int [-100,100]) – The power of the left motor.
right_power (int [-100,100]) – The power of the right motor.
- Raises:
TypeError – left_power or right_power is not an integer
- get_default_speed()
Retrieves the default motor speed. — :return: The motors default speed :rtype: int [-100,100]
- set_motor_rotation(amount, unit='cm')
Sets the ratio of one motor rotation to the distance traveled.
If there are no gears used between the motors and the wheels of the Driving Base, the “amount” is the circumference of one wheel.
Calling this method does not affect the Driving Base if it’s already running. It will only have an effect the next time one of the move or start methods is used.
- Parameters:
amount (float) – The distance that the Driving Base moves when both motors move one rotation each, 17.6 default (5.6 diameter wheel)
unit (string (cm,in)) – The unit of measurement specified for the “amount” parameter.
- Raises:
TypeError – amount is not a number or unit is not a string.
ValueError – unit is not one of the allowed values.
- set_default_speed(speed)
Sets the default motor speed.
If speed is outside of the allowed range, the value will be set to “-100” or “100” depending on whether the value is positive or negative.
Setting the speed will not have any effect until one of the move or start methods is called, even if the Driving Base is already moving.
- Parameters:
speed (int(-100,100)) – The default motor speed.
- Raises:
TypeError – speed is not a number
- set_stop_action(action)
Sets the motor action that will be used when the Driving Base stops.
If the action is “brake,” the motors will stop quickly and be allowed to turn freely.
If the action is “hold,” the motors will actively hold their current position and cannot be turned manually.
If the action is set to “coast,” the motors will stop slowly and can be turned freely.
Setting the “stop” action does not take immediate effect on the motors. The setting will be saved and used whenever stop() is called or when one of the move methods has completed without being interrupted.
- Parameters:
action (string (coast, hold, brake)) – The desired action of the motors when the Driving Base stops.
- Raises:
TypeError – action is not a string
ValueError – action is not one of the allowed values
- __process_command(command)
Process command until over
- Parameters:
command (generator function) – command to process
- c_reset()
Reset function
Warning
This function is not part of the spike API. It is provided to update the component from scenario data and shall not be used by the end-user.
- c_set_stop_action(action)
Sets the action to be performed on stop
Warning
This function is not part of the spike API. It is provided to update the component from scenario data and shall not be used by the end-user.
- Parameters:
action (string (coast, hold, brake)) – The desired motor behavior when the motor stops.
- property left
Returns left motor
Warning
This function is not part of the spike API. It is provided to update the component from scenario data and shall not be used by the end-user.
- Returns:
Left motor port, None if not set
- Return type: