4 : port_(
"/dev/ttyUSB0"),
7 control_frequency_(50.0),
8 odom_frame_parent_(
"odom"),
9 odom_frame_child_(
"base_link"),
10 cmd_vel_timeout_(1.0),
44 catch (
const std::exception &e)
46 cout <<
"connection failed" << endl;
49 cout <<
"Connected to serial : " <<
port_ <<
" with baudrate " <<
baudrate_ << endl;
107 if (msg[0] ==
'F' && msg[2] ==
':')
111 size_t index = boost::lexical_cast<size_t>(msg[1]);
113 vector<string> feedbacks;
114 boost::split(feedbacks, msg, boost::algorithm::is_any_of(
":"));
130 if (feedbacks.size() > 8)
154 toVW(l_speed, r_speed);
179 catch (boost::bad_lexical_cast &e)
183 else if (msg[0] ==
'I' && msg[1] ==
'O' && msg[2] ==
':')
188 boost::split(io, msg, boost::algorithm::is_any_of(
":"));
194 catch (boost::bad_lexical_cast& e)
204 if (bitset<16>(flags)[0] == 1)
206 if (bitset<16>(flags)[1] == 1)
208 if (bitset<16>(flags)[2] == 1)
210 if (bitset<16>(flags)[3] == 1)
212 if (bitset<16>(flags)[4] == 1)
214 if (bitset<16>(flags)[5] == 1)
216 if (bitset<16>(flags)[6] == 1)
218 if (bitset<16>(flags)[7] == 1)
236 return make_pair(l_speed, r_speed);
243 if (abs(speed) > max)
305 if ((dR - dL) == 0.0000 )
323 double ICCx = x - (R * sin(theta));
324 double ICCy = y + (R * cos(theta));
326 cout <<
"ICCx : "<<ICCx <<
" , ICCy : "<<ICCy <<endl;
329 posX_ = (cos(Wdt) * (x - ICCx)) - (sin(Wdt) * (y - ICCy)) + ICCx;
330 posY_ = (sin(Wdt) * (x - ICCx)) + (cos(Wdt) * (y - ICCy)) + ICCy;
333 cout <<
"update pose x : " <<
posX_ <<
", y : " <<
posY_ <<
", heading : " <<
heading_ << endl << endl;
338 int ms = 1000 * (float)1/hz;
339 cout <<
"publish loop hz : "<<hz <<
", ms : "<<ms<<endl;
344 std::this_thread::sleep_for(std::chrono::milliseconds(ms));
350 clober_msgs::Feedback feedback;
354 feedback.header.stamp = stamp_now;
380 nav_msgs::Odometry odom;
383 odom.header.stamp = stamp_now;
384 odom.pose.pose.position.x =
posX_;
385 odom.pose.pose.position.y =
posY_;
386 odom.pose.pose.orientation.x = q.x();
387 odom.pose.pose.orientation.y = q.y();
388 odom.pose.pose.orientation.z = q.z();
389 odom.pose.pose.orientation.w = q.w();
390 odom.pose.covariance.fill(0.0);
391 odom.pose.covariance[0] = 1e-3;
392 odom.pose.covariance[7] = 1e-3;
393 odom.pose.covariance[14] = 1e6;
394 odom.pose.covariance[21] = 1e6;
395 odom.pose.covariance[28] = 1e6;
396 odom.pose.covariance[35] = 1e-3;
400 odom.twist.covariance.fill(0.0);
401 odom.twist.covariance[0] = 1e-3;
402 odom.twist.covariance[7] = 1e-3;
403 odom.twist.covariance[14] = 1e6;
404 odom.twist.covariance[21] = 1e6;
405 odom.twist.covariance[28] = 1e6;
406 odom.twist.covariance[35] = 1e3;
408 geometry_msgs::TransformStamped odom_tf;
409 odom_tf.header.stamp = stamp_now;
412 odom_tf.transform.translation.x =
posX_;
413 odom_tf.transform.translation.y =
posY_;
414 odom_tf.transform.translation.z = 0;
415 odom_tf.transform.rotation = odom.pose.pose.orientation;
442 msg <<
"!B 3 1" <<
"\r";
449 msg <<
"!R 2" <<
"\r";
456 pair<float, float> wheel_speed;
462 pair<float, float> wheel_rpm;
468 if (abs(wheel_rpm.first) < 0.0001 && abs(wheel_rpm.second) < 0.0001)
472 sendRPM(make_pair(0, 1), make_pair(wheel_rpm.first, wheel_rpm.second));
479 msg <<
"!G " << channel.first + 1 <<
" " << rpm.first <<
"\r"
480 <<
"!G " << channel.second + 1 <<
" " << rpm.second <<
"\r";
483 cout <<
"send rpm : " << msg.str() << endl;
489 msg <<
"!MS " << channel.first + 1 <<
"\r" <<
"!MS " << channel.second + 1 <<
"\r";
491 cout <<
"stop : " << msg.str() << endl;