31void ControlBoard_nws_yarp::closePorts()
38 inputStreamingPort.
close();
41 outputPositionStatePort.
close();
44 extendedOutputStatePort.
close();
82 inputRPC_buffer.
attach(inputRPCPort);
83 RPC_parser.
attach(inputRPC_buffer);
93 if (!outputPositionStatePort.
open(
rootName +
"/state:o")) {
100 if (!extendedOutputStatePort.
open(
rootName +
"/stateExt:o")) {
105 extendedOutputState_buffer.
attach(extendedOutputStatePort);
109 if (subdevice_ready) {
127 yCWarning(
CONTROLBOARD,
"Part <%s>: iJointFault interface was not found in subdevice.", partName.c_str());
132 yCWarning(
CONTROLBOARD,
"Part <%s>: IPidControl interface was not found in subdevice.", partName.c_str());
136 if (!iPositionControl) {
137 yCWarning(
CONTROLBOARD,
"Part <%s>: IPositionControl interface was not found in subdevice.", partName.c_str());
141 if (!iPositionDirect) {
142 yCWarning(
CONTROLBOARD,
"Part <%s>: IPositionDirect interface was not found in subdevice.", partName.c_str());
146 if (!iVelocityControl) {
147 yCWarning(
CONTROLBOARD,
"Part <%s>: IVelocityControl interface was not found in subdevice.", partName.c_str());
151 if (!iEncodersTimed) {
152 yCWarning(
CONTROLBOARD,
"Part <%s>: IEncodersTimed interface was not found in subdevice.", partName.c_str());
157 yCWarning(
CONTROLBOARD,
"Part <%s>: IMotor interface was not found in subdevice.", partName.c_str());
161 if (!iMotorEncoders) {
162 yCWarning(
CONTROLBOARD,
"Part <%s>: IMotorEncoders interface was not found in subdevice.", partName.c_str());
166 if (!iAmplifierControl) {
167 yCWarning(
CONTROLBOARD,
"Part <%s>: IAmplifierControl interface was not found in subdevice.", partName.c_str());
171 if (!iControlLimits) {
172 yCWarning(
CONTROLBOARD,
"Part <%s>: IControlLimits interface was not found in subdevice.", partName.c_str());
176 if (!iControlCalibration) {
177 yCWarning(
CONTROLBOARD,
"Part <%s>: IControlCalibration interface was not found in subdevice.", partName.c_str());
181 if (!iTorqueControl) {
182 yCWarning(
CONTROLBOARD,
"Part <%s>: ITorqueControl interface was not found in subdevice.", partName.c_str());
186 if (!iImpedanceControl) {
187 yCWarning(
CONTROLBOARD,
"Part <%s>: IImpedanceControl interface was not found in subdevice.", partName.c_str());
192 yCWarning(
CONTROLBOARD,
"Part <%s>: IControlMode interface was not found in subdevice.", partName.c_str());
197 yCWarning(
CONTROLBOARD,
"Part <%s>: IAxisInfo interface was not found in subdevice.", partName.c_str());
201 if (!iPreciselyTimed) {
202 yCWarning(
CONTROLBOARD,
"Part <%s>: IPreciselyTimed interface was not found in subdevice.", partName.c_str());
206 if (!iInteractionMode) {
207 yCWarning(
CONTROLBOARD,
"Part <%s>: IInteractionMode interface was not found in subdevice.", partName.c_str());
211 if (!iRemoteVariables) {
212 yCWarning(
CONTROLBOARD,
"Part <%s>: IRemoteVariables interface was not found in subdevice.", partName.c_str());
217 yCWarning(
CONTROLBOARD,
"Part <%s>: IPWMControl interface was not found in subdevice.", partName.c_str());
221 if (!iCurrentControl) {
222 yCWarning(
CONTROLBOARD,
"Part <%s>: ICurrentControl interface was not found in subdevice.", partName.c_str());
227 yCWarning(
CONTROLBOARD,
"Part <%s>: iJointBrake interface was not found in subdevice.", partName.c_str());
231 if (!iVelocityDirect) {
232 yCWarning(
CONTROLBOARD,
"Part <%s>: iVelocityDirect interface was not found in subdevice.", partName.c_str());
240 yCError(
CONTROLBOARD) <<
"Part <%s>: iAxisInfo->getAxes() failed for subdevice " << partName.c_str();
244 else if (iEncodersTimed)
247 yCError(
CONTROLBOARD) <<
"Part <%s>: iEncodersTimed->getAxes() failed for subdevice " << partName.c_str();
251 else if (iPositionControl)
254 yCError(
CONTROLBOARD) <<
"Part <%s>: iPositionControl->getAxes() failed for subdevice " << partName.c_str();
258 else if (iVelocityControl)
261 yCError(
CONTROLBOARD) <<
"Part <%s>: iVelocityControl->getAxes() failed for subdevice " << partName.c_str();
270 subdevice_joints =
static_cast<size_t>(
tmp_axes);
271 times.
resize(subdevice_joints);
283void ControlBoard_nws_yarp::closeDevice()
286 streaming_parser.
reset();
289 subdevice_joints = 0;
290 subdevice_ready =
false;
295 iPidControl =
nullptr;
296 iPositionControl =
nullptr;
297 iPositionDirect =
nullptr;
298 iVelocityControl =
nullptr;
299 iEncodersTimed =
nullptr;
301 iMotorEncoders =
nullptr;
302 iAmplifierControl =
nullptr;
303 iControlLimits =
nullptr;
304 iControlCalibration =
nullptr;
305 iTorqueControl =
nullptr;
306 iImpedanceControl =
nullptr;
307 iControlMode =
nullptr;
309 iPreciselyTimed =
nullptr;
310 iInteractionMode =
nullptr;
311 iRemoteVariables =
nullptr;
312 iPWMControl =
nullptr;
313 iCurrentControl =
nullptr;
314 iJointFault =
nullptr;
315 iVelocityDirect =
nullptr;
321 if (subdevice_ready) {
325 if (!setDevice(poly,
false)) {
335 m_RPC = std::make_unique<ControlBoardRPCd>(iJointBrake, iVelocityDirect);
376 tmpVariableForFloatSignals.
resize(subdevice_joints);
379 if (iEncodersTimed) {
389 if (iMotorEncoders) {
411 if (iTorqueControl) {
429 if (iCurrentControl) {
431 }
else if (iAmplifierControl) {
443 if (iInteractionMode) {
450 for (
double tt : times)
452 if (std::abs(times[0] -
tt) > 1.0)
460 time.
update(std::accumulate(times.
begin(), times.
end(), 0.0) / subdevice_joints);
465 extendedOutputState_buffer.
write();
469 v.
resize(subdevice_joints);
473 outputPositionStatePort.
write();
485 std::lock_guard<std::mutex> lock(m_mutex);
486 bool b = m_RPC->read(connection);
const yarp::os::LogComponent & CONTROLBOARD()
const double DEFAULT_PERIOD
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
void run() override
Loop function.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool open(yarp::os::Searchable &prop) override
Open the DeviceDriver.
bool close() override
Close the DeviceDriver.
bool attach(yarp::dev::PolyDriver *poly) override
Attach to another object.
bool detach() override
Detach the object (you must have first called attach).
void init(yarp::dev::DeviceDriver *x)
Initialization.
virtual bool initialize()
Initialize the internal data.
void init(yarp::dev::DeviceDriver *x)
Initialization.
Interface implemented by all device drivers.
void attach(yarp::os::TypedReader< yarp::os::Bottle > &source)
Attach this object to a source of messages.
virtual bool getCurrents(double *vals)=0
virtual bool getAxes(int *ax)=0
Get the number of controlled axes.
virtual bool getControlModes(int *modes)=0
Get the current control mode (multiple joints).
virtual bool getCurrents(double *currs)=0
Get the instantaneous current measurement for all motors.
virtual bool getEncodersTimed(double *encs, double *time)=0
Read the instantaneous acceleration of all axes.
virtual bool getEncoderAccelerations(double *accs)=0
Read the instantaneous acceleration of all axes.
virtual bool getAxes(int *ax)=0
Get the number of controlled axes.
virtual bool getEncoderSpeeds(double *spds)=0
Read the instantaneous speed of all axes.
virtual bool getInteractionModes(int n_joints, int *joints, yarp::dev::InteractionModeEnum *modes)=0
Get the current interaction mode of the robot for a set of joints, values can be stiff or compliant.
virtual bool getMotorEncoderSpeeds(double *spds)=0
Read the instantaneous speed of all motor encoders.
virtual bool getMotorEncoderAccelerations(double *accs)=0
Read the instantaneous acceleration of all motor encoders.
virtual bool getMotorEncoders(double *encs)=0
Read the position of all motor encoders.
virtual bool getTemperatures(double *vals)=0
Get temperature of all the motors.
virtual bool getDutyCycles(double *vals)=0
Gets the current dutycycle of the output of the amplifier (i.e.
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).
virtual bool getAxes(int *axes)=0
Get the number of controlled axes.
A container for a device driver.
yarp::sig::VectorOf< float > pwmDutycycle
yarp::sig::VectorOf< double > motorVelocity
yarp::sig::VectorOf< double > jointAcceleration
yarp::sig::VectorOf< int > controlMode
bool pwmDutycycle_isValid
yarp::sig::VectorOf< int > interactionMode
yarp::sig::VectorOf< double > current
bool jointVelocity_isValid
yarp::sig::VectorOf< double > motorAcceleration
bool motorVelocity_isValid
yarp::sig::VectorOf< double > motorPosition
bool jointAcceleration_isValid
yarp::sig::VectorOf< double > torque
bool motorAcceleration_isValid
yarp::sig::VectorOf< float > temperature
bool interactionMode_isValid
yarp::sig::VectorOf< double > jointPosition
bool motorPosition_isValid
bool jointPosition_isValid
yarp::sig::VectorOf< double > jointVelocity
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
bool setEnvelope(PortWriter &envelope) override
Set an envelope (e.g., a timestamp) to the next message which will be sent.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
int getPendingReads() override
Get the number of objects ready to be read.
void interrupt() override
Interrupt any current reads or writes attached to the port.
void useCallback(TypedReaderCallback< T > &callback) override
Set an object whose onRead method will be called when data is available.
void setStrict(bool strict=true) override
Call this to strictly keep all messages, or allow old ones to be quietly dropped.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.
An interface for reading from a network connection.
virtual bool isValid() const =0
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...
void attach(Port &port)
Attach this buffer to a particular port.
T & get()
A synonym of PortWriterBuffer::prepare.
void write(bool forceStrict=false)
Try to write the last buffer returned by PortWriterBuffer::get.
void attach(Port &port)
Set the Port to which objects will be written.
void enableBackgroundWrite(bool backgroundFlag)
control whether writing from this port is done in the background.
void setReader(PortReader &reader) override
Set an external reader for port data.
bool removeCallbackLock() override
Remove a lock on callbacks added with setCallbackLock()
void interrupt() override
Interrupt any current reads or writes attached to the port.
bool setEnvelope(PortWriter &envelope) override
Set an envelope (e.g., a timestamp) to the next message which will be sent.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
A base class for nested structures that can be searched.
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...
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 yCError(component,...)
#define yCWarning(component,...)
#define yCIErrorThrottle(component, id, period,...)
#define yCDebug(component,...)
#define yCIWarning(component, id,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.
The main, catch-all namespace for YARP.