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@10:836e701d00a6, 2018-04-26 (annotated)
- Committer:
- MikeGray92
- Date:
- Thu Apr 26 18:33:11 2018 +0000
- Revision:
- 10:836e701d00a6
- Parent:
- 8:478f75c6109c
- Child:
- 14:97804177806d
Speed and Position controlled lift and gimbal
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); |
MikeGray92 | 10:836e701d00a6 | 28 | InterruptIn eStop(D5); |
MikeGray92 | 10:836e701d00a6 | 29 | DigitalOut value0(D3); |
MikeGray92 | 10:836e701d00a6 | 30 | DigitalOut value1(D4); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 31 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 32 | ros::NodeHandle nh; |
MikeGray92 | 7:950b3c3b5a2b | 33 | ros::Subscriber<std_msgs::Int32MultiArray> sub("module_command", &module_commandCB); |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 34 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 35 | // Global Variable |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 36 | struct fields control; |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 37 | struct fields rosInput; |
MikeGray92 | 10:836e701d00a6 | 38 | float liftDutyCycle = 0; |
MikeGray92 | 1:1ac7d472cfa2 | 39 | volatile int currentPosition = 0; |
MikeGray92 | 1:1ac7d472cfa2 | 40 | int prevPosition = 0; |
MikeGray92 | 4:89ebfa37663b | 41 | int stallcount = 0; |
MikeGray92 | 4:89ebfa37663b | 42 | bool rosFlag = 1; |
MikeGray92 | 10:836e701d00a6 | 43 | bool eStopFlag = 0; |
MikeGray92 | 2:0537a8007a39 | 44 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 45 | // Main Program |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 46 | int main() { |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 47 | // Initializations |
MikeGray92 | 10:836e701d00a6 | 48 | value0.write(1); |
MikeGray92 | 10:836e701d00a6 | 49 | value1.write(1); |
MikeGray92 | 10:836e701d00a6 | 50 | filter_hall1.start(); //Start Filtering Timer |
MikeGray92 | 10:836e701d00a6 | 51 | eStop.fall(&eStopOn); |
MikeGray92 | 10:836e701d00a6 | 52 | eStop.rise(&eStopOff); |
MikeGray92 | 2:0537a8007a39 | 53 | setupGimbal(); // Gimbal |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 54 | setupLift(); // Lift |
MikeGray92 | 4:89ebfa37663b | 55 | setupROSNode(nh, sub); // ROS Node Handle |
MikeGray92 | 7:950b3c3b5a2b | 56 | rosInput.mode = 0; |
MikeGray92 | 4:89ebfa37663b | 57 | |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 58 | // Main Loop |
MikeGray92 | 10:836e701d00a6 | 59 | while (1) { |
MikeGray92 | 10:836e701d00a6 | 60 | //LED Inputs |
MikeGray92 | 10:836e701d00a6 | 61 | value0.write(0); |
MikeGray92 | 10:836e701d00a6 | 62 | value1.write(0); |
MikeGray92 | 10:836e701d00a6 | 63 | //ROS Functions |
MikeGray92 | 10:836e701d00a6 | 64 | nh.spinOnce(); |
MikeGray92 | 10:836e701d00a6 | 65 | rosCheck(); |
MikeGray92 | 4:89ebfa37663b | 66 | // Lift Operation |
MikeGray92 | 10:836e701d00a6 | 67 | runLift(); |
MikeGray92 | 4:89ebfa37663b | 68 | //Run Gimbal |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 69 | runGimbal(); |
MikeGray92 | 10:836e701d00a6 | 70 | } |
group-UVic-Assistive-Technolog | 0:3a767f41cf04 | 71 | } |