Visual Servoing Platform  version 3.4.0
vpQbDevice Class Reference

#include <vpQbDevice.h>

+ Inheritance diagram for vpQbDevice:

Public Member Functions

 vpQbDevice ()
 
virtual ~vpQbDevice ()
 
Inherited public functionalities from vpQbDevice
double getCurrentMax () const
 
std::vector< short int > getPositionLimits () const
 
void setMaxRepeats (const int &max_repeats)
 

Protected Member Functions

Inherited protected functionalities from vpQbDevice
virtual int activate (const int &id, const bool &command, const int &max_repeats)
 
virtual int activate (const int &id, const int &max_repeats)
 
virtual bool close (const std::string &serial_port)
 
virtual int deactivate (const int &id, const int &max_repeats)
 
virtual int getCurrents (const int &id, const int &max_repeats, std::vector< short int > &currents)
 
virtual int getInfo (const int &id, const int &max_repeats, std::string &info)
 
virtual int getMeasurements (const int &id, const int &max_repeats, std::vector< short int > &currents, std::vector< short int > &positions)
 
virtual int getParameters (const int &id, std::vector< int > &limits, std::vector< int > &resolutions)
 
virtual int getPositions (const int &id, const int &max_repeats, std::vector< short int > &positions)
 
virtual int getSerialPortsAndDevices (const int &max_repeats)
 
virtual bool init (const int &id)
 
virtual int isActive (const int &id, const int &max_repeats, bool &status)
 
int isConnected (const int &id, const int &max_repeats)
 
virtual bool isInConnectedSet (const int &id)
 
virtual bool isInOpenMap (const std::string &serial_port)
 
bool isReliable (int const &failures, int const &max_repeats)
 
virtual int open (const std::string &serial_port)
 
virtual int setCommandsAndWait (const int &id, const int &max_repeats, std::vector< short int > &commands)
 
virtual int setCommandsAsync (const int &id, std::vector< short int > &commands)
 

Protected Attributes

int m_max_repeats
 
bool m_init_done
 

Detailed Description

Interface for qbrobotics devices.

See https://qbrobotics.com/ for more details.

This class was tested with the qbSoftHand.

Definition at line 63 of file vpQbDevice.h.

Constructor & Destructor Documentation

vpQbDevice::vpQbDevice ( )

Default constructor that does nothing. To connect to a device call init().

Definition at line 476 of file vpQbDevice.cpp.

References setMaxRepeats().

vpQbDevice::~vpQbDevice ( )
virtual

Close all the still open serial ports.

See also
close()

Definition at line 486 of file vpQbDevice.cpp.

Member Function Documentation

int vpQbDevice::activate ( const int &  id,
const bool &  command,
const int &  max_repeats 
)
protectedvirtual

Activate (or deactivate, according to the given command) the motors of the given device. Do nothing if the device is not connected in the Communication Handler.

Parameters
idThe ID of the device to be activated (or deactivated), in range [1, 128].
commandtrue to turn motors on, false to turn them off.
max_repeatsThe maximum number of consecutive repetitions to mark retrieved data as corrupted.
See also
activate(const int &, const int &), deactivate(), isActive()

Definition at line 499 of file vpQbDevice.cpp.

int vpQbDevice::activate ( const int &  id,
const int &  max_repeats 
)
protectedvirtual

Activate the motors of the given device. Do nothing if the device is not connected in the Communication Handler.

Parameters
idThe ID of the device to be activated, in range [1, 128].
max_repeatsThe maximum number of consecutive repetitions to mark retrieved data as corrupted.
See also
isActive()

Definition at line 510 of file vpQbDevice.cpp.

bool vpQbDevice::close ( const std::string &  serial_port)
protectedvirtual

Close the communication with all the devices connected to the given serial port.

Parameters
serial_portThe serial port which has to be closed, e.g. /dev/ttyUSB* (Unix), /dev/tty.usbserial-* (MacOS) or COM* (Windows).
See also
isInOpenMap(), open()

Definition at line 521 of file vpQbDevice.cpp.

int vpQbDevice::deactivate ( const int &  id,
const int &  max_repeats 
)
protectedvirtual

Deactivate the motors of the given device. Do nothing if the device is not connected in the Communication Handler.

Parameters
idThe ID of the device to be deactivated, in range [1, 128].
max_repeatsThe maximum number of consecutive repetitions to mark retrieved data as corrupted.
See also
activate(const int &, const bool &, const int &), isActive()

Definition at line 532 of file vpQbDevice.cpp.

double vpQbDevice::getCurrentMax ( ) const

Return the maximum current supported by the device.

Examples:
testQbSoftHand.cpp.

Definition at line 540 of file vpQbDevice.cpp.

Referenced by vpQbSoftHand::setPosition().

int vpQbDevice::getCurrents ( const int &  id,
const int &  max_repeats,
std::vector< short int > &  currents 
)
protectedvirtual

Retrieve the motor currents of the given device.

Parameters
idThe ID of the device of interest, in range [1, 128].
max_repeatsThe maximum number of consecutive repetitions to mark retrieved data as corrupted.
[out]currentsThe two-element device motor current vector, expressed in mA: if the device is a qbhand only the first element is filled while the other remains always 0; in the case of a qbmove both the elements contain relevant data, i.e. the currents respectively of motor_1 and motor_2.
Returns
0 on success.
See also
getMeasurements(), getPositions()

Definition at line 555 of file vpQbDevice.cpp.

Referenced by vpQbSoftHand::getCurrent().

int vpQbDevice::getInfo ( const int &  id,
const int &  max_repeats,
std::string &  info 
)
protectedvirtual

Retrieve the printable configuration setup of the given device.

Parameters
idThe ID of the device of interest, in range [1, 128].
max_repeatsThe maximum number of consecutive repetitions to mark retrieved data as corrupted.
infoThe configuration setup formatted as a plain text string (empty string on communication error).
Returns
The number of failure reads between 0 and max_repeats.
See also
getParameters()

Definition at line 568 of file vpQbDevice.cpp.

int vpQbDevice::getMeasurements ( const int &  id,
const int &  max_repeats,
std::vector< short int > &  currents,
std::vector< short int > &  positions 
)
protectedvirtual

Retrieve the motor currents of the given device.

Parameters
idThe ID of the device of interest, in range [1, 128].
[out]currentsThe two-element device motor current vector, expressed in mA: if the device is a qbhand only the first element is filled while the other remains always 0; in the case of a qbmove both the elements contain relevant data, i.e. the currents respectively of motor_1 and motor_2.
[out]positionsThe device position vector, expressed in ticks: if the device is a qbhand only the first element is filled while the others remain always 0; in the case of a qbmove all the elements contain relevant data, i.e. the positions respectively of motor_1, motor_2 and motor_shaft (which is not directly actuated).
max_repeatsThe maximum number of consecutive repetitions to mark retrieved data as corrupted.
Returns
The number of failure reads between 0 and max_repeats.
See also
getCurrents(), getPositions()

Definition at line 587 of file vpQbDevice.cpp.

int vpQbDevice::getParameters ( const int &  id,
std::vector< int > &  limits,
std::vector< int > &  resolutions 
)
protectedvirtual

Retrieve some of the parameters from the given device.

Parameters
idThe ID of the device of interest, in range [1, 128].
[out]limitsThe vector of motor position limits expressed in ticks: two values for each motor, respectively [lower_limit, upper_limit].
[out]resolutionsThe vector of encoder resolutions, each in range [0, 8]: one value for each encoder (note: the qbmove has also the shaft encoder even if it is not actuated). The word "resolution" could be misunderstood: taken the resolution r, $2^r$ is the number of turns of the wire inside the device mechanics. It is used essentially to convert the measured position of the motors in ticks to radians or degrees.
Returns
0 on success.
See also
getInfo(), init()

Definition at line 604 of file vpQbDevice.cpp.

std::vector< short int > vpQbDevice::getPositionLimits ( ) const
Returns
Position limits as a 2-dim vector with min and max values.

Definition at line 612 of file vpQbDevice.cpp.

Referenced by vpQbSoftHand::getPosition(), and vpQbSoftHand::setPosition().

int vpQbDevice::getPositions ( const int &  id,
const int &  max_repeats,
std::vector< short int > &  positions 
)
protectedvirtual

Retrieve the motor positions of the given device.

Parameters
idThe ID of the device of interest, in range [1, 128].
[out]positionsThe device position vector, expressed in ticks: if the device is a qbhand only the first element is filled while the others remain always 0; in the case of a qbmove all the elements contain relevant data, i.e. the positions respectively of motor_1, motor_2 and motor_shaft (which is not directly actuated).
max_repeatsThe maximum number of consecutive repetitions to mark retrieved data as corrupted.
Returns
The number of failure reads between 0 and max_repeats.
See also
getMeasurements()

Definition at line 628 of file vpQbDevice.cpp.

Referenced by vpQbSoftHand::getPosition().

int vpQbDevice::getSerialPortsAndDevices ( const int &  max_repeats)
protectedvirtual

Scan for all the serial ports of type /dev/ttyUSB* detected in the system, initialize their mutex protector (each serial port connected to the system has to be accessed in a mutually exclusive fashion), and retrieve all the qbrobotics devices connected to them. For each device, store its ID in the private map m_connected_devices, i.e. insert a pair [device_id, serial_port]. The map m_connected_devices is constructed from scratch at each call.

Parameters
max_repeatsThe maximum number of consecutive repetitions to mark retrieved data as corrupted.
Returns
the number of connected devices.
See also
isInConnectedSet(), open()

Definition at line 643 of file vpQbDevice.cpp.

bool vpQbDevice::init ( const int &  id)
protectedvirtual

Initialize the device if the relative physical device is connected through any serial port to the system. If the device is found, retrieve some of its parameter and activate its motors, if requested.

Parameters
idThe ID of the device of interest, in range [1, 128].
Returns
true if the call succeed.
See also
getSerialPortsAndDevices()

Definition at line 655 of file vpQbDevice.cpp.

References m_init_done.

Referenced by vpQbSoftHand::getCurrent(), vpQbSoftHand::getPosition(), and vpQbSoftHand::setPosition().

int vpQbDevice::isActive ( const int &  id,
const int &  max_repeats,
bool &  status 
)
protectedvirtual

Check whether the motors of the device specified by the given ID are active.

Parameters
idThe ID of the device of interest, in range [1, 128].
max_repeatsThe maximum number of consecutive repetitions to mark retrieved data as corrupted.
statustrue if the device motors are on.
Returns
The number of failure reads between 0 and max_repeats.

Definition at line 672 of file vpQbDevice.cpp.

int vpQbDevice::isConnected ( const int &  id,
const int &  max_repeats 
)
protected

Check whether the the device specified by the given ID is connected through the serial port.

Parameters
idThe ID of the device of interest, in range [1, 128].
max_repeatsThe maximum number of consecutive repetitions to mark retrieved data as corrupted.
Returns
The number of failure reads between 0 and max_repeats.

Definition at line 683 of file vpQbDevice.cpp.

bool vpQbDevice::isInConnectedSet ( const int &  id)
protectedvirtual

Check whether the physical device specified by the given ID is connected to the Communication Handler.

Parameters
idThe ID of the device of interest, in range [1, 128].
Returns
true if the given device belongs to the connected device vector, i.e. m_connected_devices.
See also
getSerialPortsAndDevices()

Definition at line 694 of file vpQbDevice.cpp.

Referenced by vpQbSoftHand::getCurrent(), vpQbSoftHand::getPosition(), and vpQbSoftHand::setPosition().

bool vpQbDevice::isInOpenMap ( const std::string &  serial_port)
protectedvirtual

Check whether the given serial port is managed by the communication handler, i.e. is open.

Parameters
serial_portThe name of the serial port of interest, e.g. /dev/ttyUSB0.
Returns
true if the given serial port belongs to the open file descriptor map, i.e. m_file_descriptors.
See also
open(), close()

Definition at line 705 of file vpQbDevice.cpp.

bool vpQbDevice::isReliable ( int const &  failures,
int const &  max_repeats 
)
protected

Check whether the reading failures are in the given range.

Parameters
failuresThe current number of communication failures per serial resource reading.
max_repeatsThe maximum number of consecutive repetitions to mark retrieved data as corrupted.
Returns
true if the failures are less than the given threshold.

Definition at line 716 of file vpQbDevice.cpp.

Referenced by vpQbSoftHand::getCurrent(), vpQbSoftHand::getPosition(), and vpQbSoftHand::setPosition().

int vpQbDevice::open ( const std::string &  serial_port)
protectedvirtual

Open the serial communication on the given serial port. On success, store the opened file descriptor in the private map m_file_descriptors, i.e. insert a pair [serial_port, file_descriptor].

Parameters
serial_portThe serial port which has to be opened, e.g. /dev/ttyUSB0.
Returns
0 on success.
See also
close(), isInOpenMap()

Definition at line 728 of file vpQbDevice.cpp.

int vpQbDevice::setCommandsAndWait ( const int &  id,
const int &  max_repeats,
std::vector< short int > &  commands 
)
protectedvirtual

Send the reference command to the motors of the given device and wait for acknowledge.

Parameters
idThe ID of the device of interest, in range [1, 128].
max_repeatsThe maximum number of consecutive repetitions to mark retrieved data as corrupted.
commandsThe reference command vector, expressed in ticks: if the device is a qbhand only the first element is meaningful while the other remains always 0; in the case of a qbmove both the elements contain relevant data, i.e. the commands respectively of motor_1 and motor_2.
Returns
0 on success.

Definition at line 742 of file vpQbDevice.cpp.

int vpQbDevice::setCommandsAsync ( const int &  id,
std::vector< short int > &  commands 
)
protectedvirtual

Send the reference command to the motors of the given device in a non-blocking fashion.

Parameters
idThe ID of the device of interest, in range [1, 128].
commandsThe reference command vector, expressed in ticks: if the device is a qbhand only the first element is meaningful while the other remains always 0; in the case of a qbmove both the elements contain relevant data, i.e. the commands respectively of motor_1 and motor_2.
Returns
Always 0 (note that this is a non reliable method).

Definition at line 755 of file vpQbDevice.cpp.

Referenced by vpQbSoftHand::setPosition().

void vpQbDevice::setMaxRepeats ( const int &  max_repeats)

Set the maximum number of consecutive repetitions to mark retrieved data as corrupted. This value is set by default to 1.

Definition at line 763 of file vpQbDevice.cpp.

References m_max_repeats.

Referenced by vpQbDevice().

Member Data Documentation

bool vpQbDevice::m_init_done
protected

Flag used to indicate if the device is initialized.

Definition at line 115 of file vpQbDevice.h.

Referenced by vpQbSoftHand::getCurrent(), vpQbSoftHand::getPosition(), init(), and vpQbSoftHand::setPosition().

int vpQbDevice::m_max_repeats
protected

Max number of trials to send a command.

Definition at line 114 of file vpQbDevice.h.

Referenced by vpQbSoftHand::getCurrent(), vpQbSoftHand::getPosition(), setMaxRepeats(), and vpQbSoftHand::setPosition().