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@14:0e6b26c1a7c5, 2019-04-25 (annotated)
- Committer:
- rpatelpj
- Date:
- Thu Apr 25 03:21:17 2019 +0000
- Revision:
- 14:0e6b26c1a7c5
- Parent:
- 11:531208aca075
- Child:
- 17:e1a5d25218de
Added rotation error correction and lidar functionality 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 | #include "XNucleo53L0A1.h" |
rpatelpj | 8:bfa4bf23522c | 9 | |
rpatelpj | 8:bfa4bf23522c | 10 | #define COUNTPERIN 75.029 ///< Encoder counts 192 every 65 mm of wheel rotation |
rpatelpj | 8:bfa4bf23522c | 11 | #define COUNTPERDEG 1.21 ///< Encoder counts 2.42 every 1 deg of body rotation |
rpatelpj | 14:0e6b26c1a7c5 | 12 | #define ROTERRI 0.730 ///< 90 commanded rotation overshoot compensation |
rpatelpj | 14:0e6b26c1a7c5 | 13 | #define ROTERRII 0.770 ///< 180 commanded rotation overshoot compensation |
rpatelpj | 14:0e6b26c1a7c5 | 14 | #define ROTERRIII 0.810 ///< 270, 360 commanded rotation overshoot compensation |
rpatelpj | 14:0e6b26c1a7c5 | 15 | #define MMTOIN 0.0393701 ///< Metric to emperical length conversion |
rpatelpj | 3:1dce1ba5b8bd | 16 | |
rpatelpj | 3:1dce1ba5b8bd | 17 | /** |
rpatelpj | 5:77c6821ae418 | 18 | * Robot Controller class. |
rpatelpj | 3:1dce1ba5b8bd | 19 | */ |
rpatelpj | 3:1dce1ba5b8bd | 20 | class RobotController { |
rpatelpj | 3:1dce1ba5b8bd | 21 | public: |
rpatelpj | 3:1dce1ba5b8bd | 22 | /** |
rpatelpj | 11:531208aca075 | 23 | * Robot Controller constructor. |
rpatelpj | 5:77c6821ae418 | 24 | * @param leftWheelPwm mbed pin transmitting speed to left motor driver |
rpatelpj | 5:77c6821ae418 | 25 | * @param leftWheelFwd mbed pin transmitting forward direction to left motor driver |
rpatelpj | 5:77c6821ae418 | 26 | * @param leftWheelRev mbed pin transmitting reverse direction to left motor driver |
rpatelpj | 5:77c6821ae418 | 27 | * @param rightWheelPwm mbed pin transmitting speed to right motor driver |
rpatelpj | 5:77c6821ae418 | 28 | * @param rightWheelFwd mbed pin transmitting forward direction to right motor driver |
rpatelpj | 5:77c6821ae418 | 29 | * @param rightWheelRev mbed pin transmitting reverse direction to right motor driver |
rpatelpj | 8:bfa4bf23522c | 30 | * @param leftEncoder mbed pin receiving rotation count from left encoder |
rpatelpj | 8:bfa4bf23522c | 31 | * @param rightEncoder mbed pin receiving rotation count from right encoder |
rpatelpj | 14:0e6b26c1a7c5 | 32 | * @param lidarShdn mbed pin commanding lidar reset |
rpatelpj | 14:0e6b26c1a7c5 | 33 | * @param sda mbed pin for I2C data line |
rpatelpj | 14:0e6b26c1a7c5 | 34 | * @param scl mbed pin for I2C clock line |
rpatelpj | 5:77c6821ae418 | 35 | */ |
rpatelpj | 5:77c6821ae418 | 36 | RobotController(PinName leftWheelPwm, PinName leftWheelFwd, |
rpatelpj | 5:77c6821ae418 | 37 | PinName leftWheelRev, PinName rightWheelPwm, PinName rightWheelFwd, |
rpatelpj | 11:531208aca075 | 38 | PinName rightWheelRev, PinName leftEncoder, PinName rightEncoder, |
rpatelpj | 14:0e6b26c1a7c5 | 39 | PinName lidarShdn, PinName sda, PinName scl); |
rpatelpj | 11:531208aca075 | 40 | |
rpatelpj | 11:531208aca075 | 41 | /** |
rpatelpj | 11:531208aca075 | 42 | * Robot Controller destructor. |
rpatelpj | 11:531208aca075 | 43 | */ |
rpatelpj | 11:531208aca075 | 44 | ~RobotController(); |
rpatelpj | 11:531208aca075 | 45 | |
rpatelpj | 5:77c6821ae418 | 46 | /** |
rpatelpj | 3:1dce1ba5b8bd | 47 | * Detect obstacles in 360-degree field of view around the robot. |
rpatelpj | 3:1dce1ba5b8bd | 48 | */ |
rpatelpj | 8:bfa4bf23522c | 49 | void detectObstacles(); |
rpatelpj | 3:1dce1ba5b8bd | 50 | |
rpatelpj | 3:1dce1ba5b8bd | 51 | /** |
rpatelpj | 3:1dce1ba5b8bd | 52 | * Follow trajectory set by user in C# GUI. |
rpatelpj | 3:1dce1ba5b8bd | 53 | */ |
rpatelpj | 8:bfa4bf23522c | 54 | void followTrajectory(); |
rpatelpj | 5:77c6821ae418 | 55 | |
rpatelpj | 5:77c6821ae418 | 56 | private: |
rpatelpj | 5:77c6821ae418 | 57 | Motor leftWheel; |
rpatelpj | 5:77c6821ae418 | 58 | Motor rightWheel; |
rpatelpj | 14:0e6b26c1a7c5 | 59 | Encoder _leftEncoder; |
rpatelpj | 14:0e6b26c1a7c5 | 60 | Encoder _rightEncoder; |
rpatelpj | 14:0e6b26c1a7c5 | 61 | DevI2C* lidarDevice; |
rpatelpj | 14:0e6b26c1a7c5 | 62 | XNucleo53L0A1* lidarBoard; |
rpatelpj | 14:0e6b26c1a7c5 | 63 | DigitalOut _lidarShdn; |
rpatelpj | 14:0e6b26c1a7c5 | 64 | uint32_t lidarDistance; |
rpatelpj | 11:531208aca075 | 65 | LSM9DS1 imu; |
rpatelpj | 11:531208aca075 | 66 | Timer t; |
rpatelpj | 14:0e6b26c1a7c5 | 67 | float yaw; |
rpatelpj | 11:531208aca075 | 68 | float w1; |
rpatelpj | 11:531208aca075 | 69 | float w2; |
rpatelpj | 11:531208aca075 | 70 | float t1; |
rpatelpj | 11:531208aca075 | 71 | float t2; |
rpatelpj | 3:1dce1ba5b8bd | 72 | }; |
rpatelpj | 3:1dce1ba5b8bd | 73 | |
rpatelpj | 3:1dce1ba5b8bd | 74 | #endif /* ROBOT_CONTROLLER_H */ |