Closed gnbl closed 5 years ago
The main purpose of the SPEED_COEFFICIENT is to adjust the slope or the power if you want on the Input. Of course, if you put it to negative the motor will spin in the opposite direction, however it is not intended to be used to reverse direction.
For reversing direction, depending on your needs, you should comment or un-comment one or both of the following lines:
#define INVERT_R_DIRECTION
#define INVERT_L_DIRECTION
With this I think the task can be closed.
I think reversing should be possible at runtime by input, unless you want the scope of this firmware to be limited to one direction (two-wheelers like scooters etc.).
I think reversing should be possible at runtime by input, unless you want the scope of this firmware to be limited to one direction (two-wheelers like scooters etc.).
Of course, indeed, you can always reverse the direction by input. The parameters I was referring is for establishing the behavior of the input.. more exactly sign of the input in connection with sign of the motor speed.
EDIT: If you want to drive both directions via ADC input. As you mentioned, you need to use an offset on the ADC input. I don't see another way at this moment.
yes, you can use that. Although the input resolution would be half, because we go from [0, 1000] -> [-1000, 1000] (using integer data type). If I have time, I will think of something, immediately after the ADC is read to not loose resolution.
How about this?
cmd1 = (CLAMP(adc_buffer.l_tx2 - ADC1_MIN, 0, ADC1_MAX) * 2000 / ADC1_MAX) - 1000; // ADC1 steer
cmd2 = (CLAMP(adc_buffer.l_rx2 - ADC2_MIN, 0, ADC2_MAX) * 2000 / ADC2_MAX) - 1000; // ADC2 speed
What changes are required to allow "reversing" of the speed? Should this be done at the CONTROL_xxx level (main.c) or would the introduction of e.g. SPEED_OFFSET and STEER_OFFSET be preferable?
Btw,
seem both to be defined by default, but there is no explanation as to why this is required in addition to SPEED_COEFFICIENT.