RokubiminiSerialCommunication.cpp
Go to the documentation of this file.
1 
3 #include <ros/ros.h>
4 
5 namespace rokubimini
6 {
7 namespace serial
8 {
10  const configuration::SensorConfiguration& sensorConfiguration, const uint8_t& dataFormat, const uint8_t& baudRate)
11  : sensorConfiguration_(sensorConfiguration), dataFormat_(dataFormat), baudRate_(baudRate)
12 {
13 }
14 
15 bool RokubiminiSerialCommandCommSetup::formatCommand(std::string& formattedString)
16 {
17  char buffer[100];
18  int bytes_count = sprintf(buffer, formatString_.c_str(), sensorConfiguration_.getTemperatureCompensationActive(),
20 
21  if (bytes_count < 0)
22  {
23  ROS_ERROR("Failed to format communication setup command");
24  return false;
25  }
26  formattedString.clear();
27  formattedString.assign(buffer, bytes_count);
28  return true;
29 }
30 
32  : filter_(filter)
33 {
34 }
35 
36 bool RokubiminiSerialCommandFilter::formatCommand(std::string& formattedString)
37 {
38  char buffer[100];
39  int bytes_count = sprintf(buffer, formatString_.c_str(), filter_.getSincFilterSize(), filter_.getChopEnable(),
41 
42  if (bytes_count < 0)
43  {
44  ROS_ERROR("Failed to format filters command");
45  return false;
46  }
47  formattedString.clear();
48  formattedString.assign(buffer, bytes_count);
49  return true;
50 }
51 
52 RokubiminiSerialCommandOffset::RokubiminiSerialCommandOffset(const Eigen::Matrix<double, 6, 1>& forceTorqueOffset)
53  : forceTorqueOffset_(forceTorqueOffset)
54 {
55 }
56 
57 bool RokubiminiSerialCommandOffset::formatCommand(std::string& formattedString)
58 {
59  char buffer[100];
60  int bytes_count =
61  sprintf(buffer, formatString_.c_str(), forceTorqueOffset_(0, 0), forceTorqueOffset_(1, 0),
63 
64  if (bytes_count < 0)
65  {
66  ROS_ERROR("Failed to format offset command");
67  return false;
68  }
69  formattedString.clear();
70  formattedString.assign(buffer, bytes_count);
71  return true;
72 }
73 
75  const double& sensorCalibration1, const double& sensorCalibration2, const double& sensorCalibration3,
76  const double& sensorCalibration4, const double& sensorCalibration5, const double& sensorCalibration6,
77  const uint32_t& row)
78  : sensorCalibration1_(sensorCalibration1)
79  , sensorCalibration2_(sensorCalibration2)
80  , sensorCalibration3_(sensorCalibration3)
81  , sensorCalibration4_(sensorCalibration4)
82  , sensorCalibration5_(sensorCalibration5)
83  , sensorCalibration6_(sensorCalibration6)
84  , row_(row)
85 {
86 }
87 
89 {
90  char buffer[100];
91  int bytes_count = sprintf(buffer, formatString_.c_str(), row_, sensorCalibration1_, sensorCalibration2_,
93 
94  if (bytes_count < 0)
95  {
96  ROS_ERROR("Failed to format offset command");
97  return false;
98  }
99  formattedString.clear();
100  formattedString.assign(buffer, bytes_count);
101  return true;
102 }
103 
104 bool RokubiminiSerialCommandHardReset::formatCommand(std::string& formattedString)
105 {
106  formattedString.clear();
107  formattedString.assign(formatString_);
108  return true;
109 }
110 
111 bool RokubiminiSerialCommandSoftReset::formatCommand(std::string& formattedString)
112 {
113  formattedString.clear();
114  formattedString.assign(formatString_);
115  return true;
116 }
117 
118 bool RokubiminiSerialCommandConfig::formatCommand(std::string& formattedString)
119 {
120  formattedString.clear();
121  formattedString.assign(formatString_);
122  return true;
123 }
124 
125 bool RokubiminiSerialCommandRun::formatCommand(std::string& formattedString)
126 {
127  formattedString.clear();
128  formattedString.assign(formatString_);
129  return true;
130 }
131 
132 bool RokubiminiSerialCommandSave::formatCommand(std::string& formattedString)
133 {
134  formattedString.clear();
135  formattedString.assign(formatString_);
136  return true;
137 }
138 
139 bool RokubiminiSerialCommandLoad::formatCommand(std::string& formattedString)
140 {
141  formattedString.clear();
142  formattedString.assign(formatString_);
143  return true;
144 }
145 
146 bool RokubiminiSerialCommandPrint::formatCommand(std::string& formattedString)
147 {
148  formattedString.clear();
149  formattedString.assign(formatString_);
150  return true;
151 }
152 
154 {
155  bool success = false;
156  std::smatch matches;
157  success = regex_search(str, matches, stringRegex_);
158  if (matches.empty() || !matches.ready())
159  {
160  ROS_ERROR("No matches were found");
161  return false;
162  }
163  ROS_INFO("Match size is: %lu", matches.size());
164  for (unsigned i = 0; i < matches.size(); ++i)
165  {
166  ROS_INFO_STREAM("match " << i << ": " << matches[i]);
167  ROS_INFO_STREAM(" (with a length of " << matches[i].length() << ")");
168  }
169  std::string s = matches[0];
170  char temp_comp, calibration, data_format, baud_rate;
171  ROS_DEBUG_STREAM("String is: " << s << " and format is: " << format_);
172  int bytes_count = sscanf(s.c_str(), format_.c_str(), &temp_comp, &calibration, &data_format, &baud_rate);
173  if (bytes_count < 4)
174  {
175  ROS_ERROR("Failed to format communication setup fields");
176  return false;
177  }
178  // use character arithmetic for extracting integer from ASCII codes.
179  tempComp_ = temp_comp - '0';
180  calibration_ = calibration - '0';
181  dataFormat_ = data_format - '0';
182  baudRate_ = baud_rate - '0';
183  ROS_INFO("Baud rate is: %u, data format is: %u, temp comp: %u, calibration: %u", getBaudRate(), getDataFormat(),
184  getTempComp(), getCalibration());
185  return success;
186 }
187 
188 } // namespace serial
189 } // namespace rokubimini
bool formatCommand(std::string &formattedString) override
bool formatCommand(std::string &formattedString) override
bool formatCommand(std::string &formattedString) override
XmlRpcServer s
bool formatCommand(std::string &formattedString) override
bool formatCommand(std::string &formattedString) override
#define ROS_INFO(...)
bool formatCommand(std::string &formattedString) override
#define ROS_DEBUG_STREAM(args)
#define ROS_INFO_STREAM(args)
bool formatCommand(std::string &formattedString) override
#define ROS_ERROR(...)
bool formatCommand(std::string &formattedString) override
System dependencies.


rokubimini_serial
Author(s):
autogenerated on Wed Mar 3 2021 03:09:18