@@ -65,41 +65,35 @@ void CANBoard::setMotorPower(double power) {
6565 return ;
6666 }
6767
68- // Fetch motor states
69-
70- // Ensure motor control mode is velocity
71- // Ensure motor state is closed loop control
72- this ->setMotorState (can::motor::axis_state_t ::closed_loop_control);
73-
7468 if (power == 0.0 ) {
7569 if (this ->board_id == robot::types::boardid_t ::shoulder || this ->board_id == robot::types::boardid_t ::elbow) {
7670 // Set brake
7771 this ->setBrake (BRAKE_ON );
7872 }
7973
80- if ( this ->watchdog ) {
81- this -> setMotorState (can::motor:: axis_state_t ::idle);
82-
83- if (nlohmann::json endpoint = getEndpoint (this ->board_id , " axis0.current_state" ); endpoint != nullptr ) {
84- uint16_t endpoint_id = endpoint[" id" ];
85- addDirectReadCallback (this ->device , endpoint_id, [this , endpoint_id](auto decoded) {
86- if (decoded.value_uint8 != static_cast <uint8_t >(can::motor::axis_state_t ::idle)) {
87- LOG_F (ERROR , " 0x%x (%s) DID NOT LISTEN AND IS NOT IDLE AND IS INSTEAD %d, re-attempting..." , this ->device .deviceUUID , util::to_string (this ->board_id ).c_str (), decoded.value_uint8 );
88- this ->setMotorState (can::motor::axis_state_t ::idle);
89- this ->read (endpoint_id);
90- } else {
91- removeDirectReadCallback (this ->device , endpoint_id);
92- }
93- });
94-
95- this ->read (endpoint_id);
96- }
97- }
74+ this ->setMotorState (can::motor:: axis_state_t ::idle);
75+
76+ // if (this->watchdog) {
77+ // if (nlohmann::json endpoint = getEndpoint(this->board_id, "axis0.current_state"); endpoint != nullptr) {
78+ // uint16_t endpoint_id = endpoint["id"];
79+ // addDirectReadCallback(this->device, endpoint_id, [this, endpoint_id](auto decoded) {
80+ // if (decoded.value_uint8 != static_cast<uint8_t>(can::motor::axis_state_t::idle)) {
81+ // LOG_F(ERROR, "0x%x (%s) DID NOT LISTEN AND IS NOT IDLE AND IS INSTEAD %d, re-attempting...", this->device.deviceUUID, util::to_string(this->board_id).c_str(), decoded.value_uint8);
82+ // this->setMotorState(can::motor::axis_state_t::idle);
83+ // this->read(endpoint_id);
84+ // } else {
85+ // removeDirectReadCallback(this->device, endpoint_id);
86+ // }
87+ // });
88+
89+ // this->read(endpoint_id);
90+ // }
91+ // }
9892 } else {
93+ // Ensure motor state is closed loop control
94+ this ->setMotorState (can::motor::axis_state_t ::closed_loop_control);
9995 // Mapping power to a target velocity
100- float input_vel = static_cast <float >(power * this ->vel_limit ) * 0.4 ; // hard-coded 40%
101- input_vel *= this ->inversion_factor ;
102-
96+ this ->input_vel = static_cast <float >(power * this ->vel_limit ) * 0.4 * this ->inversion_factor ; // hard-coded 40%
10397 // LOG_F(INFO, "True input velocity %f, ", input_vel);
10498
10599 if (this ->board_id == robot::types::boardid_t ::shoulder || this ->board_id == robot::types::boardid_t ::elbow) {
@@ -116,12 +110,12 @@ void CANBoard::setMotorPower(double power) {
116110
117111 if (nlohmann::json endpoint = getEndpoint (this ->board_id , " axis0.controller.input_vel" ); endpoint != nullptr ) {
118112 uint16_t endpoint_id = endpoint[" id" ];
119- addDirectReadCallback (this ->device , endpoint_id, [input_vel, p, this , endpoint_id](auto decoded) {
113+ addDirectReadCallback (this ->device , endpoint_id, [p, this , endpoint_id](auto decoded) {
120114 if (decoded.value_float != input_vel) {
121- LOG_F (ERROR , " Expected %f, got %f" , input_vel, decoded.value_float );
122- sendCANPacket (p);
115+ LOG_F (ERROR , " Expected %f, got %f" , this -> input_vel , decoded.value_float );
116+ // sendCANPacket(p);
123117 } else {
124- LOG_F (INFO , " Got %f vel_limit :)" , decoded.value_float );
118+ // LOG_F(INFO, "Got %f vel_limit :)", decoded.value_float);
125119 }
126120 });
127121
0 commit comments