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@0:3a767f41cf04, 2018-01-31 (annotated)
- Committer:
- group-UVic-Assistive-Technolog
- Date:
- Wed Jan 31 05:24:12 2018 +0000
- Revision:
- 0:3a767f41cf04
- Child:
- 1:1ac7d472cfa2
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 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 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 9 | // Library Includes |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 10 | #include <stdint.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 11 | #include "mbed.h" |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 12 | #include <ros.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 13 | #include <std_msgs/Empty.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 14 | #include <std_msgs/Float32MultiArray.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 15 | #include <BNO055.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 16 | #include <initializations.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 17 | #include <definitions.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 18 | #include <prototypes.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 19 | #include <Mx28.h> |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 20 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 21 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 22 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 23 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 24 | // Micro Module Declarations |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 25 | DigitalOut LED(PA_5); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 26 | PwmOut liftSpeed(D10); // Normally D10 |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 27 | DigitalOut liftDirection(D11); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 28 | DigitalIn hallSensor1(D9); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 29 | DigitalIn hallSensor2(D12); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 30 | DigitalIn button(USER_BUTTON); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 31 | Ticker hallInt; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 32 | Ticker dynaInt; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 33 | Ticker imuInt; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 34 | Ticker rosInt; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 35 | BNO055 IMU(D14, D15); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 36 | DynamixelClass gimbal(57600, D7, D8, D2); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 37 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 38 | ros::NodeHandle nh; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 39 | ros::Subscriber<std_msgs::Float32MultiArray> sub("module_command", &module_commandCB); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 40 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 41 | // Global Variable |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 42 | // Variables |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 43 | struct fields control; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 44 | struct fields rosInput; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 45 | bool liftFlag = 0; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 46 | bool motorFlag = 0; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 47 | bool homeFlag = 0; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 48 | bool imuFlag = 0; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 49 | bool rosFlag = 0; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 50 | int currentPosition = LIFTHEIGHTMIN; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 51 | bool stall = FALSE; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 52 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 53 | // Main Program |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 54 | int main() { |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 55 | // Initializations |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 56 | setupGimbal(); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 57 | setupLift(); // Lift |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 58 | setupROSNode(nh, sub); // ROS Node Handle |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 59 | // Main Loop |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 60 | while (1) { |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 61 | // Lift Operation |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 62 | runLift(); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 63 | //Run Gimbal |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 64 | runGimbal(); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 65 | //ROS Functions |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 66 | nh.spinOnce(); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 67 | rosCheck(); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 68 | } |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 69 | } |