@@ -22,6 +22,7 @@ CANBoard::CANBoard(robot::types::boardid_t board_id, CANDevice_t device)
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 , " Fetched vel limit for 0x%x: %f" , this ->device .deviceUUID , this ->vel_limit );
2526
2627 // We only need this once, remove after we get a response
2728 removeDirectReadCallback (this ->device , endpoint_id);
@@ -47,12 +48,12 @@ CANBoard::CANBoard(robot::types::boardid_t board_id, CANDevice_t device)
4748 this ->inversion_factor = it->second ;
4849 }
4950
50- if (nlohmann::json endpoint = getEndpoint (this ->board_id , " axis0.pos_estimate" ); endpoint != nullptr ) {
51- uint16_t endpoint_id = endpoint[" id" ];
52- addDirectReadCallback (this ->device , endpoint_id, [this , endpoint_id](auto p) {
53- LOG_F (INFO , " 0x%x at %f rots" , this ->device .deviceUUID , p.value_float );
54- });
55- }
51+ // if (nlohmann::json endpoint = getEndpoint(this->board_id, "axis0.pos_estimate"); endpoint != nullptr) {
52+ // uint16_t endpoint_id = endpoint["id"];
53+ // addDirectReadCallback(this->device, endpoint_id, [this, endpoint_id](auto p) {
54+ // LOG_F(INFO, "0x%x at %f rots", this->device.deviceUUID, p.value_float);
55+ // });
56+ // }
5657 }
5758
5859 if (device.peripheralDomain ) {
@@ -75,6 +76,25 @@ void CANBoard::setMotorPower(double power) {
7576 if (power == 0.0 ) {
7677 if (static_cast <uint8_t >(this ->board_id ) < 5 ) { // hack for wheels + base
7778 this ->setMotorState (can::motor::axis_state_t ::idle);
79+
80+ // hang until this actually goes idle for funsies
81+ this ->correct = false ;
82+ if (nlohmann::json endpoint = getEndpoint (this ->board_id , " axis0.current_state" ); endpoint != nullptr ) {
83+ uint16_t endpoint_id = endpoint[" id" ];
84+ addDirectReadCallback (this ->device , endpoint_id, [this , endpoint_id](auto decoded) {
85+ if (decoded.value_uint8 != static_cast <uint8_t >(can::motor::axis_state_t ::idle)) {
86+ LOG_F (ERROR , " 0x%x DID NOT LISTEN AND IS NOT IDLE" , this ->device .deviceUUID );
87+ this ->setMotorState (can::motor::axis_state_t ::idle);
88+ } else {
89+ removeDirectReadCallback (this ->device , endpoint_id);
90+ correct = true ;
91+ }
92+ });
93+
94+ this ->read (endpoint_id);
95+ }
96+
97+ while (!this ->correct );
7898 } else if (this ->board_id == robot::types::boardid_t ::shoulder || this ->board_id == robot::types::boardid_t ::elbow) {
7999 // Set motor general lockin vel to 0
80100 this ->setMotorState (can::motor::axis_state_t ::lockin_spin);
@@ -93,12 +113,12 @@ void CANBoard::setMotorPower(double power) {
93113
94114 if (nlohmann::json endpoint = getEndpoint (this ->board_id , " axis0.controller.input_vel" ); endpoint != nullptr ) {
95115 uint16_t endpoint_id = endpoint[" id" ];
96- addDirectReadCallback (this ->device , endpoint_id, [input_vel](auto decoded) {
116+ addDirectReadCallback (this ->device , endpoint_id, [input_vel, p, this , endpoint_id ](auto decoded) {
97117 if (decoded.value_float != input_vel) {
98118 LOG_F (ERROR , " Expected %f, got %f" , input_vel, decoded.value_float );
99- // send
119+ sendCANPacket (p);
100120 } else {
101- // remove from map
121+ removeDirectReadCallback ( this -> device , endpoint_id);
102122 }
103123 });
104124
0 commit comments