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 os
|
||||
import multiprocessing
|
||||
import faster_fifo
|
||||
import datetime
|
||||
import requests
|
||||
import time
|
||||
|
@ -29,7 +28,7 @@ else:
|
|||
influx_client = InfluxDBClient(url=INFLUX_HOST, token=TOKEN)
|
||||
write_api = influx_client.write_api()
|
||||
|
||||
point_queue = faster_fifo.Queue()
|
||||
point_queue = multiprocessing.Queue()
|
||||
workers = []
|
||||
|
||||
class MetricsLogging():
|
||||
|
|
|
@ -21,6 +21,7 @@ class MotorMode(IntEnum):
|
|||
BACKWARD = 2,
|
||||
BREAK = 3
|
||||
|
||||
|
||||
class Motor(object):
|
||||
"""Class used to control the motors
|
||||
"""
|
||||
|
|
|
@ -13,22 +13,50 @@ orientation = 0
|
|||
|
||||
|
||||
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):
|
||||
self.x = x
|
||||
self.y = y
|
||||
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):
|
||||
return f"X: {self.x} Y: {self.y} O: {self.orientation}"
|
||||
|
||||
|
||||
class Odom(object):
|
||||
"""Class used to track the movement of the robot in X, Y, Theta (Orientation)
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def get_odom():
|
||||
def get_odom() -> Odometry:
|
||||
"""
|
||||
:return: Current orientation of the robot
|
||||
"""
|
||||
return Odometry(pos_x, pos_y, orientation)
|
||||
|
||||
@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
|
||||
|
||||
last_run = 0
|
||||
|
@ -39,7 +67,11 @@ class Odom(object):
|
|||
orientation = 0
|
||||
|
||||
@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
|
||||
|
||||
now = time.time()
|
||||
|
|
|
@ -2,11 +2,23 @@ import math
|
|||
|
||||
|
||||
class Robot(object):
|
||||
|
||||
WHEEL_CIRCUMFERENCE_MM = 71.0 * math.pi
|
||||
"""Circumference of a wheel in millimeters"""
|
||||
|
||||
TICKS_PER_TURN = 27.7 * 100.0
|
||||
"""Ticks per 360 degree turn of a wheel"""
|
||||
|
||||
ARBOR_LENGTH_MM = 139.0
|
||||
"""Distance between the two wheels in millimeters"""
|
||||
|
||||
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 after driving one meter"""
|
||||
|
||||
LEFT_PORT = 4
|
||||
"""Motor port for the left motor"""
|
||||
|
||||
RIGHT_PORT = 1
|
||||
"""Motor port for the right motor"""
|
||||
|
|
Reference in a new issue