Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-rtos Motor LSM9DS1_Library_cal X_NUCLEO_53L0A1
RobotController.h@20:d9a373fecd42, 2019-04-25 (annotated)
- Committer:
- rpatelpj
- Date:
- Thu Apr 25 22:13:21 2019 +0000
- Revision:
- 20:d9a373fecd42
- Parent:
- 18:7ed985584ec7
Added shortest rotation and conversion constants to RobotController
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rpatelpj | 3:1dce1ba5b8bd | 1 | #ifndef ROBOT_CONTROLLER_H |
rpatelpj | 3:1dce1ba5b8bd | 2 | #define ROBOT_CONTROLLER_H |
rpatelpj | 3:1dce1ba5b8bd | 3 | |
rpatelpj | 8:bfa4bf23522c | 4 | #include "globals.h" |
rpatelpj | 3:1dce1ba5b8bd | 5 | #include "Motor.h" |
rpatelpj | 11:531208aca075 | 6 | #include "Encoder.h" |
rpatelpj | 11:531208aca075 | 7 | #include "LSM9DS1.h" |
rpatelpj | 8:bfa4bf23522c | 8 | |
rpatelpj | 20:d9a373fecd42 | 9 | #define COUNTTOMM 9.846 ///< Encoder count to distance conversion |
rpatelpj | 14:0e6b26c1a7c5 | 10 | #define ROTERRI 0.730 ///< 90 commanded rotation overshoot compensation |
rpatelpj | 14:0e6b26c1a7c5 | 11 | #define ROTERRII 0.770 ///< 180 commanded rotation overshoot compensation |
rpatelpj | 14:0e6b26c1a7c5 | 12 | #define ROTERRIII 0.810 ///< 270, 360 commanded rotation overshoot compensation |
rpatelpj | 20:d9a373fecd42 | 13 | #define MMTOCM 0.10 ///< Metric to emperical length conversion |
rpatelpj | 3:1dce1ba5b8bd | 14 | |
rpatelpj | 3:1dce1ba5b8bd | 15 | /** |
rpatelpj | 5:77c6821ae418 | 16 | * Robot Controller class. |
rpatelpj | 3:1dce1ba5b8bd | 17 | */ |
rpatelpj | 3:1dce1ba5b8bd | 18 | class RobotController { |
rpatelpj | 3:1dce1ba5b8bd | 19 | public: |
rpatelpj | 3:1dce1ba5b8bd | 20 | /** |
rpatelpj | 11:531208aca075 | 21 | * Robot Controller constructor. |
rpatelpj | 5:77c6821ae418 | 22 | * @param leftWheelPwm mbed pin transmitting speed to left motor driver |
rpatelpj | 5:77c6821ae418 | 23 | * @param leftWheelFwd mbed pin transmitting forward direction to left motor driver |
rpatelpj | 5:77c6821ae418 | 24 | * @param leftWheelRev mbed pin transmitting reverse direction to left motor driver |
rpatelpj | 5:77c6821ae418 | 25 | * @param rightWheelPwm mbed pin transmitting speed to right motor driver |
rpatelpj | 5:77c6821ae418 | 26 | * @param rightWheelFwd mbed pin transmitting forward direction to right motor driver |
rpatelpj | 5:77c6821ae418 | 27 | * @param rightWheelRev mbed pin transmitting reverse direction to right motor driver |
rpatelpj | 8:bfa4bf23522c | 28 | * @param leftEncoder mbed pin receiving rotation count from left encoder |
rpatelpj | 8:bfa4bf23522c | 29 | * @param rightEncoder mbed pin receiving rotation count from right encoder |
rpatelpj | 17:e1a5d25218de | 30 | * @param imuSda mbed pin for imu I2C data line |
rpatelpj | 17:e1a5d25218de | 31 | * @param imuScl mbed pin for imu I2C clock line |
rpatelpj | 5:77c6821ae418 | 32 | */ |
rpatelpj | 5:77c6821ae418 | 33 | RobotController(PinName leftWheelPwm, PinName leftWheelFwd, |
rpatelpj | 5:77c6821ae418 | 34 | PinName leftWheelRev, PinName rightWheelPwm, PinName rightWheelFwd, |
rpatelpj | 11:531208aca075 | 35 | PinName rightWheelRev, PinName leftEncoder, PinName rightEncoder, |
rpatelpj | 17:e1a5d25218de | 36 | PinName imuSda, PinName imuScl); |
rpatelpj | 11:531208aca075 | 37 | |
rpatelpj | 11:531208aca075 | 38 | /** |
rpatelpj | 11:531208aca075 | 39 | * Robot Controller destructor. |
rpatelpj | 11:531208aca075 | 40 | */ |
rpatelpj | 11:531208aca075 | 41 | ~RobotController(); |
rpatelpj | 11:531208aca075 | 42 | |
rpatelpj | 5:77c6821ae418 | 43 | /** |
rpatelpj | 3:1dce1ba5b8bd | 44 | * Detect obstacles in 360-degree field of view around the robot. |
rpatelpj | 3:1dce1ba5b8bd | 45 | */ |
rpatelpj | 8:bfa4bf23522c | 46 | void detectObstacles(); |
rpatelpj | 3:1dce1ba5b8bd | 47 | |
rpatelpj | 3:1dce1ba5b8bd | 48 | /** |
rpatelpj | 3:1dce1ba5b8bd | 49 | * Follow trajectory set by user in C# GUI. |
rpatelpj | 3:1dce1ba5b8bd | 50 | */ |
rpatelpj | 8:bfa4bf23522c | 51 | void followTrajectory(); |
rpatelpj | 5:77c6821ae418 | 52 | |
rpatelpj | 5:77c6821ae418 | 53 | private: |
rpatelpj | 5:77c6821ae418 | 54 | Motor leftWheel; |
rpatelpj | 5:77c6821ae418 | 55 | Motor rightWheel; |
rpatelpj | 14:0e6b26c1a7c5 | 56 | Encoder _leftEncoder; |
rpatelpj | 14:0e6b26c1a7c5 | 57 | Encoder _rightEncoder; |
rpatelpj | 11:531208aca075 | 58 | LSM9DS1 imu; |
rpatelpj | 11:531208aca075 | 59 | Timer t; |
rpatelpj | 14:0e6b26c1a7c5 | 60 | float yaw; |
rpatelpj | 11:531208aca075 | 61 | float w1; |
rpatelpj | 11:531208aca075 | 62 | float w2; |
rpatelpj | 11:531208aca075 | 63 | float t1; |
rpatelpj | 11:531208aca075 | 64 | float t2; |
rpatelpj | 3:1dce1ba5b8bd | 65 | }; |
rpatelpj | 3:1dce1ba5b8bd | 66 | |
rpatelpj | 3:1dce1ba5b8bd | 67 | #endif /* ROBOT_CONTROLLER_H */ |