33 IMU_polydriver(
nullptr),
35 subDeviceOwned(
nullptr)
41 prev_timestamp_counter=0;
42 curr_timestamp_counter=0;
45 partName =
"Server Inertial";
57 covariance.assign(9, 0);
89 if(!config.
check(
"ROS") )
107 if(!rosGroup.
check(
"useROS"))
109 yCError(
SERVERINERTIAL) << partName <<
" cannot find useROS parameter, mandatory when using ROS message. \n \
110 Allowed values are true, false, ROS_only";
114 std::string ros_use_type = rosGroup.
find(
"useROS").
asString();
115 if(ros_use_type ==
"false")
121 else if(ros_use_type ==
"true")
126 else if(ros_use_type ==
"only")
133 yCInfo(
SERVERINERTIAL) << partName <<
"useROS parameter is seet to unvalid value ('" << ros_use_type <<
"'), supported values are 'true', 'false', 'only'";
139 if(!rosGroup.
check(
"ROS_nodeName"))
141 yCError(
SERVERINERTIAL) << partName <<
" cannot find ROS_nodeName parameter, mandatory when using ROS message";
149 if(!rosGroup.
check(
"ROS_topicName"))
151 yCError(
SERVERINERTIAL) << partName <<
" cannot find ROS_topicName parameter, mandatory when using ROS message";
155 rosTopicName = rosGroup.
find(
"ROS_topicName").
asString();
159 if(!rosGroup.
check(
"frame_id"))
161 yCError(
SERVERINERTIAL) << partName <<
" cannot find frame_id parameter, mandatory when using ROS message";
171bool ServerInertial::initialize_ROS()
173 bool success =
false;
181 if(rosNode ==
nullptr)
183 yCError(
SERVERINERTIAL) <<
" opening " << rosNodeName <<
" Node, check your yarp-ROS network configuration";
188 if (!rosPublisherPort.
topic(rosTopicName) )
190 yCError(
SERVERINERTIAL) <<
" opening " << rosTopicName <<
" Topic, check your yarp-ROS network configuration";
205 yCError(
SERVERINERTIAL) << partName <<
" ROS parameter are not correct, check your configuration file";
211 yCError(
SERVERINERTIAL) << partName <<
" something went wrong with ROS configuration, we should never be here!!!";
235 p.setMonitor(prop.getMonitor(),
"subdevice");
238 IMU_polydriver->
open(p);
240 IMU_polydriver->
open(subdevice);
243 if (!IMU_polydriver->
isValid())
250 IMU_polydriver->
view(IMU);
254 IMU_polydriver->
close();
259 IMU_polydriver->
view(iTimed);
275 yCWarning(
SERVERINERTIAL) <<
"The 'inertial' device is deprecated in favour of 'multipleanalogsensorsremapper' + 'multipleanalogsensorsserver' + 'IMURosPublisher'.";
276 yCWarning(
SERVERINERTIAL) <<
"The old device is no longer supported, and it will be deprecated in YARP 3.7 and removed in YARP 4.";
290 if(prop.
check(
"subdevice"))
293 if(! openAndAttachSubDevice(prop))
302 if (!openDeferredAttach(prop)) {
308 checkROSParams(config);
313 std::string portName;
316 if (config.
check(
"name")) {
319 yCInfo(
SERVERINERTIAL) <<
"Using default values for port name, you can change it by using '--name /myPortName' parameter";
320 portName =
"/inertial";
323 if(!p.open(portName))
332 if(!initialize_ROS() )
337 if( (ownDevices) && (IMU!=
nullptr) )
350 if(rosNode!=
nullptr) {
356 if( (ownDevices) && (IMU_polydriver !=
nullptr) )
358 IMU_polydriver->
close();
379 worked=IMU->
read(indata);
385 for (
int i = 0; i < nchannels; i++) {
425 curr_timestamp_counter = ts.
getCount();
427 if (curr_timestamp_counter!=prev_timestamp_counter)
435 writer.
write(strict);
442 prev_timestamp_counter = curr_timestamp_counter;
449 double euler_xyz[3], quaternion[4];
479 rosPublisherPort.
write();
485 if ((
now - before) < period) {
486 double k = period-(
now-before);
496 cmd.
read(connection);
505 if (IMU ==
nullptr) {
return false; }
506 return IMU->
read (out);
511 if (IMU ==
nullptr) {
return false; }
517 if (IMU==
nullptr) {
return false;}
530 IMU_polydriver = poly;
531 IMU_polydriver->
view(IMU);
534 IMU_polydriver->
view(iTimed);
538 if (!Thread::isRunning()) {
556 if (imuToAttachTo.
size() != 1)
562 return attach(imuToAttachTo[0]->poly);
const yarp::os::LogComponent & SERVERINERTIAL()
inertial deprecated: Export an inertial sensor.
bool attach(yarp::dev::PolyDriver *poly) override
IWrapper interface Attach to another object.
bool close() override
Close the DeviceDriver.
bool open(yarp::os::Searchable &config) override
Open the device driver.
bool detach() override
Detach the object (you must have first called attach).
virtual bool getInertial(yarp::os::Bottle &bot)
bool calibrate(int ch, double v) override
Calibrate the sensor, single channel.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
void run() override
Main body of the new thread.
~ServerInertial() override
bool attachAll(const yarp::dev::PolyDriverList &p) override
IMultipleWrapper interface Attach to a list of objects.
bool getChannels(int *nc) override
Get the number of channels of the sensor.
bool detachAll() override
Detach the object (you must have first called attach).
bool view(T *&x)
Get an interface to the device driver.
virtual bool read(yarp::sig::Vector &out)=0
Read a vector from the sensor.
virtual bool getChannels(int *nc)=0
Get the number of channels of the sensor.
virtual bool calibrate(int ch, double v)=0
Calibrate the sensor, single channel.
virtual yarp::os::Stamp getLastInputStamp()=0
Return the time stamp relative to the last acquisition.
A container for a device driver.
bool close() override
Close the DeviceDriver.
bool isValid() const
Check if device is valid.
bool open(const std::string &txt)
Construct and configure a device by its common name.
A simple collection of objects that can be described and transmitted in a portable way.
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
void addFloat64(yarp::conf::float64_t x)
Places a 64-bit floating point number in the bottle, at the end of the list.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
void clear()
Empties the bottle of any objects it contains.
bool isNull() const override
Checks if the object is invalid.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
An interface for reading from a network connection.
void interrupt()
interrupt delegates the call to the Node port interrupt.
T & get()
A synonym of PortWriterBuffer::prepare.
void write(bool forceStrict=false)
Try to write the last buffer returned by PortWriterBuffer::get.
void attach(Port &port)
Set the Port to which objects will be written.
A class for storing options and configuration information.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
std::string toString() const override
Return a standard text representation of the content of the object.
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.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
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.
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list corresponding to a given keyword.
An abstraction for a time stamp and/or sequence number.
void update()
Set the timestamp to the current time, and increment the sequence number (wrapping to 0 if the sequen...
int getCount() const
Get the sequence number.
bool stop()
Stop the thread.
bool isStopping()
Returns true if the thread is stopping (Thread::stop has been called).
bool start()
Start the new thread running.
A single value (typically within a Bottle).
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual bool isString() const
Checks if value is a string.
std::string toString() const override
Return a standard text representation of the content of the object.
virtual std::string asString() const
Get string value.
yarp::rosmsg::std_msgs::Header header
std::vector< yarp::conf::float64_t > orientation_covariance
yarp::rosmsg::geometry_msgs::Vector3 angular_velocity
std::vector< yarp::conf::float64_t > linear_acceleration_covariance
yarp::rosmsg::geometry_msgs::Vector3 linear_acceleration
yarp::rosmsg::geometry_msgs::Quaternion orientation
std::vector< yarp::conf::float64_t > angular_velocity_covariance
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
void delay(double seconds)
Wait for a certain number of seconds.
An interface to the operating system, including Port based communication.
bool convertEulerAngleYXZdegrees_to_quaternion(double *eulerXYZ, double *quaternion)