Go to the documentation of this file.00001 #include <ros/ros.h>
00002 #include <string.h>
00003 #include <stdio.h>
00004 #include <math.h>
00005 #include <stdlib.h>
00006 #include <Ivy/ivy.h>
00007 #include <Ivy/ivyloop.h>
00008 #include "quad_status/Status.h"
00009 #include <Ivy/timer.h>
00010
00011 quad_status::Status status;
00012 ros::Publisher status_message;
00013 float batt_limit=11.0;
00014
00015
00016
00017
00018
00019 void STATCallback (IvyClientPtr app, void* data , int argc, char **argv)
00020 {
00021 double run_time, vsupply;
00022 int rc_status, motors_on, exctrl_mode;
00023
00024 sscanf(argv[0],"%*d %*d %*d %d %*d %*d %*d %*d %*d %d %*d %*d %*d %d %lf %lf",&rc_status, &motors_on, &exctrl_mode, &vsupply, &run_time);
00025
00026 status.header.stamp = ros::Time::now();
00027
00028 if(rc_status==0) status.RC_OK=true;
00029 else status.RC_OK=false;
00030
00031 if(motors_on==0) status.Motors_ON=false;
00032 else status.Motors_ON=true;
00033
00034 if(exctrl_mode==1) status.ExCtrl_ON=true;
00035 else status.ExCtrl_ON=false;
00036
00037 status.Batt_Voltage=vsupply/10;
00038 if (status.Batt_Voltage<=batt_limit) ROS_WARN("Battery Level at %fV!!!",status.Batt_Voltage);
00039
00040 status.Run_Time=ros::Duration(run_time);
00041
00042 status_message.publish(status);
00043 }
00044
00045 void ROSCallback (TimerId id, void *user_data, unsigned long delta)
00046 {
00047 if (!ros::ok()){
00048 IvyStop();
00049 exit(0);
00050 }
00051 }
00052
00053 int main(int argc, char **argv)
00054 {
00055
00056
00057 ros::init(argc, argv, "quad_status");
00058 ros::NodeHandle nh("~");
00059
00060 status_message = nh.advertise<quad_status::Status>("status", 1000);
00061
00062
00063 IvyInit ("quad_status", "'Quad Status' is READY!", 0, 0, 0, 0);
00064 IvyStart("127.255.255.255");
00065 TimerRepeatAfter (TIMER_LOOP, 500, ROSCallback, 0);
00066
00067
00068 IvyBindMsg(STATCallback, 0, "ROTORCRAFT_STATUS(.*)");
00069
00070 IvyMainLoop();
00071
00072 return 0;
00073 }