Test code for motors, sensors and leds

Dependencies:   PRRobot mbed

Committer:
jah128
Date:
Sat Nov 26 17:29:53 2016 +0000
Revision:
0:e0510fa64cef
Child:
1:17d31177e3c0
Initial commit; test code for motors, sensors and leds

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jah128 0:e0510fa64cef 1 #include "mbed.h"
jah128 0:e0510fa64cef 2 #include "robot.h"
jah128 0:e0510fa64cef 3
jah128 0:e0510fa64cef 4 DigitalOut myled(LED1);
jah128 0:e0510fa64cef 5 Robot robot;
jah128 0:e0510fa64cef 6
jah128 0:e0510fa64cef 7
jah128 0:e0510fa64cef 8 int main() {
jah128 0:e0510fa64cef 9 pc.baud(115200);
jah128 0:e0510fa64cef 10 pc.printf("PR Robot\n");
jah128 0:e0510fa64cef 11 robot.init();
jah128 0:e0510fa64cef 12 motors.init();
jah128 0:e0510fa64cef 13 led.start_test();
jah128 0:e0510fa64cef 14
jah128 0:e0510fa64cef 15 while(1){
jah128 0:e0510fa64cef 16 for(int i=1;i<100;i++){
jah128 0:e0510fa64cef 17 pc.printf("Speed: %1.2f [I=%2.4f] \n",0.01*i,motors.get_current_left());
jah128 0:e0510fa64cef 18 motors.set_left_motor_speed(0.01 * i);
jah128 0:e0510fa64cef 19 wait(0.5);
jah128 0:e0510fa64cef 20 }
jah128 0:e0510fa64cef 21 motors.brake();
jah128 0:e0510fa64cef 22 wait(0.5);
jah128 0:e0510fa64cef 23 for(int i=1;i<100;i++){
jah128 0:e0510fa64cef 24 pc.printf("Speed: -%1.2f [I=%2.4f] \n",0.01*i,motors.get_current_left());
jah128 0:e0510fa64cef 25 motors.set_left_motor_speed(-0.01 * i);
jah128 0:e0510fa64cef 26 wait(0.5);
jah128 0:e0510fa64cef 27 }
jah128 0:e0510fa64cef 28 motors.coast();
jah128 0:e0510fa64cef 29 wait(0.5);
jah128 0:e0510fa64cef 30 }
jah128 0:e0510fa64cef 31 while(1) {
jah128 0:e0510fa64cef 32 myled = 1;
jah128 0:e0510fa64cef 33 /*
jah128 0:e0510fa64cef 34 for(int i=0;i<8;i++){
jah128 0:e0510fa64cef 35 pc.printf("Sensor %d: %d\n",i,sensors.read_adc_value(i));
jah128 0:e0510fa64cef 36 wait(0.05);
jah128 0:e0510fa64cef 37 }
jah128 0:e0510fa64cef 38 */
jah128 0:e0510fa64cef 39
jah128 0:e0510fa64cef 40 pc.printf("Sensor 2: %d\n",sensors.get_adc_value(2));
jah128 0:e0510fa64cef 41 wait(0.1);
jah128 0:e0510fa64cef 42 myled = 0;
jah128 0:e0510fa64cef 43 wait(0.1);
jah128 0:e0510fa64cef 44 // pc.printf("V: %3.3f\n",robot.get_battery_voltage());
jah128 0:e0510fa64cef 45 }
jah128 0:e0510fa64cef 46 }