rq_sensor_state.cpp
Go to the documentation of this file.
1 /* Software License Agreement (BSD License)
2 *
3 * Copyright (c) 2014, Robotiq, Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials provided
15 * with the distribution.
16 * * Neither the name of Robotiq, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 * Copyright (c) 2014, Robotiq, Inc
34 */
35 
36 /*
37  * \file rq_sensor_state.c
38  * \date June 19, 2014
39  * \author Jonathan Savoie <jonathan.savoie@robotiq.com>
40  * \maintainer Jean-Philippe Roberge <ros@robotiq.com>
41  */
42 
44 //Includes
45 #include <string.h>
48 
50 //Private variables
52 
54 //Private functions
55 static INT_8 rq_state_init_com();
56 static INT_8 rq_state_init_com(const std::string& ftdi_id);
57 static void rq_state_read_info_high_lvl();
58 static void rq_state_start_stream();
59 static void rq_state_run(unsigned int max_retries);
60 
62 //Function definitions
63 
69 INT_8 rq_sensor_state(unsigned int max_retries, const std::string& ftdi_id)
70 {
71  INT_8 ret;
72 
73  switch (current_state)
74  {
75  case RQ_STATE_INIT:
76  ret = rq_state_init_com(ftdi_id);
77  if(ret == -1)
78  {
79  return -1;
80  }
81  break;
82 
83  case RQ_STATE_READ_INFO:
85  break;
86 
89  break;
90 
91  case RQ_STATE_RUN:
92  rq_state_run(max_retries);
93  break;
94 
95  default:
96  printf("rq_state(): Unknown error\r\n");
97  return -1;
98  break;
99 
100  }
101  return 0;
102  }
103 
109  INT_8 rq_sensor_state(unsigned int max_retries)
110  {
111  INT_8 ret;
112 
113  switch (current_state)
114  {
115  case RQ_STATE_INIT:
116  ret = rq_state_init_com();
117  if (ret == -1)
118  {
119  return -1;
120  }
121  break;
122 
123  case RQ_STATE_READ_INFO:
125  break;
126 
129  break;
130 
131  case RQ_STATE_RUN:
132  rq_state_run(max_retries);
133  break;
134 
135  default:
136  printf("rq_state(): Unknown error\r\n");
137  return -1;
138  break;
139 
140  }
141  return 0;
142  }
143 
150  {
151  if (rq_sensor_com() == -1)
152  {
153  return -1;
154  }
155 
157  return 0;
158  }
159 
165  static INT_8 rq_state_init_com(const std::string &ftdi_id)
166  {
167  if (rq_sensor_com(ftdi_id) == -1)
168  {
169  return -1;
170  }
171 
173  return 0;
174 }
175 
183 {
186 }
187 
195 {
196  if(rq_com_start_stream() == -1)
197  {
198 #if defined(_WIN32)||defined(WIN32) //For Windows
199  stop_connection();
200 #endif
202  }
204 }
205 
212 static void rq_state_run(unsigned int max_retries)
213 {
214  static unsigned int retries = 0;
215 
217 
218  if(rq_com_get_valid_stream() == false)
219  {
220  retries++;
221  if (retries >= max_retries)
222  {
223 #if defined(_WIN32)||defined(WIN32) //For Windows
224  stop_connection();
225 #endif
227  retries = 0;
228  }
229  }
230  else
231  {
232  retries = 0;
233  }
234 }
235 
243 {
244  if(i >= 0 && i <= 5)
245  {
246  return rq_com_get_received_data(i);
247  }
248  else
249  {
250  return 0.0;
251  }
252 }
253 
254 
255 
263 bool rq_state_get_command(INT_8 command, INT_8 * const value)
264 {
266  switch (command) {
269  break;
272  break;
275  break;
278  strcpy(value, "Done");
279  break;
280  default:
281  strcpy(value, "Unsupported command_id");
282  return false;
283  }
284  return true;
285 }
286 
287 
296 void rq_state_get_command(INT_8 const * const name, INT_8 * const value)
297 {
298  //precondition, null pointer
299  if( value == NULL || name == NULL)
300  {
301  return;
302  }
303 
304  if(strstr(name, "SNU"))
305  {
307  }
308  else if(strstr(name, "FWV"))
309  {
311  }
312  else if(strstr(name, "PYE"))
313  {
315  }
316 }
317 
323 {
324  return current_state;
325 }
326 
331 {
332  return rq_com_got_new_message();
333 }
334 
339 {
341 }
void rq_com_get_str_production_year(INT_8 *production_year)
Retrieves the sensor firmware version.
float rq_com_get_received_data(UINT_8 i)
Return an effort component.
void rq_sensor_com_read_info_high_lvl(void)
Reads and stores high level information from the sensor. These include the firmware version...
INT_8 rq_sensor_com()
Discovers and initialize the communication with the sensor.
bool rq_state_got_new_message()
Returns true if a stream message is available.
bool rq_com_get_valid_stream(void)
returns if the stream message is valid
enum rq_sensor_state_values rq_sensor_get_current_state()
Returns this module&#39;s state machine current state.
void rq_com_get_str_firmware_version(INT_8 *firmware_version)
Retrieves the sensor firmware version.
void rq_com_get_str_serial_number(INT_8 *serial_number)
Retrieves the sensor serial number.
static void rq_state_run(unsigned int max_retries)
void rq_com_do_zero_force_flag(void)
Set the "zero sensor" flag to 1. When the next stream message will be decoded, the effort values will...
static void rq_state_read_info_high_lvl()
Reads the high level information from the sensor and set the next state to RQ_STATE_START_STREAM.
void stop_connection(void)
close the serial port.
INT_8 rq_com_start_stream(void)
Starts the sensor streaming mode.
the sensor
rq_sensor_state_values
State that initialize the com. with the sensor.
unsigned char UINT_8
Definition: rq_int.h:51
void rq_state_do_zero_force_flag()
Command a zero on the sensor.
static enum rq_sensor_state_values current_state
float rq_state_get_received_data(UINT_8 i)
std::string ftdi_id
Definition: rq_sensor.cpp:55
static void rq_state_start_stream()
Send the command to start the streaming mode If the stream doesn&#39;t start, return to state init...
bool rq_state_get_command(INT_8 command, INT_8 *const value)
Gets the value of high level information from the sensor.
char INT_8
Definition: rq_int.h:46
INT_8 rq_sensor_state(unsigned int max_retries, const std::string &ftdi_id)
void rq_com_listen_stream(void)
Listens and decode a valid stream input.
static INT_8 rq_state_init_com()
Initialize communication with the sensor and set the next state to RQ_STATE_READ_INFO.
bool rq_com_got_new_message(void)
Returns true if a new valid stream message has been decoded and is available.


robotiq_ft_sensor
Author(s): Jonathan Savoie
autogenerated on Tue Jun 1 2021 02:30:04