drive in a straight line for a specified distance
rotate in place in a circle (clockwise or counter clockwise) for a specified number of degrees
drive in an arc (clockwise or counter clockwise) of a specified radius for a specified distance
Odometry can be use to enable driving to specific coordinates and rotating to a specific angle.
New arguments:
wheel_class - Typically a child class of :class:`ev3dev2.wheel.Wheel`. This is used to get the circumference of the wheels of the robot. The circumference is needed for several calculations in this class.
wheel_distance_mm - The distance between the mid point of the two wheels of the robot. You may need to do some test drives to find the correct value for your robot. It is not as simple as measuring the distance between the midpoints of the two wheels. The weight of the robot, center of gravity, etc come into play.
You can use utils/move_differential.py to call on_arc_left() to do some test drives of circles with a radius of 200mm. Adjust your wheel_distance_mm until your robot can drive in a perfect circle and stop exactly where it started. It does not have to be a circle with a radius of 200mm, you can test with any size circle but you do not want it to be too small or it will be difficult to test small adjustments to wheel_distance_mm.
Example:
from ev3dev2.motor import OUTPUT_A, OUTPUT_B, MoveDifferential, SpeedRPM
from ev3dev2.wheel import EV3Tire
STUD_MM = 8
# test with a robot that:
# - uses the standard wheels known as EV3Tire
# - wheels are 16 studs apart
mdiff = MoveDifferential(OUTPUT_A, OUTPUT_B, EV3Tire, 16 * STUD_MM)
# Rotate 90 degrees clockwise
mdiff.turn_right(SpeedRPM(40), 90)
# Drive forward 500 mm
mdiff.on_for_distance(SpeedRPM(40), 500)
# Drive in arc to the right along an imaginary circle of radius 150 mm.
# Drive for 700 mm around this imaginary circle.
mdiff.on_arc_right(SpeedRPM(80), 150, 700)
# Enable odometry
mdiff.odometry_start()
# Use odometry to drive to specific coordinates
mdiff.on_to_coordinates(SpeedRPM(40), 300, 300)
# Use odometry to go back to where we started
mdiff.on_to_coordinates(SpeedRPM(40), 0, 0)
# Use odometry to rotate in place to 90 degrees
mdiff.turn_to_angle(SpeedRPM(40), 90)
# Disable odometry
mdiff.odometry_stop()