lucysrausch / hoverboard-firmware-hack

New Hoverboard Firmware Hack. Now written from scratch and generally much better.
GNU General Public License v3.0
686 stars 401 forks source link

Controlling the two motors independently #128

Closed blubbi321 closed 4 years ago

blubbi321 commented 4 years ago

I have a robot on which I'll need the two connected wheels to turn

Best would be to have a really dumb controller (to which I just provide a value per motor in which the sign determines the motor's direction and the absolute value determines the speed) .. So I tried to get rid of all the speed/steering coefficents and in main.c replaced

speedR = CLAMP(speed * SPEED_COEFFICIENT -  steer * STEER_COEFFICIENT, -1000, 1000);
speedL = CLAMP(speed * SPEED_COEFFICIENT +  steer * STEER_COEFFICIENT, -1000, 1000);

with

speedR = CLAMP(speed, -1000, 1000);
speedL = CLAMP(steer, -1000, 1000);

expecting that I could now use the speed signal to control the right and the steer signal to control the left motor.

However, when I turn things on I still get both wheels turning, even when only providing a speed value (via UART).

Any pointers anybody?

EFeru commented 4 years ago

To me what you did is correct to make them completely independend. Did you check that cmd1 and cmd2 are indeed different? And also speedR and speedL as well different? I assume some issue with reading the serial command.

blubbi321 commented 4 years ago

@EmanuelFeru thanks for your reply, will double check via the uart output ..

blubbi321 commented 4 years ago

@EmanuelFeru sorry for the long delay. So I checked and indeed the values for cmd1 and cmd2 are the same. What I send in is produced by the arduino code sample from the config file, ie

Serial.write((uint8_t *)&steer_value, sizeof(steer_value));
Serial.write((uint8_t *)&speed_value, sizeof(speed_value));

Writing 1 for the steer value results in this on UART:

grafik

Which results in 1 == cmd1 == cmd2

Any ideas?

EFeru commented 4 years ago

That is strange... I also implemented serial commands in my repo and it worked. The thing I did differently is that I used a structure instead. So I defined:

typedef struct{
   uint16_t start;
   int16_t  steer;
   int16_t  speed;
   uint16_t checksum;
} SerialCommand;
SerialCommand Command;

and then I send the whole structure at once, i.e.:

HoverSerial.write((uint8_t *) &Command, sizeof(Command)); 

You can see the whole Arduino code here: https://github.com/EmanuelFeru/hoverboard-firmware-hack-FOC/blob/master/02_Arduino/hoverserial/hoverserial.ino

blubbi321 commented 4 years ago

Ok, I tried it out with your fork, everything worked out of the box/repo ;)

Thanks a lot! Also I have to check out all the different variants you implemented, looks very nice!