-
Notifications
You must be signed in to change notification settings - Fork 1
Opencv testing #14
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
base: main
Are you sure you want to change the base?
Opencv testing #14
Changes from all commits
38ca81f
af77f62
74b44e6
cc85213
a17a902
cdb6135
45fb819
f213352
7beae0b
08a651f
40444a2
619d226
bf09c52
3a8dc7a
a492e81
7d9d723
f26f987
9400330
90f701f
d3559a6
25c5ec9
123de20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,53 @@ | ||
| import random | ||
| from typing import Tuple | ||
| from std_msgs.msg import Float32 | ||
|
|
||
|
|
||
| def pathfinder(opencv_output: Tuple): | ||
| def pathfinder(opencv_output: Tuple, current_speed: Float32, dt: Float32, max_accel:Float32, max_steering: Float32, max_speed_straight: Float32, max_speed_turning: Float32, max_speed: Float32, logger): | ||
| """ | ||
| Calculate commands for steering and motor from opencv_pathfinder efficiently | ||
| Part of hot loop so must be efficient. | ||
| TODO(Pathfinder Team): Calculate motor_speed & steering_angle | ||
| :param opencv_output: Tuple of [left angle from center to base of track from image (float32), right angle ...] | ||
| :param current_speed: Current actual speed from motor node (% of total) | ||
| :param dt: Time elapsed time between last calculated speed command and current | ||
| :param max_accel: Max allowed acceleration of kart (m/s) | ||
| :param max_steering: Max steering angle (degrees) | ||
| :param max_speed_straight: Max allowed speed on straights (m/s) | ||
| :param max_speed_turning: Max allowed speed while turning (m/s) | ||
| :param max_speed: Max possible speed (m/s) | ||
| :param logger: Allows for logging info | ||
| :return: Returns commands to motor & steering in (speed % of total, steering angle (degrees from -90 to 90 with 0 as straight) | ||
| """ | ||
|
|
||
| # Dummy | ||
| motor_speed = 20 * random.random() | ||
| steering_angle = 180 * random.random() - 90 | ||
| # convert current speed from motor node to m/s | ||
| current_speed *= max_speed | ||
|
|
||
| speed_command_ms = current_speed # base speed command in m/s | ||
|
|
||
| theta1 = -1 * opencv_output[0] | ||
| theta2 = opencv_output[1] | ||
|
|
||
| desired_heading = (theta1 + theta2) / 2 #average of both angles | ||
|
|
||
| if abs(desired_heading) < 10: | ||
|
shb-png marked this conversation as resolved.
|
||
| target_speed = max_speed_straight #max speed on straights | ||
| else: | ||
| target_speed = max_speed_turning #target speed on turns | ||
|
|
||
| if target_speed > current_speed: | ||
| speed_command_ms = min(speed_command_ms + max_accel * dt, target_speed) | ||
| else: | ||
| speed_command_ms = max(speed_command_ms - max_accel * dt, target_speed) | ||
|
|
||
| steering_command = max(min(desired_heading, max_steering), -max_steering) | ||
|
|
||
| # calculate speed command as % of total | ||
| speed_command_percent = speed_command_ms / max_speed | ||
|
|
||
| logger.info(f"Theta1: {theta1:.1f}°, Theta2: {theta2:.1f}°") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a question for @ShayManor :
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for the delay, not sure if this is still relevant. This is fine because it's on info and when we run we set logger mode to warning. Looking into how logger works, this will make one function call, fail the check, and return. This is fine.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The if fails, so no log is made, and the string format is not evaluated. |
||
| logger.info(f"Desired Heading: {desired_heading:.1f}°") | ||
| logger.info(f"Target Speed: {target_speed} m/s | Current Speed: {current_speed:.1f} m/s | Commanded Speed: {speed_command_percent:.3f} of total") | ||
| logger.info(f"Steering Command: {steering_command:.1f}° {'Left' if steering_command < 0 else 'Right' if steering_command > 0 else 'Straight'}") | ||
| logger.info(f"dt {dt:.3f}") | ||
|
|
||
|
|
||
|
|
||
| return motor_speed, steering_angle | ||
| return float(speed_command_percent), float(steering_command) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be missing it, but does it handle the case when OpenCV node is unable to find a left or right angle?