serial_controller.h
Go to the documentation of this file.
1 
31 #ifndef SERIAL_CONTROLLER_H
32 #define SERIAL_CONTROLLER_H
33 
34 #include <ros/ros.h>
35 #include <serial/serial.h>
36 
37 #include <mutex>
38 #include <condition_variable> // std::condition_variable
39 
40 #include <thread>
41 
42 using namespace std;
43 
44 namespace roboteq {
45 
47 typedef function<void (string data) > callback_data_t;
48 
50 {
51 public:
57  serial_controller(string port, unsigned long baudrate);
58 
64  bool start();
69  bool stop();
70 
71  bool command(string msg, string params="", string type="!");
72 
73  bool query(string msg, string params="", string type="?");
74 
75  string getQuery(string msg, string params="")
76  {
77  if(query(msg, params))
78  {
79  return get();
80  }
81  else
82  {
83  return "";
84  }
85  }
86 
87  bool setParam(string msg, string params="") {
88  return command(msg, params, "^");
89  }
90 
91  string getParam(string msg, string params="") {
92  if(query(msg, params, "~"))
93  {
94  return get();
95  }
96  else
97  {
98  return "";
99  }
100  }
101 
102  bool maintenance(string msg, string params="")
103  {
104  return command(msg, params, "%");
105  }
106 
111  string get()
112  {
113  return sub_data;
114  }
120  {
121  return "V" + _script_ver;
122  }
123 
127  void reset()
128  {
129  // Send reset command
130  mSerial.write("%RESET 321654987");
131  // Wait one second after reset
132  ros::Duration(1).sleep();
133  }
134 
140  {
141  return maintenance("EERST");
142  }
148  {
149  return maintenance("EELD");
150  }
151 
156  bool saveInEEPROM() {
157  return maintenance("EESAV");
158  }
159 
165  bool script(bool status) {
166  if(status)
167  {
168  return command("R");
169  } else
170  {
171  return command("R", "0");
172  }
173  }
179  bool echo(bool type) {
180  if(type) {
181  return setParam("ECHOF", "0");
182  } else
183  {
184  return setParam("ECHOF", "1");
185  }
186  }
191  bool downloadScript();
197  bool addCallback(const callback_data_t &callback, const string data);
201  template <class T> bool addCallback(void(T::*fp)(const string), T* obj, const string data) {
202  return addCallback(bind(fp, obj, _1), data);
203  }
204 private:
205  // Serial port object
207  // Serial port name
208  string mSerialPort;
209  // Serial port baudrate
210  uint32_t mBaudrate;
211  // Timeout open serial port
212  uint32_t mTimeout;
213  // Used to stop the serial processing
214  bool mStopping;
215  // Last message sent
216  string mMessage;
217  string sub_data;
219  bool data;
220  // Async reader controller
221  std::thread first;
222  // Mutex to sto concurent sending
223  mutex mWriteMutex;
225  std::condition_variable cv;
226  // Hashmap with all type of message
227  map<string, callback_data_t> hashmap;
228  // HLD mode - To download script - reference [pag. 183]
229  bool isHLD;
230  // Version script
231  string _script_ver;
235  void async_reader();
240  bool enableDownload();
241 };
242 
243 }
244 
245 #endif // SERIAL_CONTROLLER_H
msg
bool script(bool status)
script Run and stop the script inside the Roboteq
bool setParam(string msg, string params="")
bool sleep() const
map< string, callback_data_t > hashmap
data
bool echo(bool type)
echo Enable or disable the echo message
bool factoryReset()
factoryReset Factory reset of Roboteq board
function< void(string data) > callback_data_t
Read complete callback - Array of callback.
ROSLIB_DECL std::string command(const std::string &cmd)
void reset()
reset Reset the Roboteq board
string getParam(string msg, string params="")
Definition: motor.h:51
bool loadFromEEPROM()
loadFromEEPROM
string getQuery(string msg, string params="")
bool maintenance(string msg, string params="")
bool saveInEEPROM()
saveInEEPROM The EESAV it&#39;s a real-time Command must be used to copy the RAM array to Flash...
string getVersionScript()
getVersionScript The version of the script loaded
std::condition_variable cv
bool addCallback(void(T::*fp)(const string), T *obj, const string data)


roboteq_control
Author(s): Raffaello Bonghi
autogenerated on Wed Jan 3 2018 03:48:23