Add Documentation for odometrty and robot class. Remove fast_fifo
This commit is contained in:
parent
c800b30e31
commit
866fac9848
7 changed files with 115 additions and 8 deletions
|
@ -3,7 +3,6 @@ import socket
|
||||||
import uuid
|
import uuid
|
||||||
import os
|
import os
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import faster_fifo
|
|
||||||
import datetime
|
import datetime
|
||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
|
@ -29,7 +28,7 @@ else:
|
||||||
influx_client = InfluxDBClient(url=INFLUX_HOST, token=TOKEN)
|
influx_client = InfluxDBClient(url=INFLUX_HOST, token=TOKEN)
|
||||||
write_api = influx_client.write_api()
|
write_api = influx_client.write_api()
|
||||||
|
|
||||||
point_queue = faster_fifo.Queue()
|
point_queue = multiprocessing.Queue()
|
||||||
workers = []
|
workers = []
|
||||||
|
|
||||||
class MetricsLogging():
|
class MetricsLogging():
|
||||||
|
|
|
@ -21,6 +21,7 @@ class MotorMode(IntEnum):
|
||||||
BACKWARD = 2,
|
BACKWARD = 2,
|
||||||
BREAK = 3
|
BREAK = 3
|
||||||
|
|
||||||
|
|
||||||
class Motor(object):
|
class Motor(object):
|
||||||
"""Class used to control the motors
|
"""Class used to control the motors
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -13,22 +13,50 @@ orientation = 0
|
||||||
|
|
||||||
|
|
||||||
class Odometry():
|
class Odometry():
|
||||||
|
"""DTO used for holding all odometry information. \n
|
||||||
|
Coordinate system: \n
|
||||||
|
X: + Forward; - Backwards \n
|
||||||
|
Y: + Right; - Left \n
|
||||||
|
Orientation: + Right; - Left
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, x, y, orientation):
|
def __init__(self, x, y, orientation):
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
self.orientation = orientation
|
self.orientation = orientation
|
||||||
|
|
||||||
|
def get_x(self) -> float:
|
||||||
|
"""Returns distance driven on x-axis in meters"""
|
||||||
|
return self.x
|
||||||
|
|
||||||
|
def get_y(self) -> float:
|
||||||
|
"""Returns distance driven on y-axis in meters"""
|
||||||
|
return self.y
|
||||||
|
|
||||||
|
def get_orientation(self) -> float:
|
||||||
|
"""Returns degrees turned in radians"""
|
||||||
|
return self.orientation
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"X: {self.x} Y: {self.y} O: {self.orientation}"
|
return f"X: {self.x} Y: {self.y} O: {self.orientation}"
|
||||||
|
|
||||||
|
|
||||||
class Odom(object):
|
class Odom(object):
|
||||||
|
"""Class used to track the movement of the robot in X, Y, Theta (Orientation)
|
||||||
|
"""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_odom():
|
def get_odom() -> Odometry:
|
||||||
|
"""
|
||||||
|
:return: Current orientation of the robot
|
||||||
|
"""
|
||||||
return Odometry(pos_x, pos_y, orientation)
|
return Odometry(pos_x, pos_y, orientation)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def clear():
|
def clear() -> None:
|
||||||
|
"""
|
||||||
|
Clears the current odometry information and start from X, Y, Orientation set to 0
|
||||||
|
"""
|
||||||
global last_run, last_enc_left, last_enc_right, pos_x, pos_y, orientation
|
global last_run, last_enc_left, last_enc_right, pos_x, pos_y, orientation
|
||||||
|
|
||||||
last_run = 0
|
last_run = 0
|
||||||
|
@ -39,7 +67,11 @@ class Odom(object):
|
||||||
orientation = 0
|
orientation = 0
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def update():
|
def 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!
|
||||||
|
"""
|
||||||
global last_run, last_enc_left, last_enc_right, pos_x, pos_y, orientation
|
global last_run, last_enc_left, last_enc_right, pos_x, pos_y, orientation
|
||||||
|
|
||||||
now = time.time()
|
now = time.time()
|
||||||
|
|
|
@ -2,11 +2,23 @@ import math
|
||||||
|
|
||||||
|
|
||||||
class Robot(object):
|
class Robot(object):
|
||||||
|
|
||||||
WHEEL_CIRCUMFERENCE_MM = 71.0 * math.pi
|
WHEEL_CIRCUMFERENCE_MM = 71.0 * math.pi
|
||||||
|
"""Circumference of a wheel in millimeters"""
|
||||||
|
|
||||||
TICKS_PER_TURN = 27.7 * 100.0
|
TICKS_PER_TURN = 27.7 * 100.0
|
||||||
|
"""Ticks per 360 degree turn of a wheel"""
|
||||||
|
|
||||||
ARBOR_LENGTH_MM = 139.0
|
ARBOR_LENGTH_MM = 139.0
|
||||||
|
"""Distance between the two wheels in millimeters"""
|
||||||
|
|
||||||
ARBOR_LENGTH_M = ARBOR_LENGTH_MM / 1000.0
|
ARBOR_LENGTH_M = ARBOR_LENGTH_MM / 1000.0
|
||||||
|
"""Distance between the two wheels in meters"""
|
||||||
|
|
||||||
TICKS_PER_METER = 1000.0 / WHEEL_CIRCUMFERENCE_MM * TICKS_PER_TURN
|
TICKS_PER_METER = 1000.0 / WHEEL_CIRCUMFERENCE_MM * TICKS_PER_TURN
|
||||||
|
"""Ticks after driving one meter"""
|
||||||
|
|
||||||
LEFT_PORT = 4
|
LEFT_PORT = 4
|
||||||
|
"""Motor port for the left motor"""
|
||||||
|
|
||||||
RIGHT_PORT = 1
|
RIGHT_PORT = 1
|
||||||
|
"""Motor port for the right motor"""
|
||||||
|
|
|
@ -15,11 +15,12 @@ import sys
|
||||||
|
|
||||||
sys.path.insert(0, os.path.abspath('../..'))
|
sys.path.insert(0, os.path.abspath('../..'))
|
||||||
sys.setrecursionlimit(1500)
|
sys.setrecursionlimit(1500)
|
||||||
|
os.environ["EXTENSIVE_LOGGING"] = "False"
|
||||||
|
|
||||||
# -- Project information -----------------------------------------------------
|
# -- Project information -----------------------------------------------------
|
||||||
|
|
||||||
project = 'CompLib'
|
project = 'CompLib'
|
||||||
copyright = '2021, robo4you'
|
copyright = '2022, Verein zur Förderung von Wissenschaft und Technik an Schulen (F-WuTS)'
|
||||||
author = 'robo4you'
|
author = 'robo4you'
|
||||||
|
|
||||||
# The full version, including alpha/beta/rc tags
|
# The full version, including alpha/beta/rc tags
|
||||||
|
@ -35,7 +36,8 @@ extensions = [
|
||||||
'sphinx_rtd_theme'
|
'sphinx_rtd_theme'
|
||||||
]
|
]
|
||||||
|
|
||||||
autodoc_mock_imports = ["smbus", "compLib.PCA9685", "RPi", "pigpio", "flask", "apt", "spidev", "influxdb_client"]
|
autodoc_mock_imports = ["smbus", "compLib.PCA9685", "RPi",
|
||||||
|
"pigpio", "flask", "apt", "spidev", "influxdb_client"]
|
||||||
|
|
||||||
# Add any paths that contain templates here, relative to this directory.
|
# Add any paths that contain templates here, relative to this directory.
|
||||||
templates_path = ['_templates']
|
templates_path = ['_templates']
|
||||||
|
|
50
docs/source/lib/Odom.rst
Normal file
50
docs/source/lib/Odom.rst
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
.. _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()
|
11
docs/source/lib/Robot.rst
Normal file
11
docs/source/lib/Robot.rst
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
.. _lib_robot:
|
||||||
|
|
||||||
|
Robot
|
||||||
|
******
|
||||||
|
|
||||||
|
Class Documentation
|
||||||
|
====================
|
||||||
|
|
||||||
|
.. autoclass:: compLib.Robot.Robot
|
||||||
|
:members:
|
||||||
|
:private-members:
|
Reference in a new issue