Conversation
AlexBailey11
left a comment
There was a problem hiding this comment.
see comments for changes
|
|
||
| /* ----- SELF CALIBRATION STATUS 2 ----- */ | ||
| // self-calibration status request again after, expect counter to change | ||
| _serial->write(OrbisCommands::SELF_CALIB_STATUS); delay(1); |
There was a problem hiding this comment.
rather than an if with a hard time limit of 1ms (which is not a lot), we can do while(serial.available < n and custome_timeout_counter < time_out)
This is lowk something you can implement for every single "I need to wait for sensor to respond", including already existing "while(!_serial.available())"
| // After writing POSITION_OFFSET, the next four bytes are what you subtract from your initial position. We want to start at 0, so we first | ||
| // get our initial position, and then send that position as the four bytes. Inital position - inital position = 0. | ||
|
|
||
| while (_serial->available()) { |
There was a problem hiding this comment.
If these are here just to clear the Serial buffer, please note that somewhere
Make it a one liner lowkenuinely
|
|
||
| while (_serial->available() < 4); | ||
|
|
||
| if (_serial->available() < 4) // check if received all 4 bytes |
There was a problem hiding this comment.
technically we don't need this if anymore. You can move this into the while loop as suggested earlier to handle timeout
| _lastConversion.status = anyError ? SteeringEncoderStatus_e::STEERING_ENCODER_ERROR : SteeringEncoderStatus_e::STEERING_ENCODER_NOMINAL; | ||
|
|
||
| // Extract 14-bit position data | ||
| uint16_t raw_position_data = (((uint16_t) general1) << OrbisConstants::POSITION_DATA_MASK_1) | (uint16_t) general2; |
There was a problem hiding this comment.
move this into one line
| // Convert Position Data to Angle | ||
| _lastConversion.raw = _position_data; | ||
|
|
||
| float angle = ((float)_position_data / OrbisConstants::ENCODER_RESOLUTION ) * OrbisConstants::DEGREES_PER_REVOLUTION; |
There was a problem hiding this comment.
note: we do conversion in steeringSystem
| void _decodeErrors(uint8_t general, uint8_t detailed); | ||
|
|
||
| HardwareSerial* _serial; | ||
| SteeringEncoderConversion_s _lastConversion; // initialize variable _lastConversion of type SteeringEncoderConversion_s. |
There was a problem hiding this comment.
name this better. This stores way more than just last conversion
| bool noData = false; // No data received | ||
| }; | ||
|
|
||
| struct SteeringEncoderConversion_s // This is the final struct I would like to send across the car. What's seen in foxglove? |
There was a problem hiding this comment.
rename to be more fit
|
|
||
| } | ||
|
|
||
| SteeringEncoderConversion_s OrbisBR::convert() |
There was a problem hiding this comment.
this is not "convert". rename
| _decodeErrors(general_status, detailed); | ||
|
|
||
| // Decode errors, detailed status bytes | ||
| bool anyError = |
There was a problem hiding this comment.
can we move all of these into your _decodeErrors method
| return; | ||
| } | ||
|
|
||
| uint8_t echo = _serial->read(); |
There was a problem hiding this comment.
goof ahh spacing breh
Changed the interface from Ben's version to speak with the sensor. Offset functionality has been fully tested. Save configuration function has not been saved. Rewrote command structure.