This repository has been archived on 2025-06-01. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
compLIB/_sources/lib/Odom.rst.txt
Konstantin Lampalzer 30a5567a6c Update documentation
2022-01-28 19:51:52 +01:00

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()