 |
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
36 IMU_polydriver(
nullptr),
38 subDeviceOwned(
nullptr)
44 prev_timestamp_counter=0;
45 curr_timestamp_counter=0;
48 partName =
"Server Inertial";
60 covariance.assign(9, 0);
83 if (IMU !=
nullptr) close();
90 if(!config.
check(
"ROS") )
108 if(!rosGroup.
check(
"useROS"))
110 yCError(
SERVERINERTIAL) << partName <<
" cannot find useROS parameter, mandatory when using ROS message. \n \
111 Allowed values are true, false, ROS_only";
115 std::string ros_use_type = rosGroup.
find(
"useROS").
asString();
116 if(ros_use_type ==
"false")
122 else if(ros_use_type ==
"true")
127 else if(ros_use_type ==
"only")
134 yCInfo(
SERVERINERTIAL) << partName <<
"useROS parameter is seet to unvalid value ('" << ros_use_type <<
"'), supported values are 'true', 'false', 'only'";
140 if(!rosGroup.
check(
"ROS_nodeName"))
142 yCError(
SERVERINERTIAL) << partName <<
" cannot find ROS_nodeName parameter, mandatory when using ROS message";
150 if(!rosGroup.
check(
"ROS_topicName"))
152 yCError(
SERVERINERTIAL) << partName <<
" cannot find ROS_topicName parameter, mandatory when using ROS message";
156 rosTopicName = rosGroup.
find(
"ROS_topicName").
asString();
160 if(!rosGroup.
check(
"frame_id"))
162 yCError(
SERVERINERTIAL) << partName <<
" cannot find frame_id parameter, mandatory when using ROS message";
172 bool ServerInertial::initialize_ROS()
174 bool success =
false;
184 yCError(
SERVERINERTIAL) <<
" opening " << rosNodeName <<
" Node, check your yarp-ROS network configuration";
189 if (!rosPublisherPort.topic(rosTopicName) )
191 yCError(
SERVERINERTIAL) <<
" opening " << rosTopicName <<
" Topic, check your yarp-ROS network configuration";
206 yCError(
SERVERINERTIAL) << partName <<
" ROS parameter are not correct, check your configuration file";
212 yCError(
SERVERINERTIAL) << partName <<
" something went wrong with ROS configuration, we should never be here!!!";
236 p.setMonitor(prop.getMonitor(),
"subdevice");
239 IMU_polydriver->open(p);
242 IMU_polydriver->open(subdevice);
244 if (!IMU_polydriver->isValid())
251 IMU_polydriver->view(IMU);
255 IMU_polydriver->close();
260 IMU_polydriver->view(iTimed);
287 if(prop.
check(
"subdevice"))
290 if(! openAndAttachSubDevice(prop))
299 if(!openDeferredAttach(prop))
304 checkROSParams(config);
309 std::string portName;
312 if (config.
check(
"name"))
316 yCInfo(
SERVERINERTIAL) <<
"Using default values for port name, you can change it by using '--name /myPortName' parameter";
317 portName =
"/inertial";
320 if(!p.open(portName))
329 if(!initialize_ROS() )
334 if( (ownDevices) && (IMU!=
nullptr) )
353 if( (ownDevices) && (IMU_polydriver !=
nullptr) )
355 IMU_polydriver->close();
371 IMU->getChannels (&nchannels);
376 worked=IMU->read(indata);
382 for (
int i = 0; i < nchannels; i++)
398 while (!isStopping())
404 bool res = getInertial(imuData);
415 ts=iTimed->getLastInputStamp();
420 curr_timestamp_counter = ts.
getCount();
422 if (curr_timestamp_counter!=prev_timestamp_counter)
430 writer.
write(strict);
437 prev_timestamp_counter = curr_timestamp_counter;
444 double euler_xyz[3], quaternion[4];
474 rosPublisherPort.write();
480 if ((
now - before) < period) {
481 double k = period-(
now-before);
491 cmd.
read(connection);
500 if (IMU ==
nullptr) {
return false; }
501 return IMU->read (out);
506 if (IMU ==
nullptr) {
return false; }
507 return IMU->getChannels (nc);
512 if (IMU==
nullptr) {
return false;}
513 return IMU->calibrate(ch, v);
525 IMU_polydriver = poly;
526 IMU_polydriver->
view(IMU);
529 IMU_polydriver->view(iTimed);
533 if(!Thread::isRunning())
550 if (imuToAttachTo.
size() != 1)
556 return attach(imuToAttachTo[0]->poly);
~ServerInertial() override
A simple collection of objects that can be described and transmitted in a portable way.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
std::vector< yarp::conf::float64_t > angular_velocity_covariance
void clear()
Empties the bottle of any objects it contains.
bool attach(yarp::dev::PolyDriver *poly) override
IWrapper interface Attach to another object.
A base class for nested structures that can be searched.
virtual bool getInertial(yarp::os::Bottle &bot)
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list corresponding to a given keyword.
bool write(ConnectionWriter &writer) const override
Write this object to a network connection.
virtual std::string toString() const =0
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.
#define YARP_LOG_COMPONENT(name,...)
std::vector< yarp::conf::float64_t > linear_acceleration_covariance
yarp::rosmsg::geometry_msgs::Quaternion orientation
const yarp::os::LogComponent & SERVERINERTIAL()
bool view(T *&x)
Get an interface to the device driver.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
void addFloat64(yarp::conf::float64_t x)
Places a 64-bit floating point number in the bottle, at the end of the list.
yarp::rosmsg::geometry_msgs::Vector3 angular_velocity
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface for the device drivers.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
virtual bool isString() const
Checks if value is a string.
bool detach() override
Detach the object (you must have first called attach).
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
std::string toString() const override
Return a standard text representation of the content of the object.
virtual std::string asString() const
Get string value.
A container for a device driver.
inertial: Export an inertial sensor.
bool calibrate(int ch, double v) override
Calibrate the sensor, single channel.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
bool detachAll() override
Detach the object (you must have first called attach).
yarp::rosmsg::geometry_msgs::Vector3 linear_acceleration
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
int getCount() const
Get the sequence number.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
bool close() override
Close the DeviceDriver.
bool attachAll(const yarp::dev::PolyDriverList &p) override
IMultipleWrapper interface Attach to a list of objects.
void run() override
Main body of the new thread.
bool isNull() const override
Checks if the object is invalid.
An interface for reading from a network connection.
bool getChannels(int *nc) override
Get the number of channels of the sensor.
An abstraction for a time stamp and/or sequence number.
#define yCError(component,...)
bool convertEulerAngleYXZdegrees_to_quaternion(double *eulerXYZ, double *quaternion)
void update()
Set the timestamp to the current time, and increment the sequence number (wrapping to 0 if the sequen...
#define yCInfo(component,...)
bool open(yarp::os::Searchable &config) override
Open the device driver.
An interface to the operating system, including Port based communication.
#define yCDebug(component,...)
std::vector< yarp::conf::float64_t > orientation_covariance
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
void interrupt()
interrupt delegates the call to the Node port interrupt.
yarp::rosmsg::std_msgs::Header header
#define yCTrace(component,...)
std::string toString() const override
Return a standard text representation of the content of the object.
A single value (typically within a Bottle).
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
void delay(double seconds)
Wait for a certain number of seconds.
A class for storing options and configuration information.