50 lines
No EOL
1 KiB
ReStructuredText
50 lines
No EOL
1 KiB
ReStructuredText
.. _lib_odom:
|
|
|
|
Odometry
|
|
********
|
|
|
|
Class Documentation
|
|
====================
|
|
|
|
.. autoclass:: compLib.Odom.Odometry
|
|
:members:
|
|
|
|
.. autoclass:: compLib.Odom.Odom
|
|
:members:
|
|
|
|
|
|
Examples
|
|
=========
|
|
|
|
Getting actual distance driven
|
|
------------------------------
|
|
|
|
.. code-block:: python
|
|
|
|
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() |