6#define _USE_MATH_DEFINES
23 m_odometry2D_interface =
nullptr;
32 driver->
view(m_odometry2D_interface);
37 if (m_odometry2D_interface ==
nullptr)
43 PeriodicThread::setPeriod(m_period);
44 return PeriodicThread::start();
50 if (PeriodicThread::isRunning())
52 PeriodicThread::stop();
54 m_odometry2D_interface =
nullptr;
68 if (config.
check(
"publish_tf_topic")) {
69 m_enable_publish_tf =
true;
71 if (config.
check(
"skip_tf_topic")) {
72 m_enable_publish_tf =
false;
75 if (!config.
check(
"period")) {
81 if (!config.
check(
"node_name")) {
86 if (m_nodeName[0] !=
'/') {
91 if (!config.
check(
"topic_name")) {
96 if (m_topicName[0] !=
'/') {
101 if (!config.
check(
"odom_frame")) {
108 if (!config.
check(
"base_frame")) {
114 if (config.
check(
"subdevice")) {
130 if (m_node ==
nullptr) {
134 if (!rosPublisherPort_odometry.
topic(m_topicName)) {
139 if (m_enable_publish_tf)
141 if (!rosPublisherPort_tf.
topic(
"/tf")) {
155 if (m_odometry2D_interface!=
nullptr)
158 double synchronized_timestamp = 0;
159 m_odometry2D_interface->
getOdometry(odometryData, &synchronized_timestamp);
161 if (std::isnan(synchronized_timestamp) ==
false)
163 m_lastStateStamp.
update(synchronized_timestamp);
183 double cosYaw = cos(halfYaw);
184 double sinYaw = sin(halfYaw);
187 odom_quat.
z = sinYaw;
188 odom_quat.
w = cosYaw;
196 rosPublisherPort_odometry.
write();
199 if (m_enable_publish_tf)
208 double cosYaw = cos(halfYaw);
209 double sinYaw = sin(halfYaw);
229 rosPublisherPort_tf.
write();
240 if (PeriodicThread::isRunning())
242 PeriodicThread::stop();
249 rosPublisherPort_odometry.
close();
250 if (m_enable_publish_tf)
252 rosPublisherPort_tf.
close();
const yarp::os::LogComponent & ODOMETRY2D_NWS_ROS()
constexpr double DEFAULT_THREAD_PERIOD
Odometry2D_nws_ros: A ros nws to get odometry and publish it on a ros topic. The attached device must...
bool open(yarp::os::Searchable ¶ms) override
Open the DeviceDriver.
bool detach() override
Detach the object (you must have first called attach).
bool threadInit() override
Initialization method.
void run() override
Loop function.
void threadRelease() override
Release method.
bool attach(yarp::dev::PolyDriver *driver) override
Attach to another object.
bool close() override
Close the DeviceDriver.
bool view(T *&x)
Get an interface to the device driver.
virtual bool getOdometry(yarp::dev::OdometryData &odom, double *timestamp=nullptr)=0
Gets the odometry of the robot, including its velocity expressed in the world and in the local refere...
double base_vel_x
velocity of the robot [m/s] expressed in the robot reference frame
double base_vel_theta
angular velocity of the robot [deg/s] expressed in the robot reference frame
double base_vel_y
velocity of the robot [m/s] expressed in the robot reference frame
double odom_x
position of the robot [m], expressed in the world reference frame
double odom_y
position of the robot [m], expressed in the world reference frame
double odom_theta
orientation the robot [deg], expressed in the world reference frame
A container for a device driver.
bool isValid() const
Check if device is valid.
bool open(const std::string &txt)
Construct and configure a device by its common name.
A class for storing options and configuration information.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
void close() override
Stop port activity.
bool topic(const std::string &name)
Set topic to publish to.
void write(bool forceStrict=false)
Write the current object being returned by Publisher::prepare.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::Publisher::write.
A base class for nested structures that can be searched.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
void update()
Set the timestamp to the current time, and increment the sequence number (wrapping to 0 if the sequen...
double getTime() const
Get the time stamp.
int getCount() const
Get the sequence number.
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual std::string asString() const
Get string value.
yarp::rosmsg::geometry_msgs::Pose pose
yarp::rosmsg::geometry_msgs::Point position
yarp::rosmsg::geometry_msgs::Quaternion orientation
yarp::rosmsg::geometry_msgs::Twist twist
yarp::rosmsg::geometry_msgs::Vector3 angular
yarp::rosmsg::geometry_msgs::Vector3 linear
yarp::rosmsg::geometry_msgs::PoseWithCovariance pose
yarp::rosmsg::std_msgs::Header header
std::string child_frame_id
yarp::rosmsg::geometry_msgs::TwistWithCovariance twist
std::vector< yarp::rosmsg::geometry_msgs::TransformStamped > transforms
#define yCError(component,...)
#define yCTrace(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
double now()
Return the current time in seconds, relative to an arbitrary starting point.
The main, catch-all namespace for YARP.