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
ros_functions.cpp
- Committer:
- MikeGray92
- Date:
- 2018-03-15
- Revision:
- 8:478f75c6109c
- Parent:
- 7:950b3c3b5a2b
- Child:
- 9:30901bec3a2d
File content as of revision 8:478f75c6109c:
#include <ros_functions.h>
#include <definitions.h>
#include <ros.h>
#include <std_msgs/Empty.h>
#include <std_msgs/Int32MultiArray.h>
#include <prototypes.h>
static int h = 0; //variable used to reset the currentPosition value when switching input direction
static int initialize = 0; //Variable used to allow the set up of each mode
int rosModeDelay = 1; //The amount of delay before switching modes
void module_commandCB(const std_msgs::Int32MultiArray& command_data){
rosInput.yaw = command_data.data[ROSYAW];
rosInput.pitch = command_data.data[ROSPITCH];
rosInput.roll = command_data.data[ROSROLL];
rosInput.height = command_data.data[ROSHEIGHT];
if(rosFlag == 1){
rosInput.mode = command_data.data[ROSMODE];
}
}
void rosCheck(){
if(rosInput.mode == 0){ //Transport Mode
control.yaw = YAWZERO;
control.pitch = PITCHZERO;
control.roll = ROLLZERO;
control.height = LIFTHEIGHTMIN;
if(initialize != rosInput.mode){
initializeMode();
}
else{
if(rosMode_Delay.read() > rosModeDelay){
rosFlag = 1;
rosMode_Delay.reset();
rosMode_Delay.stop();
}
}
}
else if(rosInput.mode == 1){ //Photo Mode
if(h != rosInput.height){
control.height = currentPosition;
}
if(initialize != rosInput.mode){
rosFlag = 0;
control.height = currentPosition;
initialize = rosInput.mode;
rosMode_Delay.start();
}
rosTranslator(rosInput.height, rosInput.yaw, rosInput.pitch, rosInput.roll);
h = rosInput.height;
if(rosMode_Delay.read() > rosModeDelay){
rosFlag = 1;
rosMode_Delay.reset();
rosMode_Delay.stop();
}
}
if(rosInput.mode == 2){ //Chat Mode - Standing
if(initialize != rosInput.mode){
control.pitch = 2122;
control.height = LIFTHEIGHTMAX;
control.yaw = YAWZERO;
control.roll = ROLLZERO;
initializeMode();
}
else{
rosTranslator(rosInput.height, rosInput.yaw, rosInput.pitch, rosInput.roll);
if(rosMode_Delay.read() > rosModeDelay){
rosFlag = 1;
rosMode_Delay.reset();
rosMode_Delay.stop();
}
}
}
if(rosInput.mode == 3){ //Chat Mode - Sitting
if(initialize != rosInput.mode){
control.pitch = PITCHZERO;
control.height = 1100; // need to find values
control.yaw = YAWZERO;
control.roll = ROLLZERO;
initializeMode();
}
else{
rosTranslator(rosInput.height, rosInput.yaw, rosInput.pitch, rosInput.roll);
if(rosMode_Delay.read() > rosModeDelay){
rosFlag = 1;
rosMode_Delay.reset();
rosMode_Delay.stop();
}
}
}
if(rosInput.mode == 4){ //Chat Mode - in bed
if(initialize != rosInput.mode){
control.pitch = 2500; // need to find values
control.height = 1700; // need to find values
control.yaw = YAWZERO; // need to find values
initializeMode();
}
else{
rosTranslator(rosInput.height, rosInput.yaw, rosInput.pitch, rosInput.roll);
if(rosMode_Delay.read() > rosModeDelay){
rosFlag = 1;
rosMode_Delay.reset();
rosMode_Delay.stop();
}
}
}
}
// Converting the ros inputs for the lift and gimbal and determining action
void rosTranslator(int height, int yaw, int pitch, int roll){
switch(height){
case(0):
control.height--;
if(control.height < LIFTHEIGHTMIN){control.height = LIFTHEIGHTMIN;}
break;
case(1):
control.height = currentPosition;
break;
case(2):
control.height++;
if(control.height > LIFTHEIGHTMAX){control.height = LIFTHEIGHTMAX;}
break;
}
switch(yaw){
case(0):
control.yaw++;
if(control.yaw > YAWMAX){control.yaw = YAWMAX;}
break;
case(1):
break;
case(2):
control.yaw--;
if(control.yaw < YAWMIN){control.yaw = YAWMIN;}
break;
}
switch(pitch){
case(0):
control.pitch--;
if(control.pitch < PITCHMIN){control.pitch = PITCHMIN;}
break;
case(1):
break;
case(2):
control.pitch++;
if(control.pitch > PITCHMAX){
control.pitch = PITCHMAX;}
break;
}
switch(rosInput.roll){
case(0):
control.roll--;
if(control.roll < ROLLMIN){control.roll = ROLLMIN;}
break;
case(1):
break;
case(2):
control.roll++;
if(control.roll > ROLLMAX){control.roll = ROLLMAX;}
break;
}
}
//Allowing intialization in various modes
void initializeMode(){
rosFlag = 0;
if(abs(control.height - currentPosition) < 5){
initialize = rosInput.mode;
rosMode_Delay.start();
}
}