@@ -61,7 +61,7 @@ CANBoard::CANBoard(robot::types::boardid_t board_id, CANDevice_t device)
6161
6262void CANBoard::setMotorPower (double power) {
6363 if (!this ->device .motorDomain ) {
64- LOG_F (WARNING , " setMotorPower called for board 0x%x not in motor domain!" , this ->device . deviceUUID );
64+ LOG_F (WARNING , " setMotorPower called for %s board not in motor domain!" , util::to_string ( this ->board_id ). c_str () );
6565 return ;
6666 }
6767
@@ -72,14 +72,19 @@ void CANBoard::setMotorPower(double power) {
7272 this ->setMotorState (can::motor::axis_state_t ::closed_loop_control);
7373
7474 if (power == 0.0 ) {
75+ if (this ->board_id == robot::types::boardid_t ::shoulder || this ->board_id == robot::types::boardid_t ::elbow) {
76+ // Set brake
77+ this ->setBrake (BRAKE_ON );
78+ }
79+
7580 if (this ->watchdog ) {
7681 this ->setMotorState (can::motor::axis_state_t ::idle);
7782
7883 if (nlohmann::json endpoint = getEndpoint (this ->board_id , " axis0.current_state" ); endpoint != nullptr ) {
7984 uint16_t endpoint_id = endpoint[" id" ];
8085 addDirectReadCallback (this ->device , endpoint_id, [this , endpoint_id](auto decoded) {
8186 if (decoded.value_uint8 != static_cast <uint8_t >(can::motor::axis_state_t ::idle)) {
82- LOG_F (ERROR , " 0x%x DID NOT LISTEN AND IS NOT IDLE AND IS INSTEAD %d" , this ->device .deviceUUID , decoded.value_uint8 );
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 );
8388 this ->setMotorState (can::motor::axis_state_t ::idle);
8489 this ->read (endpoint_id);
8590 } else {
@@ -89,19 +94,18 @@ void CANBoard::setMotorPower(double power) {
8994
9095 this ->read (endpoint_id);
9196 }
92- } else if (this ->board_id == robot::types::boardid_t ::shoulder || this ->board_id == robot::types::boardid_t ::elbow) {
93- // Set motor general lockin vel to 0
94- this ->setMotorState (can::motor::axis_state_t ::lockin_spin);
95- }
96-
97- if (nlohmann::json endpoint = getEndpoint (this ->board_id , " axis0.controller.input_vel" ); endpoint != nullptr ) {
98- uint16_t endpoint_id = endpoint[" id" ];
99- removeDirectReadCallback (this ->device , endpoint_id);
10097 }
10198 } else {
10299 // Mapping power to a target velocity
103- float input_vel = static_cast <float >(power * this ->vel_limit );
100+ float input_vel = static_cast <float >(power * this ->vel_limit ) * 0.4 ; // hard-coded 40%
104101 input_vel *= this ->inversion_factor ;
102+
103+ // LOG_F(INFO, "True input velocity %f, ", input_vel);
104+
105+ if (this ->board_id == robot::types::boardid_t ::shoulder || this ->board_id == robot::types::boardid_t ::elbow) {
106+ this ->setBrake (BRAKE_OFF );
107+ }
108+
105109 // Make CANPacket_t
106110 CANPacket_t p = CANMotorPacket_BLDC_SetInputVelocity (
107111 Constants::JETSON_DEVICE , this ->device , input_vel, 0 .0f
@@ -116,6 +120,8 @@ void CANBoard::setMotorPower(double power) {
116120 if (decoded.value_float != input_vel) {
117121 LOG_F (ERROR , " Expected %f, got %f" , input_vel, decoded.value_float );
118122 sendCANPacket (p);
123+ } else {
124+ LOG_F (INFO , " Got %f vel_limit :)" , decoded.value_float );
119125 }
120126 });
121127
@@ -126,7 +132,7 @@ void CANBoard::setMotorPower(double power) {
126132
127133void CANBoard::setMotorState (can::motor::axis_state_t state) {
128134 if (!this ->device .motorDomain ) {
129- LOG_F (WARNING , " setMotorState called for board 0x%x not in motor domain!" , this ->device . deviceUUID );
135+ LOG_F (WARNING , " setMotorState called for %s board not in motor domain!" , util::to_string ( this ->board_id ). c_str () );
130136 return ;
131137 }
132138
@@ -139,7 +145,7 @@ void CANBoard::setMotorState(can::motor::axis_state_t state) {
139145
140146void CANBoard::setMotorVel (int8_t velocity) {
141147 if (!this ->device .motorDomain ) {
142- LOG_F (WARNING , " setMotorVel called for board 0x%x not in motor domain!" , this ->device . deviceUUID );
148+ LOG_F (WARNING , " setMotorVel called for %s board not in motor domain!" , util::to_string ( this ->board_id ). c_str () );
143149 return ;
144150 }
145151
@@ -156,7 +162,7 @@ void CANBoard::setMotorVel(int8_t velocity) {
156162
157163void CANBoard::setStepperRevs (float revs) {
158164 if (!this ->device .motorDomain ) {
159- LOG_F (WARNING , " setStepperRevs called for board 0x%x not in motor domain!" , this ->device . deviceUUID );
165+ LOG_F (WARNING , " setStepperRevs called for %s board not in motor domain!" , util::to_string ( this ->board_id ). c_str () );
160166 return ;
161167 }
162168
@@ -166,6 +172,20 @@ void CANBoard::setStepperRevs(float revs) {
166172 sendCANPacket (p);
167173}
168174
175+ void CANBoard::setBrake (uint8_t state) {
176+ auto it = robot::boardBrakeIDMap.find (this ->board_id );
177+ if (it == robot::boardBrakeIDMap.end ()) {
178+ LOG_F (WARNING , " setBrake called for %s that does not have a brake!" , util::to_string (this ->board_id ).c_str ());
179+ return ;
180+ }
181+
182+ // hack, but we only have one braking board sooo
183+ CANPacket_t p = CANPeripheralPacket_SetBrakes (
184+ Constants::JETSON_DEVICE , CANDevice_t{1 , 0 , 0 , CAN_UUID_TELEMETRY }, it->second , state
185+ );
186+ sendCANPacket (p);
187+ }
188+
169189void CANBoard::read (uint16_t endpoint) {
170190 CANPacket_t p = CANMotorPacket_BLDC_DirectRead (
171191 Constants::JETSON_DEVICE , this ->device , endpoint
0 commit comments