jordy morsinkhof / Mbed 2 deprecated Handmatig

Dependencies:   USBHost USBHostXpad mbed-rtos mbed

Fork of x4180_Tank by C K

Committer:
hotwheelharry
Date:
Sat Nov 15 21:42:16 2014 +0000
Revision:
2:5e870c215495
Parent:
0:79485480cd7e
Child:
3:c1620db50a75
thread tweaks

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 0:79485480cd7e 4
hotwheelharry 0:79485480cd7e 5 int getMotorSpeedInt(float f){
hotwheelharry 0:79485480cd7e 6
hotwheelharry 0:79485480cd7e 7 int max = 100;
hotwheelharry 0:79485480cd7e 8
hotwheelharry 0:79485480cd7e 9 if(f > 1.0)
hotwheelharry 0:79485480cd7e 10 f = 1.0;
hotwheelharry 0:79485480cd7e 11
hotwheelharry 0:79485480cd7e 12 if(f < -1.0)
hotwheelharry 0:79485480cd7e 13 f = -1.0;
hotwheelharry 0:79485480cd7e 14
hotwheelharry 0:79485480cd7e 15 return (int)round( (float)max * f );
hotwheelharry 0:79485480cd7e 16 }
hotwheelharry 0:79485480cd7e 17
hotwheelharry 0:79485480cd7e 18 void Traxster::SetMotors(float fm1, float fm2)
hotwheelharry 0:79485480cd7e 19 {
hotwheelharry 0:79485480cd7e 20 int m1 = getMotorSpeedInt(fm1);
hotwheelharry 0:79485480cd7e 21 int m2 = getMotorSpeedInt(fm2);
hotwheelharry 0:79485480cd7e 22
hotwheelharry 2:5e870c215495 23 //clear robot msgs
hotwheelharry 2:5e870c215495 24 while (rob.readable())
hotwheelharry 2:5e870c215495 25 rob.getc();
hotwheelharry 2:5e870c215495 26
hotwheelharry 0:79485480cd7e 27 if (m1 == 0 && m2 == 0)
hotwheelharry 0:79485480cd7e 28 {
hotwheelharry 0:79485480cd7e 29 rob.puts("stop\r");
hotwheelharry 0:79485480cd7e 30 }
hotwheelharry 0:79485480cd7e 31 else
hotwheelharry 0:79485480cd7e 32 {
hotwheelharry 0:79485480cd7e 33 rob.printf("mogo 1:%d 2:%d\r", m1, m2);
hotwheelharry 0:79485480cd7e 34 }
hotwheelharry 2:5e870c215495 35
hotwheelharry 2:5e870c215495 36 //clear robot msgs
hotwheelharry 0:79485480cd7e 37 while (rob.readable())
hotwheelharry 0:79485480cd7e 38 rob.getc();
hotwheelharry 0:79485480cd7e 39 }