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
00033
00034
00035
00036
00037 #define NODE_VERSION 0.01
00038
00039 #include <ros/ros.h>
00040 #include <lse_sensor_msgs/Nostril.h>
00041 #include <lse_sensor_msgs/Anemometer.h>
00042
00043 #include <vector>
00044 #include <string>
00045
00046 #include "cereal_port/CerealPort.h"
00047
00048 #define DEBUG 0
00049
00050 #define CR 13
00051 #define SN_START ':'
00052 #define SN_SEP ','
00053
00054 #define SN_BROADCAST 'Z'
00055
00056 #define SN_SYNC_TIME 'a'
00057 #define SN_SET_TIME 'b'
00058 #define SN_READ_SENSORS 'c'
00059 #define SN_GET_POWER 'd'
00060 #define SN_GET_TIME 'e'
00061 #define SN_SET_ALL_PWM 'f'
00062 #define SN_SET_PWM 'g'
00063 #define SN_SET_ADDRESS 'h'
00064 #define SN_SET_SENSORS 'i'
00065 #define SN_GET_SENSORS 'j'
00066 #define SN_GET_INFO 'x'
00067
00068 #define SN_SENSOR 's'
00069 #define SN_ACTUATOR 'a'
00070
00071 #define SN_VERSION 10
00072
00073 class SensorNet
00074 {
00075 public:
00076 SensorNet(std::string port_name, int baud_rate);
00077 ~SensorNet();
00078
00079 class Node
00080 {
00081 public:
00082 Node(){}
00083 Node(char address, char type, int period)
00084 {
00085 this->node_address=address;
00086 this->node_type=type;
00087 this->node_period=period;
00088 }
00089 ~Node(){}
00090
00091 char address(){return node_address;}
00092 char type(){return node_type;}
00093 int period(){return node_period;}
00094 bool sensors(int i){return node_sensors[i];}
00095
00096 void setAddress(char address){node_address=address;}
00097 void setType(char type){node_type=type;}
00098 void setPeriod(int period){node_period=period;}
00099 void setSensors(int s1, int s2, int s3, int s4, int w1, int w2)
00100 {
00101 node_sensors[0] = s1==0 ? false : true;
00102 node_sensors[1] = s2==0 ? false : true;
00103 node_sensors[2] = s3==0 ? false : true;
00104 node_sensors[3] = s4==0 ? false : true;
00105 node_sensors[4] = w1==0 ? false : true;
00106 node_sensors[5] = w2==0 ? false : true;
00107 }
00108
00109 bool sensor(){return node_type==SN_SENSOR;}
00110 bool actuator(){return node_type==SN_ACTUATOR;}
00111
00112 private:
00113 char node_address;
00114 char node_type;
00115 int node_period;
00116
00117 bool node_sensors[6];
00118 };
00119
00120 std::vector<Node> nodes;
00121
00122 bool scanNodes(int period);
00123 bool syncNodes();
00124
00125 bool syncTime(SensorNet::Node * node);
00126 bool setTime(SensorNet::Node * node, ros::Time start_time);
00127 bool getTime(SensorNet::Node * node, ros::Time * current_time, ros::Time * next_reading);
00128 bool getSensorReadings(SensorNet::Node * node, std::vector<lse_sensor_msgs::Nostril> * mox, std::vector<lse_sensor_msgs::Anemometer> * termistor);
00129 bool setAllPWM(SensorNet::Node * node, int pwm1, int pwm2, int pwm3, int pwm4);
00130 bool setPWM(SensorNet::Node * node, ros::Time time, unsigned int id, int pwm);
00131 bool getInfo(SensorNet::Node * node);
00132 bool setSensors(SensorNet::Node * node, int s1, int s2, int s3, int s4, int w1, int w2);
00133 bool getSensors(SensorNet::Node * node);
00134 bool setAddress(SensorNet::Node * node, char new_address);
00135
00136 int timeout;
00137
00138 private:
00139 cereal::CerealPort * serial_port;
00140
00141 ros::Time start_time;
00142
00143 bool sendCommand(char address, char command);
00144 bool waitForIt(char address);
00145
00146 void appendTime(std::string * data, ros::Time time);
00147 void appendInt(std::string * data, int value);
00148 ros::Time extractTime(std::string data);
00149 int extractInt(std::string data);
00150 };
00151
00152