Skip to content

Commit 4d797dd

Browse files
committed
update lat disp and long disp calculation to fix datatype issue
1 parent 9bd53ee commit 4d797dd

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

firmware/sensor_microcontroller/src/JoystickFunctions.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@ RefDisplacement joystickToDisplacement(Adafruit_ADS1115 &adc){
2626
*/
2727

2828
//Converting the speeds so they start around 0 and then go positive and negative
29-
// displacements.longDisp = forwardJoystick - (8500+4400); //The second value is used to zero it out when the ADC gain is set to 0 instead of the default (2/3)
30-
// displacements.latDisp = sidewaysJoystick - (8400+4400);
29+
forwardJoystick = forwardJoystick - (8500+4400); //The second value is used to zero it out when the ADC gain is set to 0 instead of the default (2/3)
30+
sidewaysJoystick = sidewaysJoystick - (8400+4400);
31+
32+
const float MAX_INPUT = 13000.0f;
33+
float y = constrain(forwardJoystick / MAX_INPUT, -1.0f, 1.0f);
34+
float x = constrain(sidewaysJoystick / MAX_INPUT, -1.0f, 1.0f);
3135

32-
displacements.longDisp = forwardJoystick;
33-
displacements.latDisp = sidewaysJoystick;
36+
displacements.longDisp = (int16_t)roundf(y * 100.0f);
37+
displacements.latDisp = (int16_t)roundf(x * 100.0f);
3438
return displacements;
3539
}
3640

0 commit comments

Comments
 (0)