Code for autonomous rover for Sparkfun AVC. DataBus won 3rd in 2012 and the same code was used on Troubled Child, a 1986 Jeep Grand Wagoneer to win 1st in 2014.
Dependencies: mbed Watchdog SDFileSystem DigoleSerialDisp
Diff: Actuators/Steering/Steering.h
- Revision:
- 15:01fb4916a5cd
- Parent:
- 2:fbc6e3cf3ed8
diff -r 86ee4d840f6b -r 01fb4916a5cd Actuators/Steering/Steering.h --- a/Actuators/Steering/Steering.h Thu Nov 29 16:59:39 2018 +0000 +++ b/Actuators/Steering/Steering.h Thu Nov 29 17:11:34 2018 +0000 @@ -2,6 +2,9 @@ #define __STEERING_H #include "globals.h" +#include "devices.h" +#include "Servo.h" +#include "Config.h" /** A class for managing steering angle calculations based on current and desired heading * and specified intercept distance along the new path. @@ -11,19 +14,55 @@ class Steering { public: - /** create a new steering calculator + /** create a new steering calculator */ + Steering(PinName pin); + + /** Initalize steering actuator (servo) + * + */ + void initSteering(void); + + + /** Set the track width (left to right contact patch distance) * - * @param wheelbase vehicle wheelbase - * @param track vehicle track width - * @param intercept new course intercept distance + * @param track is the vehicle track width */ - Steering(float wheelbase, float track); + void setTrack(float track); + + + /** Set the wheelbase (front to rear axle distance) + * + * @param wheelbase is the vehicle wheelbase + */ + void setWheelbase(float wheelbase); + /** set intercept distance * @param intercept distance along new course at which turn arc will intercept */ void setIntercept(float intercept); + + /** set steering scale factor to convert between steering angle and servo output + * @param scale is the scale factor + */ + void setScale(float scale); + + + /** Convert steerAngle to servo value + * + * Testing determined near linear conversion between servo ms setting and steering angle + * up to ~20*. + * + * @param steerAngle is the steering angle, measured at front wheels, averaged + */ + void setSteering(float steerAngle); + + + /** Shorthand for the write function */ + float operator= (float steerAngle); + + /** convert course change to average steering angle * assumes Ackerman steering, with track and wheelbase * and course intercept distance specified. @@ -35,6 +74,7 @@ */ float calcSA(float theta); + /** convert course change to average steering angle * assumes Ackerman steering, with track and wheelbase * and course intercept distance specified. Also, |radius| of turn is limited to limit @@ -47,28 +87,42 @@ */ float calcSA(float theta, float limit); + /** compute steering angle based on pure pursuit algorithm */ float purePursuitSA(float hdg, float Bx, float By, float Ax, float Ay, float Cx, float Cy); + /** compute steering angle based on a simpler path pursuit variant of pure pursuit */ float pathPursuitSA(float hdg, float Bx, float By, float Ax, float Ay, float Cx, float Cy); + /** Compute cross track error given last waypoint, next waypoint, and robot coordinates * @returns cross track error */ float crossTrack(float Bx, float By, float Ax, float Ay, float Cx, float Cy); - - private: + - inline static float angle_radians(float deg) {return (PI/180.0)*deg;} + /** Convert degrees to radians + * @param deg degrees to convert + * @return radians + */ + inline static float toRadians(float deg) {return (PI/180.0)*deg;} + - inline static float angle_degrees(float rad) {return (180/PI)*rad;} + /** Convert radians to degrees + * @param rad radians to convert + * @return degrees + */ + inline static float toDegrees(float rad) {return (180/PI)*rad;} - float _wheelbase; - float _track; - float _intercept; + private: + Servo _steering; // Steering Servo + float _scale; // Steering scale factor + float _track; // vehicle track used for steering intercept calc + float _wheelbase; // vehicle wheelbase used for steering intercept calc + float _intercept; // circle intercept distance }; -#endif \ No newline at end of file +#endif