Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

921 kinematics pose estimation #1089

Merged
merged 29 commits into from
Feb 16, 2023
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1ce5b00
Add tachometer, odometer and kinematics part
Ezward Jan 1, 2023
deeb6fc
refactor pose estimation into a single part
Ezward Jan 8, 2023
d31b163
comment out logging of pose to quiet the console
Ezward Jan 8, 2023
9710c16
add arduino encoder sketches
Ezward Jan 16, 2023
6d66d2c
remove unicode characters that prevent compilation of arduino sketch
Ezward Jan 17, 2023
ff95fdf
clean up comments a little
Ezward Jan 17, 2023
e2a9a54
Add more documentation to the quadrature_encoder.ino sketch
Ezward Jan 18, 2023
325e89b
Add interrupt mode to the mono encoder
Ezward Jan 24, 2023
a5c6a44
Remove spurious unicode beta character
Ezward Jan 24, 2023
ae4ab8f
removed digital write high in mono encoder
Ezward Jan 24, 2023
8f2f859
Fix syntax error if only using one channel in int mode
Ezward Jan 26, 2023
e6eb5cf
Added a quadrature encoder sketch with no libraries
Ezward Jan 28, 2023
162ff35
Fix bug in mono encoder sketch
Ezward Jan 28, 2023
5d05b11
Fix bug in quadrature nolib sketch
Ezward Jan 28, 2023
a4ede0a
minor change to quadrature nolib
Ezward Jan 28, 2023
896cc26
Updated quadrature_encoder.ino to not require library
Ezward Jan 31, 2023
1cf569d
fix merge error in path_follow.py
Ezward Feb 4, 2023
a90421d
Fix RPi_GPIO_Servo part so it does not need GPIO in constructor
Ezward Feb 5, 2023
92af322
added non-threaded run() to UnicyclePose and BicyclePose for testing
Ezward Feb 8, 2023
4e6c371
Improved accuracy of MockEncoder by propagating fractional ticks
Ezward Feb 8, 2023
6d4f506
Updated add_odometry() so we could add as non-threaded for testing.
Ezward Feb 8, 2023
9f2ab20
Vehicle loop prints out number of iterations and total time
Ezward Feb 8, 2023
e9cac78
Rewrite of the kinematics unit tests
Ezward Feb 8, 2023
0cda9b0
Adjust bicycle kinematics to use front wheel reference
Ezward Feb 9, 2023
a1d4f78
relax orientation test to 3% accuracy
Ezward Feb 9, 2023
024fc0f
updated based on PR feedback
Ezward Feb 9, 2023
0ae8db9
removed hard-coded logging level
Ezward Feb 12, 2023
ee22a1b
Update vehicle.py
Ezward Feb 13, 2023
78711a7
Update setup.py version="4.4.dev5"
Ezward Feb 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added non-threaded run() to UnicyclePose and BicyclePose for testing
  • Loading branch information
Ezward committed Feb 14, 2023
commit 92af3223bbbd24201c7cba3942d56d5f3e4cb39a
77 changes: 54 additions & 23 deletions donkeycar/parts/pose.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def __init__(self, cfg, poll_delay_secs:float=0):
MockEncoder)
from donkeycar.parts.odometer import Odometer

# distance_per_revolution = cfg.ENCODER_PPR * cfg.MM_PER_TICK / 1000
distance_per_revolution = cfg.WHEEL_RADIUS * 2 * 3.141592653589793

self.poll_delay_secs = poll_delay_secs
Expand All @@ -55,7 +54,7 @@ def __init__(self, cfg, poll_delay_secs:float=0):
elif cfg.ENCODER_TYPE == "arduino":
self.encoder = SerialEncoder(serial_port=SerialPort(cfg.ODOM_SERIAL, cfg.ODOM_SERIAL_BAUDRATE), debug=cfg.ODOM_DEBUG)
elif cfg.ENCODER_TYPE.upper() == "MOCK":
self.encoder = MockEncoder(cfg.ENCODER_PPR * 10) # max 10 revolutions per second
self.encoder = MockEncoder(cfg.MOCK_TICKS_PER_SECOND)
else:
print("No supported encoder found")

Expand All @@ -79,16 +78,9 @@ def __init__(self, cfg, poll_delay_secs:float=0):
else:
logger.error("Unable to initialize BicyclePose part")

def update(self):
"""
This will get called on it's own thread.
throttle: sign of throttle is use used to determine direction.
timestamp: timestamp for update or None to use current time.
This is useful for creating deterministic tests.
"""
while self.running:
def poll(self, timestamp=None):
if self.running:
if self.tachometer:
timestamp = None
throttle, steering = self.inputs
if isinstance(self.encoder, MockEncoder):
self.encoder.run(throttle, timestamp)
Expand All @@ -97,6 +89,15 @@ def update(self):
steering_angle = self.steerer.run(steering)
self.reading = self.bicycle.run(distance, steering_angle, timestamp)

def update(self):
"""
This will get called on it's own thread.
throttle: sign of throttle is use used to determine direction.
timestamp: timestamp for update or None to use current time.
This is useful for creating deterministic tests.
"""
while self.running:
self.poll()
time.sleep(self.poll_delay_secs) # give other threads time

def run_threaded(self, throttle:float=0.0, steering:float=0.0, timestamp:float=None) -> Tuple[float, float, float, float, float, float, float, float, float]:
Expand All @@ -112,6 +113,20 @@ def run_threaded(self, throttle:float=0.0, steering:float=0.0, timestamp:float=N

return 0, 0, 0, 0, 0, 0, 0, 0, timestamp

def run(self, throttle:float=0.0, steering:float=0.0, timestamp:float=None) -> Tuple[float, float, float, float, float, float, float, float, float]:
if self.running and self.tachometer:
if throttle is None:
throttle = 0
if steering is None:
steering = 0

self.inputs = (throttle, steering)
self.poll(timestamp)

return self.reading

return 0, 0, 0, 0, 0, 0, 0, 0, timestamp


class UnicyclePose:
"""
Expand Down Expand Up @@ -157,8 +172,8 @@ def __init__(self, cfg, poll_delay_secs:float=0):
]
elif cfg.ENCODER_TYPE.upper() == "MOCK":
self.encoder = [
MockEncoder(cfg.ENCODER_PPR * 10),
MockEncoder(cfg.ENCODER_PPR * 10)
MockEncoder(cfg.MOCK_TICKS_PER_SECOND),
MockEncoder(cfg.MOCK_TICKS_PER_SECOND),
]
else:
print("No supported encoder found")
Expand Down Expand Up @@ -193,17 +208,11 @@ def __init__(self, cfg, poll_delay_secs:float=0):
self.unicycle = Unicycle(cfg.AXLE_LENGTH, cfg.ODOM_DEBUG)
self.running = True

def update(self):
"""
This will get called on it's own thread.
throttle: sign of throttle is use used to determine direction.
timestamp: timestamp for update or None to use current time.
This is useful for creating deterministic tests.
"""
while self.running:
def poll(self, timestamp=None):
if self.running:
if self.tachometer:
left_timestamp = None
right_timestamp = None
left_timestamp = timestamp
right_timestamp = timestamp
left_throttle, right_throttle = self.inputs
if isinstance(self.encoder[0], MockEncoder):
self.encoder[0].run(left_throttle, left_timestamp)
Expand All @@ -217,6 +226,15 @@ def update(self):

self.reading = self.unicycle.run(left_distance, right_distance, right_timestamp)

def update(self):
"""
This will get called on it's own thread.
throttle: sign of throttle is use used to determine direction.
timestamp: timestamp for update or None to use current time.
This is useful for creating deterministic tests.
"""
while self.running:
self.poll()
time.sleep(self.poll_delay_secs) # give other threads time

def run_threaded(self, throttle:float=0.0, steering:float=0.0, timestamp:float=None) -> Tuple[float, float, float, float, float, float, float, float, float]:
Expand All @@ -230,3 +248,16 @@ def run_threaded(self, throttle:float=0.0, steering:float=0.0, timestamp:float=N
return self.reading

return 0, 0, 0, 0, 0, 0, 0, 0, timestamp

def run(self, throttle:float=0.0, steering:float=0.0, timestamp:float=None) -> Tuple[float, float, float, float, float, float, float, float, float]:
if self.running and self.tachometer:
if throttle is None:
throttle = 0
if steering is None:
steering = 0

self.inputs = differential_steering(throttle, steering)
self.poll(timestamp)
return self.reading

return 0, 0, 0, 0, 0, 0, 0, 0, timestamp