Example:
tank_drive = MoveTank(OUTPUT_A, OUTPUT_B)
# drive in a turn for 10 rotations of the outer motor
tank_drive.on_for_rotations(50, 75, 10)kp, ki, and kd are the PID constants.
speed is the desired speed of the midpoint of the robot
target_angle is the angle we want to maintain
the loop. This is to give the robot a chance to react to the new motor settings. This should be something small such as 0.01 (10ms).
desired angle or stop. This function will be passed self (the current MoveTank object). Current supported options are: - follow_for_forever - follow_for_ms
**kwargs will be passed to the follow_for function
Example:
from ev3dev2.motor import OUTPUT_A, OUTPUT_B, MoveTank, SpeedPercent, follow_for_ms
from ev3dev2.sensor.lego import GyroSensor
# Instantiate the MoveTank object
tank = MoveTank(OUTPUT_A, OUTPUT_B)
# Initialize the tank's gyro sensor
tank.gyro = GyroSensor()
# Calibrate the gyro to eliminate drift, and to initialize the current angle as 0
tank.gyro.calibrate()
try:
# Follow the target_angle for 4500ms
tank.follow_gyro_angle(
kp=11.3, ki=0.05, kd=3.2,
speed=SpeedPercent(30),
target_angle=0,
follow_for=follow_for_ms,
ms=4500
)
except FollowGyroAngleErrorTooFast:
tank.stop()
raisekp, ki, and kd are the PID constants.
speed is the desired speed of the midpoint of the robot
is on the edge of the line. If this is None we assume that the color sensor is on the edge of the line and will take a reading to set this variable.
follow_left_edge determines if we follow the left or right edge of the line
lost the line
reflected_light_intensity must be greater than white before we declare the line lost and raise an exception
the loop. This is to give the robot a chance to react to the new motor settings. This should be something small such as 0.01 (10ms).
line or stop. This function will be passed self (the current MoveTank object). Current supported options are: - follow_for_forever - follow_for_ms
**kwargs will be passed to the follow_for function
Example:
from ev3dev2.motor import OUTPUT_A, OUTPUT_B, MoveTank, SpeedPercent, follow_for_ms
from ev3dev2.sensor.lego import ColorSensor
tank = MoveTank(OUTPUT_A, OUTPUT_B)
tank.cs = ColorSensor()
try:
# Follow the line for 4500ms
tank.follow_line(
kp=11.3, ki=0.05, kd=3.2,
speed=SpeedPercent(30),
follow_for=follow_for_ms,
ms=4500
)
except LineFollowErrorTooFast:
tank.stop()
raiseThis method is overriden in:
If the left speed is not equal to the right speed (i.e., the robot will turn), the motor on the outside of the turn will rotate for the full degrees while the motor on the inside will have its requested distance calculated according to the expected turn.
This method is overriden in:
If the left speed is not equal to the right speed (i.e., the robot will turn), the motor on the outside of the turn will rotate for the full rotations while the motor on the inside will have its requested distance calculated according to the expected turn.
This method is overriden in:
speed is the desired speed of the midpoint of the robot
target_angle is the number of degrees we want to rotate
brake hit the brakes once we reach target_angle
error_margin is the +/- angle threshold to control how accurate the turn should be
the loop. This is to give the robot a chance to react to the new motor settings. This should be something small such as 0.01 (10ms).
Rotate in place for target_degrees at speed
Example:
from ev3dev2.motor import OUTPUT_A, OUTPUT_B, MoveTank, SpeedPercent
from ev3dev2.sensor.lego import GyroSensor
# Instantiate the MoveTank object
tank = MoveTank(OUTPUT_A, OUTPUT_B)
# Initialize the tank's gyro sensor
tank.gyro = GyroSensor()
# Calibrate the gyro to eliminate drift, and to initialize the current angle as 0
tank.gyro.calibrate()
# Pivot 30 degrees
tank.turn_degrees(
speed=SpeedPercent(5),
target_angle=30
)This method is overriden in: