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

Feat/can node #13

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Feat/can node #13

wants to merge 9 commits into from

Conversation

antonioc76
Copy link
Member

New Can node based on new can spec.

@danielbrownmsm danielbrownmsm self-requested a review November 20, 2024 00:35
self.safetyLightsSubscriber = self.create_subscription(
SafetyLights,
"autonav/safety_lights",
self.on_safety_lights_received(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove parentheses (and on following lines) as this is calling the function instead of passing the function as a reference python thingamajig


def init(self):
# can threading
self.canTimer = self.create_timer(0.5, self.can_worker)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the .5 a timeout and should it be shorter or longer? half a second seems slow for CAN stuff but idk what the number means

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ this is attempting to make a new can worker if there isn't one already every .5 seconds, seems reasonable

class CanConfig:
def __init__(self):
self.odom_feedback_scaler = 10000
self.linear_pid_scaling_factor = 1000
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for consistency they should all be scaler or all be factor, I don't like having both right next to each other


def can_worker(self):
try:
with open("/dev/ttyACM0", "r") as f:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add an easy way to change the device path? I think in the future we'll make a udev rule for it and make it like ttyACM200 or something because the first like 80 are auto-assigned, might be nice to check multiple paths so we don't accidentally miss it or something

def can_worker(self):
try:
with open("/dev/ttyACM0", "r") as f:
pass
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait why are we just passing here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevermind

if arbitration_id == arbitration_ids["Estop"]:
self.set_mobility(False)

if arbitration_id == arbitration_ids["MobilityStart"]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a super huge thing but this could be optimized if it's one big if/elif chain instead of multiple individual if statements

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plus we can throw an else: at the end of it all and throw an error because we should never get an ID that's not one of those listed here

forward_velocity, forward_velocity_setpoint, sideways_velocity, sideways_velocity_setpoint = struct.unpack("hhhh", msg.data)
linear_pid_statistics_msg = LinearPIDStatistics()
linear_pid_statistics_msg.forward_velocity = forward_velocity
linear_pid_statistics_msg.forward_velocity_setpoint - forward_velocity_setpoint
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably want this to be an equal sign instead of a minus sign

try:
self.can.send(can_msg)
except can.CanError:
pass
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to be passing these can errors or should the user know about them? how often do they occur? is it like a once every couple seconds because communication protocols be like that or is it a big deal and we should change device state and log an error?

"msg/Log.msg"
"msg/MotorFeedback.msg"
"msg/MotorInput.msg"
"msg/MotorStatisticsBackMotors.msg"
"msg/MotorStatisticsFrontMotors.msg"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are these separate messages? aren't both back and front motor messages the same? they should be different callbacks yes but same message type

uint8 left_drive_motor_output
uint8 left_steer_motor_output
uint8 right_drive_motor_output
uint8 right_steer_motor_output
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment about separate front and back message types

@danielbrownmsm danielbrownmsm added the enhancement New feature or request label Nov 25, 2024
Copy link
Collaborator

@danielbrownmsm danielbrownmsm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants