本文整理汇总了C++中Transporter::getDisplacement方法的典型用法代码示例。如果您正苦于以下问题:C++ Transporter::getDisplacement方法的具体用法?C++ Transporter::getDisplacement怎么用?C++ Transporter::getDisplacement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transporter
的用法示例。
在下文中一共展示了Transporter::getDisplacement方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: publish_odom
void TransporterNode::publish_odom()
{
// store the current pose
prevPose.x = cur_x;
prevPose.y = cur_y;
prevPose.theta = cur_theta;
// calculate the new pose
double distance, angle;
trobot.getDisplacement(&distance, &angle);
cur_theta += angle;
cur_x += distance * cos(cur_theta);
cur_y += distance * sin(cur_theta);
ROS_DEBUG("PREVIOUS x = [%f], y = [%f], theta = [%f]\n", prevPose.x, prevPose.y, prevPose.theta);
ROS_DEBUG("CURRENT x = [%f], y = [%f], theta = [%f]\n", cur_x, cur_y, cur_theta);
current_time = ros::Time::now();
double dt = (current_time - last_time).toSec();
// convert rotation about z into quaternion
geometry_msgs::Quaternion odom_quat;
odom_quat.z = sin(cur_theta/2.0);
odom_quat.w = cos(cur_theta/2.0);
//next, we'll publish the odometry message over ROS
nav_msgs::Odometry odom;
odom.header.stamp = current_time;
odom.header.frame_id = "odom";
odom.child_frame_id = "base_footprint";
//set the position (with respect to header.frame)
odom.pose.pose.position.x = cur_x;
odom.pose.pose.position.y = cur_y;
odom.pose.pose.position.z = 0.0;
odom.pose.pose.orientation = odom_quat;
odom.pose.covariance =
boost::array<double, 36>{{1e-3, 0, 0, 0, 0, 0,
0, 1e-3, 0, 0, 0, 0,
0, 0, 1e6, 0, 0, 0,
0, 0, 0, 1e6, 0, 0,
0, 0, 0, 0, 1e6, 0,
0, 0, 0, 0, 0, 1e-3}};
//set the velocity (with respect to child_frame)
odom.twist.twist.linear.x = distance/dt;
odom.twist.twist.angular.z = angle/dt;
odom.twist.covariance =
boost::array<double, 36>{{1e-3, 0, 0, 0, 0, 0,
0, 1e-3, 0, 0, 0, 0,
0, 0, 1e6, 0, 0, 0,
0, 0, 0, 1e6, 0, 0,
0, 0, 0, 0, 1e6, 0,
0, 0, 0, 0, 0, 1e-3}};
//publish the message
odom_pub.publish(odom);
// publish joint state in order to show the continuous joints (wheels) in tf
sensor_msgs::JointState js;
js.header.stamp=current_time;
js.name.resize(2);
js.position.resize(2);
js.name[0]="left_wheel_joint";
js.name[1]="right_wheel_joint";
js.position[0]=0;
js.position[1]=0;
js_pub.publish(js);
last_time = current_time;
} //void TransporterNode::publish_odom()