Odometry¶
Class Documentation¶
-
class
compLib.Odom.
Odometry
(x, y, orientation)¶ DTO used for holding all odometry information.
Coordinate system:
X: + Forward; - Backwards
Y: + Right; - Left
Orientation: + Right; - Left
-
get_orientation
() → float¶ Returns degrees turned in radians
-
get_x
() → float¶ Returns distance driven on x-axis in meters
-
get_y
() → float¶ Returns distance driven on y-axis in meters
-
-
class
compLib.Odom.
Odom
¶ Class used to track the movement of the robot in X, Y, Theta (Orientation)
-
static
clear
() → None¶ Clears the current odometry information and start from X, Y, Orientation set to 0
-
static
get_odom
() → compLib.Odom.Odometry¶ - Returns
Current orientation of the robot
-
static
update
() → None¶ Updates the current odometry information of the robot, Should be called in a loop with at least 100HZ. Do not clear encoder positions between updates! Must be cleared, when clearing encoders!
-
static
Examples¶
Getting actual distance driven¶
import time
import math
from compLib.Motor import Motor
from compLib.Encoder import Encoder
from compLib.Odom import Odom, Odometry
# distance in meters
# speed in % of max speed
def drive_example(distance, speed):
Odom.update()
odom = Odom.get_odom()
while abs(odom.get_x()) < distance:
Odom.update()
odom = Odom.get_odom()
Motor.power(4, speed)
Motor.power(1, -speed)
print(f" Forward: {odom.get_x()} m")
print(f" Right: {odom.get_y()} m")
print(f" Turned: {math.degrees(odom.get_orientation())} degrees")
Motor.active_break(1)
Motor.active_break(4)
time.sleep(0.1)
Encoder.clear_all()
Odom.clear()