YARP
Yet Another Robot Platform
ServerInertial.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef YARP_DEV_SERVERINERTIAL_SERVERINERTIAL_H
11 #define YARP_DEV_SERVERINERTIAL_SERVERINERTIAL_H
12 
13 #include <cstdio>
14 
15 #include <yarp/os/BufferedPort.h>
16 #include <yarp/dev/PolyDriver.h>
18 #include <yarp/os/Time.h>
19 #include <yarp/os/Network.h>
20 #include <yarp/os/Thread.h>
21 #include <yarp/os/Vocab.h>
22 #include <yarp/os/Bottle.h>
24 #include <yarp/dev/IWrapper.h>
26 
27 // ROS state publisher
28 #include <yarp/os/Node.h>
29 #include <yarp/os/Publisher.h>
32 
33 
110  public yarp::dev::IWrapper,
112  private yarp::os::Thread,
113  public yarp::os::PortReader,
115 {
116 private:
117  bool spoke;
118  std::string partName;
119  yarp::dev::PolyDriver *IMU_polydriver;
120  yarp::dev::IGenericSensor *IMU; //The inertial device
122  double period;
123  yarp::os::Port p;
125  int prev_timestamp_counter;
126  int curr_timestamp_counter;
127  int trap;
128  bool strict;
129 
130  // ROS data
131  ROSTopicUsageType useROS; // decide if open ROS topic or not
132  std::string frame_id; // name of the frame measures are referred to
133  std::string rosNodeName; // name of the rosNode
134  std::string rosTopicName; // name of the rosTopic
135  yarp::os::Node *rosNode; // add a ROS node
136  yarp::os::NetUint32 rosMsgCounter; // incremental counter in the ROS message
137  yarp::os::Publisher<yarp::rosmsg::sensor_msgs::Imu> rosPublisherPort; // Dedicated ROS topic publisher
138  std::vector<yarp::os::NetFloat64> covariance; // empty matrix to store covariance data needed by ROS msg
139 
140  bool checkROSParams(yarp::os::Searchable &config);
141  bool initialize_ROS();
142  bool initialize_YARP(yarp::os::Searchable &prop);
143 
144 public:
145  ServerInertial();
146  ServerInertial(const ServerInertial&) = delete;
150  ~ServerInertial() override;
151 
157  bool open(yarp::os::Searchable& config) override;
158 
159  bool close() override;
160 
161  virtual bool getInertial(yarp::os::Bottle &bot);
162 
163  void run() override;
164 
165  bool read(yarp::os::ConnectionReader& connection) override;
166 
167  bool read(yarp::sig::Vector &out) override;
168 
169  bool getChannels(int *nc) override;
170 
171  bool calibrate(int ch, double v) override;
172 
178  bool attach(yarp::dev::PolyDriver *poly) override;
179  bool detach() override;
180 
186  bool attachAll(const yarp::dev::PolyDriverList &p) override;
187  bool detachAll() override;
188 
189 private:
190 
191  bool ownDevices;
192  yarp::dev::PolyDriver *subDeviceOwned;
193 
194  // Open the wrapper only, the attach method needs to be called before using it
195  bool openDeferredAttach(yarp::os::Property& prop);
196 
197  // If a subdevice parameter is given to the wrapper, it will open it as well
198  // and attach to it immediately.
199  bool openAndAttachSubDevice(yarp::os::Property& prop);
200 };
201 
202 
203 #endif // YARP_DEV_SERVERINERTIAL_SERVERINERTIAL_H
ServerInertial::~ServerInertial
~ServerInertial() override
Definition: ServerInertial.cpp:81
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
ServerInertial::attach
bool attach(yarp::dev::PolyDriver *poly) override
IWrapper interface Attach to another object.
Definition: ServerInertial.cpp:517
Network.h
yarp::dev::IGenericSensor
A generic interface to sensors – gyro, a/d converters etc.
Definition: IGenericSensor.h:25
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
ServerInertial::getInertial
virtual bool getInertial(yarp::os::Bottle &bot)
Definition: ServerInertial.cpp:362
IWrapper.h
IPreciselyTimed.h
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
yarp::os::PortWriterBuffer< yarp::os::Bottle >
yarp::os::Thread
An abstraction for a thread of execution.
Definition: Thread.h:25
Imu.h
yarp::os::Publisher< yarp::rosmsg::sensor_msgs::Imu >
yarp::dev::PolyDriverList
Definition: PolyDriverList.h:22
ServerInertial::ServerInertial
ServerInertial()
Constructor.
Definition: ServerInertial.cpp:35
yarpRosHelper.h
yarp::sig::VectorOf< double >
yarp::os::Port
A mini-server for network communication.
Definition: Port.h:50
ServerInertial::detach
bool detach() override
Detach the object (you must have first called attach).
Definition: ServerInertial.cpp:543
ServerInertial::ServerInertial
ServerInertial(const ServerInertial &)=delete
yarp::os::PortReader
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:28
ROSTopicUsageType
ROSTopicUsageType
Definition: yarpRosHelper.h:19
PolyDriver.h
yarp::os::NetUint32
std::uint32_t NetUint32
Definition of the NetUint32 type.
Definition: NetUint32.h:33
ServerInertial::operator=
ServerInertial & operator=(const ServerInertial &)=delete
yarp::dev::PolyDriver
A container for a device driver.
Definition: PolyDriver.h:27
ServerInertial
inertial: Export an inertial sensor.
Definition: ServerInertial.h:115
ServerInertial::calibrate
bool calibrate(int ch, double v) override
Calibrate the sensor, single channel.
Definition: ServerInertial.cpp:510
Node.h
yarp::dev::IWrapper
Interface for an object that can wrap/or "attach" to another.
Definition: IWrapper.h:29
ServerInertial::detachAll
bool detachAll() override
Detach the object (you must have first called attach).
Definition: ServerInertial.cpp:559
Thread.h
yarp::os::Node
The Node class.
Definition: Node.h:27
ServerInertial::close
bool close() override
Close the DeviceDriver.
Definition: ServerInertial.cpp:342
ServerInertial::attachAll
bool attachAll(const yarp::dev::PolyDriverList &p) override
IMultipleWrapper interface Attach to a list of objects.
Definition: ServerInertial.cpp:548
BufferedPort.h
IMultipleWrapper.h
ServerInertial::run
void run() override
Main body of the new thread.
Definition: ServerInertial.cpp:394
ServerInertial::ServerInertial
ServerInertial(ServerInertial &&)=delete
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
ServerInertial::getChannels
bool getChannels(int *nc) override
Get the number of channels of the sensor.
Definition: ServerInertial.cpp:504
ServerInertial::open
bool open(yarp::os::Searchable &config) override
Open the device driver.
Definition: ServerInertial.cpp:274
Publisher.h
yarp::dev::IMultipleWrapper
Interface for an object that can wrap/attach to to another.
Definition: IMultipleWrapper.h:30
IGenericSensor.h
ServerInertial::operator=
ServerInertial & operator=(ServerInertial &&)=delete
Vocab.h
Time.h
yarp::dev::IPreciselyTimed
Definition: IPreciselyTimed.h:21
ServerInertial::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: ServerInertial.cpp:488
Bottle.h
yarp::os::Property
A class for storing options and configuration information.
Definition: Property.h:37