UVic Assistive Technology Lab / Mbed 2 deprecated DSLR_Camera_Gimbal

Dependencies:   mbed ros_lib_kinetic

Committer:
MikeGray92
Date:
Tue Feb 06 20:50:55 2018 +0000
Revision:
1:1ac7d472cfa2
Parent:
0:3a767f41cf04
Child:
2:0537a8007a39
Set up with external interrupt for lift. NOT TESTED

Who changed what in which revision?

UserRevisionLine numberNew 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);
MikeGray92 1:1ac7d472cfa2 28 //DigitalIn hallSensor1(D9);
MikeGray92 1:1ac7d472cfa2 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;
MikeGray92 1:1ac7d472cfa2 35 Ticker liftInt;
MikeGray92 1:1ac7d472cfa2 36 Timer filter_hall1;
group-UVic-Assistive-Technolog 0:3a767f41cf04 37 BNO055 IMU(D14, D15);
group-UVic-Assistive-Technolog 0:3a767f41cf04 38 DynamixelClass gimbal(57600, D7, D8, D2);
group-UVic-Assistive-Technolog 0:3a767f41cf04 39
group-UVic-Assistive-Technolog 0:3a767f41cf04 40 ros::NodeHandle nh;
group-UVic-Assistive-Technolog 0:3a767f41cf04 41 ros::Subscriber<std_msgs::Float32MultiArray> sub("module_command", &module_commandCB);
group-UVic-Assistive-Technolog 0:3a767f41cf04 42
group-UVic-Assistive-Technolog 0:3a767f41cf04 43 // Global Variable
group-UVic-Assistive-Technolog 0:3a767f41cf04 44 // Variables
group-UVic-Assistive-Technolog 0:3a767f41cf04 45 struct fields control;
group-UVic-Assistive-Technolog 0:3a767f41cf04 46 struct fields rosInput;
group-UVic-Assistive-Technolog 0:3a767f41cf04 47 bool liftFlag = 0;
group-UVic-Assistive-Technolog 0:3a767f41cf04 48 bool motorFlag = 0;
group-UVic-Assistive-Technolog 0:3a767f41cf04 49 bool homeFlag = 0;
group-UVic-Assistive-Technolog 0:3a767f41cf04 50 bool imuFlag = 0;
group-UVic-Assistive-Technolog 0:3a767f41cf04 51 bool rosFlag = 0;
MikeGray92 1:1ac7d472cfa2 52 volatile int currentPosition = 0;
MikeGray92 1:1ac7d472cfa2 53 int prevPosition = 0;
MikeGray92 1:1ac7d472cfa2 54 bool stall = false;
group-UVic-Assistive-Technolog 0:3a767f41cf04 55
group-UVic-Assistive-Technolog 0:3a767f41cf04 56 // Main Program
group-UVic-Assistive-Technolog 0:3a767f41cf04 57 int main() {
group-UVic-Assistive-Technolog 0:3a767f41cf04 58 // Initializations
MikeGray92 1:1ac7d472cfa2 59 filter_hall1.start(); //Start Filtering Timer
group-UVic-Assistive-Technolog 0:3a767f41cf04 60 setupGimbal();
group-UVic-Assistive-Technolog 0:3a767f41cf04 61 setupLift(); // Lift
group-UVic-Assistive-Technolog 0:3a767f41cf04 62 setupROSNode(nh, sub); // ROS Node Handle
group-UVic-Assistive-Technolog 0:3a767f41cf04 63 // Main Loop
group-UVic-Assistive-Technolog 0:3a767f41cf04 64 while (1) {
group-UVic-Assistive-Technolog 0:3a767f41cf04 65 // Lift Operation
group-UVic-Assistive-Technolog 0:3a767f41cf04 66 runLift();
group-UVic-Assistive-Technolog 0:3a767f41cf04 67 //Run Gimbal
group-UVic-Assistive-Technolog 0:3a767f41cf04 68 runGimbal();
group-UVic-Assistive-Technolog 0:3a767f41cf04 69 //ROS Functions
group-UVic-Assistive-Technolog 0:3a767f41cf04 70 nh.spinOnce();
group-UVic-Assistive-Technolog 0:3a767f41cf04 71 rosCheck();
group-UVic-Assistive-Technolog 0:3a767f41cf04 72 }
group-UVic-Assistive-Technolog 0:3a767f41cf04 73 }