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 
113  public yarp::dev::IWrapper,
115  private yarp::os::Thread,
116  public yarp::os::PortReader,
118 {
119 private:
120  bool spoke;
121  std::string partName;
122  yarp::dev::PolyDriver *IMU_polydriver;
123  yarp::dev::IGenericSensor *IMU; //The inertial device
125  double period;
126  yarp::os::Port p;
128  int prev_timestamp_counter;
129  int curr_timestamp_counter;
130  int trap;
131  bool strict;
132 
133  // ROS data
134  ROSTopicUsageType useROS; // decide if open ROS topic or not
135  std::string frame_id; // name of the frame measures are referred to
136  std::string rosNodeName; // name of the rosNode
137  std::string rosTopicName; // name of the rosTopic
138  yarp::os::Node *rosNode; // add a ROS node
139  yarp::os::NetUint32 rosMsgCounter; // incremental counter in the ROS message
140  yarp::os::Publisher<yarp::rosmsg::sensor_msgs::Imu> rosPublisherPort; // Dedicated ROS topic publisher
141  std::vector<yarp::os::NetFloat64> covariance; // empty matrix to store covariance data needed by ROS msg
142 
143  bool checkROSParams(yarp::os::Searchable &config);
144  bool initialize_ROS();
145  bool initialize_YARP(yarp::os::Searchable &prop);
146 
147 public:
148  ServerInertial();
149  ServerInertial(const ServerInertial&) = delete;
153  ~ServerInertial() override;
154 
160  bool open(yarp::os::Searchable& config) override;
161 
162  bool close() override;
163 
164  virtual bool getInertial(yarp::os::Bottle &bot);
165 
166  void run() override;
167 
168  bool read(yarp::os::ConnectionReader& connection) override;
169 
170  bool read(yarp::sig::Vector &out) override;
171 
172  bool getChannels(int *nc) override;
173 
174  bool calibrate(int ch, double v) override;
175 
181  bool attach(yarp::dev::PolyDriver *poly) override;
182  bool detach() override;
183 
189  bool attachAll(const yarp::dev::PolyDriverList &p) override;
190  bool detachAll() override;
191 
192 private:
193 
194  bool ownDevices;
195  yarp::dev::PolyDriver *subDeviceOwned;
196 
197  // Open the wrapper only, the attach method needs to be called before using it
198  bool openDeferredAttach(yarp::os::Property& prop);
199 
200  // If a subdevice parameter is given to the wrapper, it will open it as well
201  // and attach to it immediately.
202  bool openAndAttachSubDevice(yarp::os::Property& prop);
203 };
204 
205 
206 #endif // YARP_DEV_SERVERINERTIAL_SERVERINERTIAL_H
bool attach(yarp::dev::PolyDriver *poly) override
IWrapper interface Attach to another object.
bool close() override
Close the DeviceDriver.
ServerInertial & operator=(const ServerInertial &)=delete
bool open(yarp::os::Searchable &config) override
Open the device driver.
bool detach() override
Detach the object (you must have first called attach).
ServerInertial & operator=(ServerInertial &&)=delete
ServerInertial(ServerInertial &&)=delete
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
ServerInertial(const ServerInertial &)=delete
bool attachAll(const yarp::dev::PolyDriverList &p) override
IMultipleWrapper interface Attach to a list of objects.
ServerInertial()
Constructor.
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).
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
A generic interface to sensors – gyro, a/d converters etc.
Interface for an object that can wrap/attach to to another.
Interface for an object that can wrap/or "attach" to another.
Definition: IWrapper.h:29
A container for a device driver.
Definition: PolyDriver.h:27
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
An interface for reading from a network connection.
The Node class.
Definition: Node.h:27
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:28
A mini-server for network communication.
Definition: Port.h:50
A class for storing options and configuration information.
Definition: Property.h:37
A base class for nested structures that can be searched.
Definition: Searchable.h:69
An abstraction for a thread of execution.
Definition: Thread.h:25
std::uint32_t NetUint32
Definition of the NetUint32 type.
Definition: NetUint32.h:33
ROSTopicUsageType
Definition: yarpRosHelper.h:19