@@ -17,22 +17,30 @@ CANBoard::CANBoard(robot::types::boardid_t board_id, CANDevice_t device)
1717 );
1818 sendCANPacket (p);
1919
20- // Ping motor for configs (max vel)
20+ // Ping motor for configs
2121 if (nlohmann::json endpoint = getEndpoint (this ->board_id , " axis0.controller.config.vel_limit" ); endpoint != nullptr ) {
2222 uint16_t endpoint_id = endpoint[" id" ];
2323 addDirectReadCallback (this ->device , endpoint_id, [this , endpoint_id](auto p) {
2424 this ->vel_limit = p.value_float ;
25- LOG_F (INFO , " got vel limit %f" , p.value_float );
2625
2726 // We only need this once, remove after we get a response
2827 removeDirectReadCallback (this ->device , endpoint_id);
2928 });
3029
3130 this ->read (endpoint_id);
32- } else {
33- LOG_F (ERROR , " CAN Endpoints does not contain axis0.controller.config.vel_limit!" );
3431 }
35- // Has watchdog?
32+
33+ if (nlohmann::json endpoint = getEndpoint (this ->board_id , " axis0.config.enable_watchdog" ); endpoint != nullptr ) {
34+ uint16_t endpoint_id = endpoint[" id" ];
35+ addDirectReadCallback (this ->device , endpoint_id, [this , endpoint_id](auto p) {
36+ this ->watchdog = p.value_bool ;
37+
38+ // We only need this once, remove after we get a response
39+ removeDirectReadCallback (this ->device , endpoint_id);
40+ });
41+
42+ this ->read (endpoint_id);
43+ }
3644
3745 // Inversion
3846 if (auto it = robot::boardInversionMap.find (board_id); it != robot::boardInversionMap.end ()) {
@@ -66,7 +74,7 @@ void CANBoard::setMotorPower(double power) {
6674 }
6775 } else {
6876 // Mapping power to a target velocity
69- int8_t input_vel = static_cast <int8_t >(power * this ->vel_limit );
77+ float input_vel = static_cast <float >(power * this ->vel_limit );
7078 input_vel *= this ->inversion_factor ;
7179 // Make CANPacket_t
7280 CANPacket_t p = CANMotorPacket_BLDC_SetInputVelocity (
@@ -75,6 +83,20 @@ void CANBoard::setMotorPower(double power) {
7583
7684 // Send packet
7785 sendCANPacket (p);
86+
87+ if (nlohmann::json endpoint = getEndpoint (this ->board_id , " axis0.controller.input_vel" ); endpoint != nullptr ) {
88+ uint16_t endpoint_id = endpoint[" id" ];
89+ addDirectReadCallback (this ->device , endpoint_id, [input_vel](auto decoded) {
90+ if (decoded.value_float != input_vel) {
91+ LOG_F (ERROR , " Expected %f, got %f" , input_vel, decoded.value_float );
92+ // send
93+ } else {
94+ // remove from map
95+ }
96+ });
97+
98+ this ->read (endpoint_id);
99+ }
78100 }
79101}
80102
0 commit comments