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@8:478f75c6109c, 2018-03-15 (annotated)
- Committer:
- MikeGray92
- Date:
- Thu Mar 15 19:20:23 2018 +0000
- Revision:
- 8:478f75c6109c
- Parent:
- 7:950b3c3b5a2b
- Child:
- 10:836e701d00a6
Fix issue when in transport mode, the system would not go to preset positions
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> |
MikeGray92 | 7:950b3c3b5a2b | 13 | #include <std_msgs/Int32MultiArray.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 | // Micro Module Declarations |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 21 | PwmOut liftSpeed(D10); // Normally D10 |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 22 | DigitalOut liftDirection(D11); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 23 | DigitalIn button(USER_BUTTON); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 24 | Ticker hallInt; |
MikeGray92 | 1:1ac7d472cfa2 | 25 | Timer filter_hall1; |
MikeGray92 | 4:89ebfa37663b | 26 | Timer rosMode_Delay; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 27 | DynamixelClass gimbal(57600, D7, D8, D2); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 28 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 29 | ros::NodeHandle nh; |
MikeGray92 | 7:950b3c3b5a2b | 30 | ros::Subscriber<std_msgs::Int32MultiArray> sub("module_command", &module_commandCB); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 31 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 32 | // Global Variable |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 33 | struct fields control; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 34 | struct fields rosInput; |
MikeGray92 | 1:1ac7d472cfa2 | 35 | volatile int currentPosition = 0; |
MikeGray92 | 1:1ac7d472cfa2 | 36 | int prevPosition = 0; |
MikeGray92 | 4:89ebfa37663b | 37 | int stallcount = 0; |
MikeGray92 | 4:89ebfa37663b | 38 | bool rosFlag = 1; |
MikeGray92 | 2:0537a8007a39 | 39 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 40 | // Main Program |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 41 | int main() { |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 42 | // Initializations |
MikeGray92 | 4:89ebfa37663b | 43 | filter_hall1.start(); //Start Filtering Timer |
MikeGray92 | 2:0537a8007a39 | 44 | setupGimbal(); // Gimbal |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 45 | setupLift(); // Lift |
MikeGray92 | 4:89ebfa37663b | 46 | setupROSNode(nh, sub); // ROS Node Handle |
MikeGray92 | 7:950b3c3b5a2b | 47 | rosInput.yaw = 1; |
MikeGray92 | 7:950b3c3b5a2b | 48 | rosInput.pitch = 1; |
MikeGray92 | 7:950b3c3b5a2b | 49 | rosInput.roll = 1; |
MikeGray92 | 7:950b3c3b5a2b | 50 | rosInput.height = 1; |
MikeGray92 | 7:950b3c3b5a2b | 51 | rosInput.mode = 0; |
MikeGray92 | 4:89ebfa37663b | 52 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 53 | // Main Loop |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 54 | while (1) { |
MikeGray92 | 4:89ebfa37663b | 55 | // Lift Operation |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 56 | runLift(); |
MikeGray92 | 4:89ebfa37663b | 57 | //Run Gimbal |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 58 | runGimbal(); |
MikeGray92 | 4:89ebfa37663b | 59 | //ROS Functions |
MikeGray92 | 4:89ebfa37663b | 60 | nh.spinOnce(); |
MikeGray92 | 8:478f75c6109c | 61 | rosCheck(); |
MikeGray92 | 4:89ebfa37663b | 62 | } |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 63 | } |