#include <vpQbDevice.h>
|
int | m_max_repeats |
|
bool | m_init_done |
|
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 > ¤ts) |
|
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 > ¤ts, 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) |
|
Interface for qbrobotics devices.
See https://qbrobotics.com/ for more details.
This class was tested with the qbSoftHand.
Definition at line 62 of file vpQbDevice.h.
◆ vpQbDevice()
vpQbDevice::vpQbDevice |
( |
| ) |
|
Default constructor that does nothing. To connect to a device call init().
Definition at line 475 of file vpQbDevice.cpp.
◆ ~vpQbDevice()
vpQbDevice::~vpQbDevice |
( |
| ) |
|
|
virtual |
◆ activate() [1/2]
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
-
id | The ID of the device to be activated (or deactivated), in range [1 , 128 ]. |
command | true to turn motors on, false to turn them off. |
max_repeats | The maximum number of consecutive repetitions to mark retrieved data as corrupted. |
- See also
- activate(const int &, const int &), deactivate(), isActive()
Definition at line 498 of file vpQbDevice.cpp.
◆ activate() [2/2]
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
-
id | The ID of the device to be activated, in range [1 , 128 ]. |
max_repeats | The maximum number of consecutive repetitions to mark retrieved data as corrupted. |
- See also
- isActive()
Definition at line 509 of file vpQbDevice.cpp.
◆ close()
bool vpQbDevice::close |
( |
const std::string & |
serial_port | ) |
|
|
protectedvirtual |
Close the communication with all the devices connected to the given serial port.
- Parameters
-
serial_port | The 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 520 of file vpQbDevice.cpp.
◆ deactivate()
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
-
id | The ID of the device to be deactivated, in range [1 , 128 ]. |
max_repeats | The maximum number of consecutive repetitions to mark retrieved data as corrupted. |
- See also
- activate(const int &, const bool &, const int &), isActive()
Definition at line 531 of file vpQbDevice.cpp.
◆ getCurrentMax()
double vpQbDevice::getCurrentMax |
( |
| ) |
const |
◆ getCurrents()
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
-
| id | The ID of the device of interest, in range [1 , 128 ]. |
| max_repeats | The maximum number of consecutive repetitions to mark retrieved data as corrupted. |
[out] | currents | The 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 554 of file vpQbDevice.cpp.
◆ getInfo()
int vpQbDevice::getInfo |
( |
const int & |
id, |
|
|
const int & |
max_repeats, |
|
|
std::string & |
info |
|
) |
| |
|
protectedvirtual |
Retrieve the printable configuration setup of the given device.
- Parameters
-
id | The ID of the device of interest, in range [1 , 128 ]. |
max_repeats | The maximum number of consecutive repetitions to mark retrieved data as corrupted. |
info | The 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 567 of file vpQbDevice.cpp.
◆ getMeasurements()
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
-
| id | The ID of the device of interest, in range [1 , 128 ]. |
[out] | currents | The 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] | positions | The 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_repeats | The 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 586 of file vpQbDevice.cpp.
◆ getParameters()
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
-
| id | The ID of the device of interest, in range [1 , 128 ]. |
[out] | limits | The vector of motor position limits expressed in ticks: two values for each motor, respectively [lower_limit , upper_limit ]. |
[out] | resolutions | The 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 , 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 603 of file vpQbDevice.cpp.
◆ getPositionLimits()
std::vector< short int > vpQbDevice::getPositionLimits |
( |
| ) |
const |
- Returns
- Position limits as a 2-dim vector with min and max values.
Definition at line 611 of file vpQbDevice.cpp.
◆ getPositions()
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
-
| id | The ID of the device of interest, in range [1 , 128 ]. |
[out] | positions | The 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_repeats | The 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 627 of file vpQbDevice.cpp.
◆ getSerialPortsAndDevices()
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_repeats | The maximum number of consecutive repetitions to mark retrieved data as corrupted. |
- Returns
- the number of connected devices.
- See also
- isInConnectedSet(), open()
Definition at line 642 of file vpQbDevice.cpp.
◆ init()
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
-
id | The ID of the device of interest, in range [1 , 128 ]. |
- Returns
true
if the call succeed.
- See also
- getSerialPortsAndDevices()
Definition at line 654 of file vpQbDevice.cpp.
◆ isActive()
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
-
id | The ID of the device of interest, in range [1 , 128 ]. |
max_repeats | The maximum number of consecutive repetitions to mark retrieved data as corrupted. |
status | true if the device motors are on. |
- Returns
- The number of failure reads between
0
and max_repeats
.
Definition at line 671 of file vpQbDevice.cpp.
◆ isConnected()
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
-
id | The ID of the device of interest, in range [1 , 128 ]. |
max_repeats | The 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 682 of file vpQbDevice.cpp.
◆ isInConnectedSet()
bool vpQbDevice::isInConnectedSet |
( |
const int & |
id | ) |
|
|
protectedvirtual |
Check whether the physical device specified by the given ID is connected to the Communication Handler.
- Parameters
-
id | The 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 693 of file vpQbDevice.cpp.
◆ isInOpenMap()
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_port | The 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 704 of file vpQbDevice.cpp.
◆ isReliable()
bool vpQbDevice::isReliable |
( |
int const & |
failures, |
|
|
int const & |
max_repeats |
|
) |
| |
|
protected |
Check whether the reading failures are in the given range.
- Parameters
-
failures | The current number of communication failures per serial resource reading. |
max_repeats | The 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 715 of file vpQbDevice.cpp.
◆ open()
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_port | The serial port which has to be opened, e.g. /dev/ttyUSB0 . |
- Returns
0
on success.
- See also
- close(), isInOpenMap()
Definition at line 727 of file vpQbDevice.cpp.
◆ setCommandsAndWait()
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
-
id | The ID of the device of interest, in range [1 , 128 ]. |
max_repeats | The maximum number of consecutive repetitions to mark retrieved data as corrupted. |
commands | The 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 741 of file vpQbDevice.cpp.
◆ setCommandsAsync()
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
-
id | The ID of the device of interest, in range [1 , 128 ]. |
commands | The 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 754 of file vpQbDevice.cpp.
◆ setMaxRepeats()
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 762 of file vpQbDevice.cpp.
◆ m_init_done
bool vpQbDevice::m_init_done |
|
protected |
Flag used to indicate if the device is initialized.
Definition at line 114 of file vpQbDevice.h.
◆ m_max_repeats
int vpQbDevice::m_max_repeats |
|
protected |
Max number of trials to send a command.
Definition at line 113 of file vpQbDevice.h.