-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Publish sensors tfs as static, and allow configuring odom frequency #202
base: indigo-devel
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,9 +60,13 @@ namespace stdr_robot | |
_moveRobotService = n.advertiseService( | ||
getName() + "/replace", &Robot::moveRobotCallback, this); | ||
|
||
//we should not start the timer, until we hame a motion controller | ||
//allow changing odometry rate, as the default 10Hz can be too slow in some cases | ||
double odometry_rate; | ||
n.param(getName() + "/odometry_rate", odometry_rate, 10.0); | ||
|
||
//we should not start the timer, until we have a motion controller | ||
_tfTimer = n.createTimer( | ||
ros::Duration(0.1), &Robot::publishTransforms, this, false, false); | ||
ros::Duration(1.0/odometry_rate), &Robot::publishTransforms, this, false, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we put the default to 100Hz and not use the parameter? If you use the parameter you would need to check for division by zero. I also don't know what would be the computational impact if we increase to 100Hz though... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Impact is small, I get similar same CPU usage (~85% vs. ~90% in my machine). What is normal as the function is quite light. But 50 Hz would be equally fine. |
||
} | ||
|
||
/** | ||
|
@@ -172,6 +176,27 @@ namespace stdr_robot | |
new IdealMotionController(_currentPose, _tfBroadcaster, n, getName(), p)); | ||
} | ||
|
||
//!< Sensors static tfs | ||
for (int i = 0; i < _sensors.size(); i++) { | ||
geometry_msgs::Pose2D sensorPose = _sensors[i]->getSensorPose(); | ||
|
||
geometry_msgs::TransformStamped static_transformStamped; | ||
|
||
static_transformStamped.header.stamp = ros::Time::now(); | ||
static_transformStamped.header.frame_id = getName(); | ||
static_transformStamped.child_frame_id = _sensors[i]->getFrameId(); | ||
static_transformStamped.transform.translation.x = sensorPose.x; | ||
static_transformStamped.transform.translation.y = sensorPose.y; | ||
static_transformStamped.transform.translation.z = 0.0; | ||
tf2::Quaternion quat; | ||
quat.setRPY(0.0, 0.0, sensorPose.theta); | ||
static_transformStamped.transform.rotation.x = quat.x(); | ||
static_transformStamped.transform.rotation.y = quat.y(); | ||
static_transformStamped.transform.rotation.z = quat.z(); | ||
static_transformStamped.transform.rotation.w = quat.w(); | ||
static_broadcaster.sendTransform(static_transformStamped); | ||
} | ||
|
||
_tfTimer.start(); | ||
} | ||
|
||
|
@@ -407,7 +432,7 @@ namespace stdr_robot | |
} | ||
|
||
/** | ||
@brief Publishes the tf transforms every with 10Hz | ||
@brief Publishes the tf transforms every with 10Hz (default) | ||
@return void | ||
**/ | ||
void Robot::publishTransforms(const ros::TimerEvent&) | ||
|
@@ -442,25 +467,7 @@ namespace stdr_robot | |
_previousPose.theta); | ||
odom.twist.twist = _motionControllerPtr->getVelocity(); | ||
|
||
_odomPublisher.publish(odom); | ||
|
||
//!< Sensors tf | ||
for (int i = 0; i < _sensors.size(); i++) { | ||
geometry_msgs::Pose2D sensorPose = _sensors[i]->getSensorPose(); | ||
|
||
tf::Vector3 trans(sensorPose.x, sensorPose.y, 0); | ||
tf::Quaternion rot; | ||
rot.setRPY(0, 0, sensorPose.theta); | ||
|
||
tf::Transform robotToSensor(rot, trans); | ||
|
||
_tfBroadcaster.sendTransform( | ||
tf::StampedTransform( | ||
robotToSensor, | ||
ros::Time::now(), | ||
getName(), | ||
_sensors[i]->getFrameId())); | ||
} | ||
_odomPublisher.publish(odom); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this function the same time can be used when publishing odometry and the pose tf, instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. true. In fact, using the same timestamp also for the sensors made things better (though using static tf is much much better anyway and the reasonable thing to do) |
||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prepend underscore to comply with the coding styleguide (I know it's ugly...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right