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 ros_lib_kinetic
main.cpp@6:2ffa254e8f6e, 2018-03-06 (annotated)
- Committer:
- MikeGray92
- Date:
- Tue Mar 06 21:44:07 2018 +0000
- Revision:
- 6:2ffa254e8f6e
- Parent:
- 5:7e59733b02b2
- Child:
- 7:950b3c3b5a2b
Added Comments; Changed the order of rosInput values (0 - neg, 1 -nothing, 2 - pos); Changed Roll limits
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikeGray92 | 4:89ebfa37663b | 1 | /* |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 2 | * Code for the Module Microcontroller as part of the |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 3 | * Autonomous Camera Kart project. |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 4 | * Controls the Gimbal motors, raise and lower mechanism, |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 5 | * IMU sensor input, communication with the NUC onboard computer. |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 6 | */ |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 7 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 8 | // Library Includes |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 9 | #include <stdint.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 10 | #include "mbed.h" |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 11 | #include <ros.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 12 | #include <std_msgs/Empty.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 13 | #include <std_msgs/Float32MultiArray.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 14 | #include <BNO055.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 15 | #include <initializations.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 16 | #include <definitions.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 17 | #include <prototypes.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 18 | #include <Mx28.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 19 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 20 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 21 | // Micro Module Declarations |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 22 | PwmOut liftSpeed(D10); // Normally D10 |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 23 | DigitalOut liftDirection(D11); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 24 | DigitalIn button(USER_BUTTON); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 25 | Ticker hallInt; |
MikeGray92 | 1:1ac7d472cfa2 | 26 | Timer filter_hall1; |
MikeGray92 | 4:89ebfa37663b | 27 | Timer rosMode_Delay; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 28 | DynamixelClass gimbal(57600, D7, D8, D2); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 29 | |
MikeGray92 | 2:0537a8007a39 | 30 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 31 | ros::NodeHandle nh; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 32 | ros::Subscriber<std_msgs::Float32MultiArray> sub("module_command", &module_commandCB); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 33 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 34 | // Global Variable |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 35 | struct fields control; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 36 | struct fields rosInput; |
MikeGray92 | 1:1ac7d472cfa2 | 37 | volatile int currentPosition = 0; |
MikeGray92 | 1:1ac7d472cfa2 | 38 | int prevPosition = 0; |
MikeGray92 | 4:89ebfa37663b | 39 | int stallcount = 0; |
MikeGray92 | 4:89ebfa37663b | 40 | bool rosFlag = 1; |
MikeGray92 | 2:0537a8007a39 | 41 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 42 | // Main Program |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 43 | int main() { |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 44 | // Initializations |
MikeGray92 | 4:89ebfa37663b | 45 | filter_hall1.start(); //Start Filtering Timer |
MikeGray92 | 2:0537a8007a39 | 46 | setupGimbal(); // Gimbal |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 47 | setupLift(); // Lift |
MikeGray92 | 4:89ebfa37663b | 48 | setupROSNode(nh, sub); // ROS Node Handle |
MikeGray92 | 4:89ebfa37663b | 49 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 50 | // Main Loop |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 51 | while (1) { |
MikeGray92 | 4:89ebfa37663b | 52 | // Lift Operation |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 53 | runLift(); |
MikeGray92 | 4:89ebfa37663b | 54 | //Run Gimbal |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 55 | runGimbal(); |
MikeGray92 | 4:89ebfa37663b | 56 | //ROS Functions |
MikeGray92 | 4:89ebfa37663b | 57 | nh.spinOnce(); |
MikeGray92 | 4:89ebfa37663b | 58 | rosCheck(); |
MikeGray92 | 4:89ebfa37663b | 59 | } |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 60 | } |