30 void ControlBoard_nws_ros::closePorts()
33 publisherPort.
close();
59 if (prop.
check(
"period")) {
71 period = default_period;
76 if (prop.
check(
"subdevice")) {
77 prop.setMonitor(config.getMonitor());
78 if (!openAndAttachSubDevice(prop)) {
82 subdevice_ready =
true;
86 if (!config.
check(
"node_name")) {
91 if(nodeName[0] !=
'/'){
97 if (!config.
check(
"topic_name")) {
102 if(topicName[0] !=
'/'){
109 if (!publisherPort.
topic(topicName)) {
116 if (subdevice_ready) {
131 bool ControlBoard_nws_ros::openAndAttachSubDevice(
Property& prop)
137 std::string subdevice = prop.
find(
"subdevice").
asString();
138 p.setMonitor(prop.getMonitor(), subdevice.c_str());
140 p.
put(
"device", subdevice);
144 subDeviceOwned->open(p);
146 if (!subDeviceOwned->isValid()) {
151 return setDevice(subDeviceOwned,
true);
160 subdevice_ptr = driver;
161 subdevice_owned = owned;
163 subdevice_ptr->
view(iPositionControl);
164 if (!iPositionControl) {
165 yCError(
CONTROLBOARD,
"<%s - %s>: IPositionControl interface was not found in subdevice. Quitting", nodeName.c_str(), topicName.c_str());
169 subdevice_ptr->
view(iEncodersTimed);
170 if (!iEncodersTimed) {
171 yCError(
CONTROLBOARD,
"<%s - %s>: IEncodersTimed interface was not found in subdevice. Quitting", nodeName.c_str(), topicName.c_str());
175 subdevice_ptr->
view(iTorqueControl);
176 if (!iTorqueControl) {
177 yCWarning(
CONTROLBOARD,
"<%s - %s>: ITorqueControl interface was not found in subdevice.", nodeName.c_str(), topicName.c_str());
180 subdevice_ptr->
view(iAxisInfo);
182 yCError(
CONTROLBOARD,
"<%s - %s>: IAxisInfo interface was not found in subdevice. Quitting", nodeName.c_str(), topicName.c_str());
188 if (!iPositionControl->
getAxes(&tmp_axes)) {
189 yCError(
CONTROLBOARD,
"<%s - %s>: Failed to get axes number for subdevice ", nodeName.c_str(), topicName.c_str());
193 yCError(
CONTROLBOARD,
"<%s - %s>: attached device has an invalid number of joints (%d)", nodeName.c_str(), topicName.c_str(), tmp_axes);
196 subdevice_joints =
static_cast<size_t>(tmp_axes);
197 times.
resize(subdevice_joints);
198 ros_struct.
name.resize(subdevice_joints);
199 ros_struct.
position.resize(subdevice_joints);
200 ros_struct.
velocity.resize(subdevice_joints);
201 ros_struct.
effort.resize(subdevice_joints);
203 if (!updateAxisName()) {
211 void ControlBoard_nws_ros::closeDevice()
214 if (subdevice_owned) {
216 subdevice_ptr->
close();
217 delete subdevice_ptr;
219 subdevice_ptr =
nullptr;
220 subdevice_owned =
false;
221 subdevice_joints = 0;
222 subdevice_ready =
false;
227 iPositionControl =
nullptr;
228 iEncodersTimed =
nullptr;
229 iTorqueControl =
nullptr;
236 if (subdevice_ready) {
240 if (!setDevice(poly,
false)) {
256 if (subdevice_owned) {
271 bool ControlBoard_nws_ros::updateAxisName()
278 std::vector<std::string> tmpVect;
279 for (
size_t i = 0; i < subdevice_joints; i++) {
286 tmpVect.emplace_back(tmp);
291 jointNames = tmpVect;
308 if (iTorqueControl) {
314 time.
update(std::accumulate(times.
begin(), times.
end(), 0.0) / subdevice_joints);
319 for (
size_t i = 0; i < subdevice_joints; i++) {
327 ros_struct.
name = jointNames;
332 publisherPort.
write(ros_struct);
const yarp::os::LogComponent & CONTROLBOARD()
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 Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
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.
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,...)
An interface for the device drivers.
@ 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