UVic Assistive Technology Lab / Mbed 2 deprecated DSLR_Camera_Gimbal

Dependencies:   mbed ros_lib_kinetic

Committer:
MikeGray92
Date:
Wed Mar 14 19:33:08 2018 +0000
Revision:
7:950b3c3b5a2b
Parent:
6:2ffa254e8f6e
Child:
8:478f75c6109c
Tested with ROS; Added Initialized ROS Inputs to avoid errors at start up; Limit the roll movement, to allow greater pitch movement; In Bed Chatting mode changed to rosInput.mode = 4 and Standing Chatting mode changed to rosInput.mode = 2.

Who changed what in which revision?

UserRevisionLine numberNew 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
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
group-UVic-Assistive-Technolog 0:3a767f41cf04 30 ros::NodeHandle nh;
MikeGray92 7:950b3c3b5a2b 31 ros::Subscriber<std_msgs::Int32MultiArray> sub("module_command", &module_commandCB);
group-UVic-Assistive-Technolog 0:3a767f41cf04 32
group-UVic-Assistive-Technolog 0:3a767f41cf04 33 // Global Variable
group-UVic-Assistive-Technolog 0:3a767f41cf04 34 struct fields control;
group-UVic-Assistive-Technolog 0:3a767f41cf04 35 struct fields rosInput;
MikeGray92 1:1ac7d472cfa2 36 volatile int currentPosition = 0;
MikeGray92 1:1ac7d472cfa2 37 int prevPosition = 0;
MikeGray92 4:89ebfa37663b 38 int stallcount = 0;
MikeGray92 4:89ebfa37663b 39 bool rosFlag = 1;
MikeGray92 2:0537a8007a39 40
group-UVic-Assistive-Technolog 0:3a767f41cf04 41 // Main Program
group-UVic-Assistive-Technolog 0:3a767f41cf04 42 int main() {
group-UVic-Assistive-Technolog 0:3a767f41cf04 43 // Initializations
MikeGray92 4:89ebfa37663b 44 filter_hall1.start(); //Start Filtering Timer
MikeGray92 2:0537a8007a39 45 setupGimbal(); // Gimbal
group-UVic-Assistive-Technolog 0:3a767f41cf04 46 setupLift(); // Lift
MikeGray92 4:89ebfa37663b 47 setupROSNode(nh, sub); // ROS Node Handle
MikeGray92 7:950b3c3b5a2b 48 rosInput.yaw = 1;
MikeGray92 7:950b3c3b5a2b 49 rosInput.pitch = 1;
MikeGray92 7:950b3c3b5a2b 50 rosInput.roll = 1;
MikeGray92 7:950b3c3b5a2b 51 rosInput.height = 1;
MikeGray92 7:950b3c3b5a2b 52 rosInput.mode = 0;
MikeGray92 4:89ebfa37663b 53
group-UVic-Assistive-Technolog 0:3a767f41cf04 54 // Main Loop
group-UVic-Assistive-Technolog 0:3a767f41cf04 55 while (1) {
MikeGray92 4:89ebfa37663b 56 // Lift Operation
group-UVic-Assistive-Technolog 0:3a767f41cf04 57 runLift();
MikeGray92 4:89ebfa37663b 58 //Run Gimbal
group-UVic-Assistive-Technolog 0:3a767f41cf04 59 runGimbal();
MikeGray92 4:89ebfa37663b 60 //ROS Functions
MikeGray92 4:89ebfa37663b 61 nh.spinOnce();
MikeGray92 4:89ebfa37663b 62 rosCheck();
MikeGray92 4:89ebfa37663b 63 }
group-UVic-Assistive-Technolog 0:3a767f41cf04 64 }