jordy morsinkhof / Mbed 2 deprecated Handmatig

Dependencies:   USBHost USBHostXpad mbed-rtos mbed

Fork of x4180_Tank by C K

Committer:
hotwheelharry
Date:
Wed Nov 26 22:53:15 2014 +0000
Revision:
3:c1620db50a75
Parent:
2:5e870c215495
Child:
8:36b2ef26a0b1
Movement works. Solenoid digital fire signal and rumble added. Still need audio, and fix the bug where the controller doesn't work when not plugged into usb. It has to do with output to the serial port, not sure what else.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hotwheelharry 0:79485480cd7e 1
hotwheelharry 0:79485480cd7e 2 #include "Traxster.h"
hotwheelharry 0:79485480cd7e 3 #include "utils.h"
hotwheelharry 3:c1620db50a75 4 #include "rtos.h"
hotwheelharry 3:c1620db50a75 5
hotwheelharry 3:c1620db50a75 6 //extern Serial pc;
hotwheelharry 3:c1620db50a75 7 //extern Mutex m;
hotwheelharry 0:79485480cd7e 8
hotwheelharry 0:79485480cd7e 9 int getMotorSpeedInt(float f){
hotwheelharry 0:79485480cd7e 10
hotwheelharry 0:79485480cd7e 11 int max = 100;
hotwheelharry 0:79485480cd7e 12
hotwheelharry 0:79485480cd7e 13 if(f > 1.0)
hotwheelharry 0:79485480cd7e 14 f = 1.0;
hotwheelharry 0:79485480cd7e 15
hotwheelharry 0:79485480cd7e 16 if(f < -1.0)
hotwheelharry 0:79485480cd7e 17 f = -1.0;
hotwheelharry 0:79485480cd7e 18
hotwheelharry 0:79485480cd7e 19 return (int)round( (float)max * f );
hotwheelharry 0:79485480cd7e 20 }
hotwheelharry 0:79485480cd7e 21
hotwheelharry 0:79485480cd7e 22 void Traxster::SetMotors(float fm1, float fm2)
hotwheelharry 0:79485480cd7e 23 {
hotwheelharry 0:79485480cd7e 24 int m1 = getMotorSpeedInt(fm1);
hotwheelharry 0:79485480cd7e 25 int m2 = getMotorSpeedInt(fm2);
hotwheelharry 0:79485480cd7e 26
hotwheelharry 2:5e870c215495 27 //clear robot msgs
hotwheelharry 2:5e870c215495 28 while (rob.readable())
hotwheelharry 2:5e870c215495 29 rob.getc();
hotwheelharry 2:5e870c215495 30
hotwheelharry 0:79485480cd7e 31 if (m1 == 0 && m2 == 0)
hotwheelharry 0:79485480cd7e 32 {
hotwheelharry 0:79485480cd7e 33 rob.puts("stop\r");
hotwheelharry 0:79485480cd7e 34 }
hotwheelharry 0:79485480cd7e 35 else
hotwheelharry 0:79485480cd7e 36 {
hotwheelharry 3:c1620db50a75 37 //m.lock();
hotwheelharry 3:c1620db50a75 38 //pc.printf("mogo 1:%d 2:%d\r\n", m1, m2);
hotwheelharry 3:c1620db50a75 39 //m.unlock();
hotwheelharry 0:79485480cd7e 40 rob.printf("mogo 1:%d 2:%d\r", m1, m2);
hotwheelharry 0:79485480cd7e 41 }
hotwheelharry 2:5e870c215495 42
hotwheelharry 2:5e870c215495 43 //clear robot msgs
hotwheelharry 0:79485480cd7e 44 while (rob.readable())
hotwheelharry 0:79485480cd7e 45 rob.getc();
hotwheelharry 0:79485480cd7e 46 }