Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.

Dependencies:   Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo

Committer:
shimniok
Date:
Wed Jun 20 14:57:48 2012 +0000
Revision:
0:826c6171fc1b
Updated documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 0:826c6171fc1b 1 #include "mbed.h"
shimniok 0:826c6171fc1b 2 #include "Servo.h"
shimniok 0:826c6171fc1b 3 #include "Config.h"
shimniok 0:826c6171fc1b 4
shimniok 0:826c6171fc1b 5 extern Config config;
shimniok 0:826c6171fc1b 6
shimniok 0:826c6171fc1b 7 Servo steering(p21); // Steering Servo
shimniok 0:826c6171fc1b 8 Servo throttle(p22); // ESC
shimniok 0:826c6171fc1b 9 int escMax=520; // Servo setting for max speed
shimniok 0:826c6171fc1b 10
shimniok 0:826c6171fc1b 11 #define THROTTLE_CENTER 0.4
shimniok 0:826c6171fc1b 12
shimniok 0:826c6171fc1b 13 void initSteering()
shimniok 0:826c6171fc1b 14 {
shimniok 0:826c6171fc1b 15 // Setup steering servo
shimniok 0:826c6171fc1b 16 steering = config.steerZero;
shimniok 0:826c6171fc1b 17 // TODO: 3 parameterize this in config file
shimniok 0:826c6171fc1b 18 steering.calibrate(0.005, 45.0);
shimniok 0:826c6171fc1b 19 }
shimniok 0:826c6171fc1b 20
shimniok 0:826c6171fc1b 21
shimniok 0:826c6171fc1b 22 void initThrottle()
shimniok 0:826c6171fc1b 23 {
shimniok 0:826c6171fc1b 24 throttle = (float)config.escZero/1000.0;
shimniok 0:826c6171fc1b 25 // TODO: 3 parameterize this in config file
shimniok 0:826c6171fc1b 26 throttle.calibrate(0.001, 45.0);
shimniok 0:826c6171fc1b 27 }
shimniok 0:826c6171fc1b 28
shimniok 0:826c6171fc1b 29 void setThrottle(int value)
shimniok 0:826c6171fc1b 30 {
shimniok 0:826c6171fc1b 31 throttle = ((float)value)/1000.0;
shimniok 0:826c6171fc1b 32 }
shimniok 0:826c6171fc1b 33
shimniok 0:826c6171fc1b 34 void setSteering(float steerAngle)
shimniok 0:826c6171fc1b 35 {
shimniok 0:826c6171fc1b 36 // Convert steerAngle to servo value
shimniok 0:826c6171fc1b 37 // Testing determined near linear conversion between servo ms setting and steering angle
shimniok 0:826c6171fc1b 38 // up to 20*. Assumes a particular servo library with range = 0.005
shimniok 0:826c6171fc1b 39 // In that case, f(SA) = servoPosition = 0.500 + SA/762.5
shimniok 0:826c6171fc1b 40 // between 20 and 24* the slope is approximately 475
shimniok 0:826c6171fc1b 41 // What if we ignore the linearity and just set to a max angle
shimniok 0:826c6171fc1b 42 // also range is 0.535-0.460 --> slope = 800
shimniok 0:826c6171fc1b 43 // steering = 0.500 + (double) steerAngle / 762.5;
shimniok 0:826c6171fc1b 44 //
shimniok 0:826c6171fc1b 45 // TODO: 1 parameterize through config
shimniok 0:826c6171fc1b 46 steering = 0.500 + (double) steerAngle / 808.0;
shimniok 0:826c6171fc1b 47 }
shimniok 0:826c6171fc1b 48