31void ControlBoard_nws_ros::closePorts()
34 publisherPort.
close();
60 if (prop.
check(
"period")) {
72 period = default_period;
77 if (prop.
check(
"subdevice")) {
78 prop.setMonitor(config.getMonitor());
79 if (!openAndAttachSubDevice(prop)) {
83 subdevice_ready =
true;
87 if (!config.
check(
"node_name")) {
92 if(nodeName[0] !=
'/'){
98 if (!config.
check(
"topic_name")) {
103 if(topicName[0] !=
'/'){
110 if (!publisherPort.
topic(topicName)) {
117 if (subdevice_ready) {
132bool ControlBoard_nws_ros::openAndAttachSubDevice(
Property& prop)
138 std::string subdevice = prop.
find(
"subdevice").
asString();
139 p.setMonitor(prop.getMonitor(), subdevice.c_str());
141 p.
put(
"device", subdevice);
145 subDeviceOwned->open(p);
147 if (!subDeviceOwned->isValid()) {
152 return setDevice(subDeviceOwned,
true);
161 subdevice_ptr = driver;
162 subdevice_owned = owned;
164 subdevice_ptr->
view(iPositionControl);
165 if (!iPositionControl) {
166 yCError(
CONTROLBOARD,
"<%s - %s>: IPositionControl interface was not found in subdevice. Quitting", nodeName.c_str(), topicName.c_str());
170 subdevice_ptr->
view(iEncodersTimed);
171 if (!iEncodersTimed) {
172 yCError(
CONTROLBOARD,
"<%s - %s>: IEncodersTimed interface was not found in subdevice. Quitting", nodeName.c_str(), topicName.c_str());
176 subdevice_ptr->
view(iTorqueControl);
177 if (!iTorqueControl) {
178 yCWarning(
CONTROLBOARD,
"<%s - %s>: ITorqueControl interface was not found in subdevice.", nodeName.c_str(), topicName.c_str());
181 subdevice_ptr->
view(iAxisInfo);
183 yCError(
CONTROLBOARD,
"<%s - %s>: IAxisInfo interface was not found in subdevice. Quitting", nodeName.c_str(), topicName.c_str());
189 if (!iPositionControl->
getAxes(&tmp_axes)) {
190 yCError(
CONTROLBOARD,
"<%s - %s>: Failed to get axes number for subdevice ", nodeName.c_str(), topicName.c_str());
194 yCError(
CONTROLBOARD,
"<%s - %s>: attached device has an invalid number of joints (%d)", nodeName.c_str(), topicName.c_str(), tmp_axes);
197 subdevice_joints =
static_cast<size_t>(tmp_axes);
198 times.
resize(subdevice_joints);
199 ros_struct.
name.resize(subdevice_joints);
200 ros_struct.
position.resize(subdevice_joints);
201 ros_struct.
velocity.resize(subdevice_joints);
202 ros_struct.
effort.resize(subdevice_joints);
204 if (!updateAxisName()) {
212void ControlBoard_nws_ros::closeDevice()
215 if (subdevice_owned) {
217 subdevice_ptr->
close();
218 delete subdevice_ptr;
220 subdevice_ptr =
nullptr;
221 subdevice_owned =
false;
222 subdevice_joints = 0;
223 subdevice_ready =
false;
228 iPositionControl =
nullptr;
229 iEncodersTimed =
nullptr;
230 iTorqueControl =
nullptr;
237 if (subdevice_ready) {
241 if (!setDevice(poly,
false)) {
257 if (subdevice_owned) {
272bool ControlBoard_nws_ros::updateAxisName()
279 std::vector<std::string> tmpVect;
280 for (
size_t i = 0; i < subdevice_joints; i++) {
287 tmpVect.emplace_back(tmp);
292 jointNames = tmpVect;
309 if (iTorqueControl) {
315 double tt = *times.
data();
316 for (
auto it = times.
begin(); it != times.
end(); it++)
318 if (fabs(tt - *it) > 1.0)
320 yCError(
CONTROLBOARD,
"Encoder Timestamps are not consistent! Data will not be published.");
326 time.
update(std::accumulate(times.
begin(), times.
end(), 0.0) / subdevice_joints);
331 for (
size_t i = 0; i < subdevice_joints; i++) {
339 ros_struct.
name = jointNames;
344 publisherPort.
write(ros_struct);
const yarp::os::LogComponent & CONTROLBOARD()
constexpr double default_period
bool attach(yarp::dev::PolyDriver *poly) override
Attach to another object.
void run() override
Loop function.
bool close() override
Close the DeviceDriver.
bool open(yarp::os::Searchable &prop) override
Open the DeviceDriver.
bool detach() override
Detach the object (you must have first called attach).
Interface implemented by all device drivers.
bool view(T *&x)
Get an interface to the device driver.
bool close() override
Close the DeviceDriver.
virtual bool getAxisName(int axis, std::string &name)=0
virtual bool getJointType(int axis, yarp::dev::JointTypeEnum &type)
virtual bool getEncodersTimed(double *encs, double *time)=0
Read the instantaneous acceleration of all axes.
virtual bool getEncoderSpeeds(double *spds)=0
Read the instantaneous speed of all axes.
virtual bool getAxes(int *ax)=0
Get the number of controlled axes.
virtual bool getTorques(double *t)=0
Get the value of the torque for all joints (this is the feedback if you have torque sensors).
A container for a device driver.
An abstraction for a periodic thread.
bool setPeriod(double period)
Set the (new) period of the thread.
bool isRunning() const
Returns true when the thread is started, false otherwise.
bool start()
Call this to start the thread.
void stop()
Call this to stop the thread, this call blocks until the thread is terminated (and releaseThread() ca...
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.
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
void close() override
Stop port activity.
bool topic(const std::string &name)
Set topic to publish to.
void interrupt() override
Interrupt any current reads or writes attached to the port.
void write(bool forceStrict=false)
Write the current object being returned by Publisher::prepare.
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.
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...
double getTime() const
Get the time stamp.
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual bool isFloat64() const
Checks if value is a 64-bit floating point number.
virtual std::string asString() const
Get string value.
std::vector< std::string > name
std::vector< yarp::conf::float64_t > position
std::vector< yarp::conf::float64_t > velocity
std::vector< yarp::conf::float64_t > effort
yarp::rosmsg::std_msgs::Header header
void resize(size_t size) override
Resize the vector.
iterator begin() noexcept
Returns an iterator to the beginning of the VectorOf.
T * data()
Return a pointer to the first element of the vector.
iterator end() noexcept
Returns an iterator to the end of the VectorOf.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCAssert(component, x)
#define yCWarning(component,...)
#define yCDebug(component,...)
For streams capable of holding different kinds of content, check what they actually have.
@ VOCAB_JOINTTYPE_REVOLUTE
An interface to the operating system, including Port based communication.
The main, catch-all namespace for YARP.
double convertDegreesToRadians(double degrees)
convert degrees to radiants for ROS messages