Skip to content

Commit

Permalink
wait for ODrive to boot up before sending control mode
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Aug 8, 2023
1 parent 047f720 commit 4659fb6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions main/modules/odrive_motor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ void ODriveMotor::subscribe_to_can() {
}

void ODriveMotor::set_mode(const uint8_t state, const uint8_t control_mode, const uint8_t input_mode) {
if (!this->is_boot_complete) {
return;
}
if (this->axis_state != state) {
this->can->send(this->can_id + 0x007, state, 0, 0, 0, 0, 0, 0, 0);
this->axis_state = state;
Expand Down Expand Up @@ -53,6 +56,7 @@ void ODriveMotor::call(const std::string method_name, const std::vector<ConstExp
}

void ODriveMotor::handle_can_msg(const uint32_t id, const int count, const uint8_t *const data) {
this->is_boot_complete = true;
switch (id - this->can_id) {
case 0x009: {
float tick;
Expand Down
1 change: 1 addition & 0 deletions main/modules/odrive_motor.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ODriveMotor : public Module, public std::enable_shared_from_this<ODriveMot
private:
const uint32_t can_id;
const Can_ptr can;
bool is_boot_complete = false;
uint8_t axis_state = -1;
uint8_t axis_control_mode = -1;
uint8_t axis_input_mode = -1;
Expand Down

0 comments on commit 4659fb6

Please sign in to comment.