32void ControlBoard_nws_ros::closePorts()
35 publisherPort.
close();
61 if (prop.
check(
"period")) {
73 period = default_period;
78 if (prop.
check(
"subdevice")) {
79 prop.setMonitor(config.getMonitor());
80 if (!openAndAttachSubDevice(prop)) {
84 subdevice_ready =
true;
88 if (!config.
check(
"node_name")) {
93 if(nodeName[0] !=
'/'){
99 if (!config.
check(
"topic_name")) {
104 if(topicName[0] !=
'/'){
111 if (!publisherPort.
topic(topicName)) {
118 if (subdevice_ready) {
133bool ControlBoard_nws_ros::openAndAttachSubDevice(
Property& prop)
139 std::string subdevice = prop.
find(
"subdevice").
asString();
140 p.setMonitor(prop.getMonitor(), subdevice.c_str());
142 p.
put(
"device", subdevice);
146 subDeviceOwned->open(p);
148 if (!subDeviceOwned->isValid()) {
153 return setDevice(subDeviceOwned,
true);
162 subdevice_ptr = driver;
163 subdevice_owned = owned;
165 subdevice_ptr->
view(iPositionControl);
166 if (!iPositionControl) {
167 yCError(
CONTROLBOARD,
"<%s - %s>: IPositionControl interface was not found in subdevice. Quitting", nodeName.c_str(), topicName.c_str());
171 subdevice_ptr->
view(iEncodersTimed);
172 if (!iEncodersTimed) {
173 yCError(
CONTROLBOARD,
"<%s - %s>: IEncodersTimed interface was not found in subdevice. Quitting", nodeName.c_str(), topicName.c_str());
177 subdevice_ptr->
view(iTorqueControl);
178 if (!iTorqueControl) {
179 yCWarning(
CONTROLBOARD,
"<%s - %s>: ITorqueControl interface was not found in subdevice.", nodeName.c_str(), topicName.c_str());
182 subdevice_ptr->
view(iAxisInfo);
184 yCError(
CONTROLBOARD,
"<%s - %s>: IAxisInfo interface was not found in subdevice. Quitting", nodeName.c_str(), topicName.c_str());
190 if (!iPositionControl->
getAxes(&tmp_axes)) {
191 yCError(
CONTROLBOARD,
"<%s - %s>: Failed to get axes number for subdevice ", nodeName.c_str(), topicName.c_str());
195 yCError(
CONTROLBOARD,
"<%s - %s>: attached device has an invalid number of joints (%d)", nodeName.c_str(), topicName.c_str(), tmp_axes);
198 subdevice_joints =
static_cast<size_t>(tmp_axes);
199 times.
resize(subdevice_joints);
200 ros_struct.
name.resize(subdevice_joints);
201 ros_struct.
position.resize(subdevice_joints);
202 ros_struct.
velocity.resize(subdevice_joints);
203 ros_struct.
effort.resize(subdevice_joints);
205 if (!updateAxisName()) {
213void ControlBoard_nws_ros::closeDevice()
216 if (subdevice_owned) {
218 subdevice_ptr->
close();
219 delete subdevice_ptr;
221 subdevice_ptr =
nullptr;
222 subdevice_owned =
false;
223 subdevice_joints = 0;
224 subdevice_ready =
false;
229 iPositionControl =
nullptr;
230 iEncodersTimed =
nullptr;
231 iTorqueControl =
nullptr;
238 if (subdevice_ready) {
242 if (!setDevice(poly,
false)) {
258 if (subdevice_owned) {
273bool ControlBoard_nws_ros::updateAxisName()
280 std::vector<std::string> tmpVect;
281 for (
size_t i = 0; i < subdevice_joints; i++) {
288 tmpVect.emplace_back(tmp);
293 jointNames = tmpVect;
310 if (iTorqueControl) {
316 time.
update(std::accumulate(times.
begin(), times.
end(), 0.0) / subdevice_joints);
321 for (
size_t i = 0; i < subdevice_joints; i++) {
329 ros_struct.
name = jointNames;
334 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,...)
#define YARP_LOG_COMPONENT(name,...)
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