The project is not done yet

Dependencies:   USBHost USBHostXpad mbed-rtos mbed

Fork of Totaleprogramma by jordy morsinkhof

Committer:
juliandekker
Date:
Mon Mar 02 10:58:30 2015 +0000
Revision:
1:da390b3b1330
Parent:
0:345f76c72b9a
xbox controller robot

Who changed what in which revision?

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