Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <boost/shared_ptr.hpp>
00033 #include "comm.h"
00034 #include "hl_interface.h"
00035 #include "ssdk_interface.h"
00036 #include "ekf_interface.h"
00037
00038 void printTopicInfo()
00039 {
00040
00041 std::string nodeName = ros::this_node::getName();
00042 ros::V_string topics;
00043 ros::this_node::getSubscribedTopics(topics);
00044 std::string topicsStr = nodeName + ":\n\tsubscribed to topics:\n";
00045 for (unsigned int i = 0; i < topics.size(); i++)
00046 topicsStr += ("\t\t" + topics.at(i) + "\n");
00047
00048 topicsStr += "\tadvertised topics:\n";
00049 ros::this_node::getAdvertisedTopics(topics);
00050 for (unsigned int i = 0; i < topics.size(); i++)
00051 topicsStr += ("\t\t" + topics.at(i) + "\n");
00052
00053 ROS_INFO_STREAM(""<< topicsStr);
00054 }
00055
00056 class Watchdog{
00057 private:
00058 CommPtr & comm_;
00059 const double PERIOD;
00060 ros::Timer timer;
00061 uint32_t last_rx_count_;
00062 uint32_t timeout_count_;
00063 void check(const ros::TimerEvent & e)
00064 {
00065 if(last_rx_count_ == comm_->getRxPacketsGood()){
00066 timeout_count_++;
00067 ROS_WARN("No new valid packets within the last %f s",PERIOD);
00068 }
00069
00070 if(timeout_count_ > 4){
00071
00072 ROS_FATAL("No valid packets within the last %f s, aborting !", 5*PERIOD);
00073 ros::Duration(0.1).sleep();
00074 ros::shutdown();
00075 }
00076
00077 last_rx_count_ = comm_->getRxPacketsGood();
00078 }
00079
00080 public:
00081 Watchdog(CommPtr & comm):comm_(comm), PERIOD(1), last_rx_count_(0), timeout_count_(0)
00082 {
00083 ROS_INFO("creating watchdog monitoring successful rx packets");
00084 ros::NodeHandle nh;
00085 timer = nh.createTimer(ros::Duration(PERIOD), &Watchdog::check, this);
00086 }
00087 };
00088
00089 int main(int argc, char ** argv)
00090 {
00091 ros::init(argc, argv, "fcu");
00092 ros::NodeHandle nh("fcu");
00093
00094
00095 std::string port, portRX, portTX;
00096 int baudrate;
00097 ros::NodeHandle pnh("~");
00098 CommPtr comm(new Comm);
00099
00100 bool connected = false;
00101
00102 pnh.param("baudrate", baudrate, HLI_DEFAULT_BAUDRATE);
00103
00104 if (pnh.getParam("serial_port_rx", portRX) && pnh.getParam("serial_port_tx", portTX))
00105 {
00106 connected = comm->connect(portRX, portTX, baudrate);
00107 }
00108 else
00109 {
00110 pnh.param("serial_port", port, std::string("/dev/ttyUSB0"));
00111 connected = comm->connect(port, port, baudrate);
00112 }
00113
00114 if (!connected)
00115 {
00116 ROS_ERROR("unable to connect");
00117 ros::Duration(2).sleep();
00118 return -1;
00119 }
00120
00121 HLInterface asctecInterface(nh, comm);
00122 SSDKInterface ssdk_if(nh, comm);
00123 EKFInterface ekf_if(nh, comm);
00124
00125 printTopicInfo();
00126
00127 Watchdog wd(comm);
00128
00129 ros::spin();
00130
00131
00132 return 0;
00133 }