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

Committer:
shimniok
Date:
Thu Jun 06 13:40:23 2013 +0000
Revision:
2:fbc6e3cf3ed8
Parent:
0:a6a169de725f
Child:
15:01fb4916a5cd
Sort-of working version, still some errors with estimation. Added clamp() function.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 2:fbc6e3cf3ed8 1 #ifndef __STEERING_H
shimniok 2:fbc6e3cf3ed8 2 #define __STEERING_H
shimniok 0:a6a169de725f 3
shimniok 2:fbc6e3cf3ed8 4 #include "globals.h"
shimniok 0:a6a169de725f 5
shimniok 0:a6a169de725f 6 /** A class for managing steering angle calculations based on current and desired heading
shimniok 0:a6a169de725f 7 * and specified intercept distance along the new path.
shimniok 0:a6a169de725f 8 *
shimniok 0:a6a169de725f 9 * See Notebook entry: http://mbed.org/users/shimniok/notebook/smooth-steering-for-rc-car/
shimniok 0:a6a169de725f 10 */
shimniok 0:a6a169de725f 11 class Steering
shimniok 0:a6a169de725f 12 {
shimniok 0:a6a169de725f 13 public:
shimniok 0:a6a169de725f 14 /** create a new steering calculator
shimniok 0:a6a169de725f 15 *
shimniok 0:a6a169de725f 16 * @param wheelbase vehicle wheelbase
shimniok 0:a6a169de725f 17 * @param track vehicle track width
shimniok 0:a6a169de725f 18 * @param intercept new course intercept distance
shimniok 0:a6a169de725f 19 */
shimniok 0:a6a169de725f 20 Steering(float wheelbase, float track);
shimniok 0:a6a169de725f 21
shimniok 0:a6a169de725f 22 /** set intercept distance
shimniok 0:a6a169de725f 23 * @param intercept distance along new course at which turn arc will intercept
shimniok 0:a6a169de725f 24 */
shimniok 0:a6a169de725f 25 void setIntercept(float intercept);
shimniok 0:a6a169de725f 26
shimniok 0:a6a169de725f 27 /** convert course change to average steering angle
shimniok 0:a6a169de725f 28 * assumes Ackerman steering, with track and wheelbase
shimniok 0:a6a169de725f 29 * and course intercept distance specified.
shimniok 0:a6a169de725f 30 *
shimniok 0:a6a169de725f 31 * See notebook: http://mbed.org/users/shimniok/notebook/smooth-steering-for-rc-car/
shimniok 0:a6a169de725f 32 *
shimniok 0:a6a169de725f 33 * @param theta relative bearing of the new course
shimniok 0:a6a169de725f 34 * @returns steering angle in degrees
shimniok 0:a6a169de725f 35 */
shimniok 0:a6a169de725f 36 float calcSA(float theta);
shimniok 0:a6a169de725f 37
shimniok 0:a6a169de725f 38 /** convert course change to average steering angle
shimniok 0:a6a169de725f 39 * assumes Ackerman steering, with track and wheelbase
shimniok 0:a6a169de725f 40 * and course intercept distance specified. Also, |radius| of turn is limited to limit
shimniok 0:a6a169de725f 41 *
shimniok 0:a6a169de725f 42 * See notebook: http://mbed.org/users/shimniok/notebook/smooth-steering-for-rc-car/
shimniok 0:a6a169de725f 43 *
shimniok 0:a6a169de725f 44 * @param theta relative bearing of the new course
shimniok 0:a6a169de725f 45 * @param limit is the limit of the turn circle radius (absolute value)
shimniok 0:a6a169de725f 46 * @returns steering angle in degrees
shimniok 0:a6a169de725f 47 */
shimniok 0:a6a169de725f 48 float calcSA(float theta, float limit);
shimniok 0:a6a169de725f 49
shimniok 0:a6a169de725f 50 /** compute steering angle based on pure pursuit algorithm
shimniok 0:a6a169de725f 51 */
shimniok 0:a6a169de725f 52 float purePursuitSA(float hdg, float Bx, float By, float Ax, float Ay, float Cx, float Cy);
shimniok 0:a6a169de725f 53
shimniok 0:a6a169de725f 54 /** compute steering angle based on a simpler path pursuit variant of pure pursuit
shimniok 0:a6a169de725f 55 */
shimniok 0:a6a169de725f 56 float pathPursuitSA(float hdg, float Bx, float By, float Ax, float Ay, float Cx, float Cy);
shimniok 0:a6a169de725f 57
shimniok 0:a6a169de725f 58 /** Compute cross track error given last waypoint, next waypoint, and robot coordinates
shimniok 0:a6a169de725f 59 * @returns cross track error
shimniok 0:a6a169de725f 60 */
shimniok 0:a6a169de725f 61 float crossTrack(float Bx, float By, float Ax, float Ay, float Cx, float Cy);
shimniok 0:a6a169de725f 62
shimniok 0:a6a169de725f 63 private:
shimniok 0:a6a169de725f 64
shimniok 0:a6a169de725f 65 inline static float angle_radians(float deg) {return (PI/180.0)*deg;}
shimniok 0:a6a169de725f 66
shimniok 0:a6a169de725f 67 inline static float angle_degrees(float rad) {return (180/PI)*rad;}
shimniok 0:a6a169de725f 68
shimniok 0:a6a169de725f 69 float _wheelbase;
shimniok 0:a6a169de725f 70 float _track;
shimniok 0:a6a169de725f 71 float _intercept;
shimniok 2:fbc6e3cf3ed8 72 };
shimniok 2:fbc6e3cf3ed8 73
shimniok 2:fbc6e3cf3ed8 74 #endif