Visual Servoing Platform  version 3.2.1 under development (2019-08-19)
vpQbSoftHand Class Reference

#include <visp3/robot/vpQbSoftHand.h>

+ Inheritance diagram for vpQbSoftHand:

Public Member Functions

 vpQbSoftHand ()
 
virtual ~vpQbSoftHand ()
 
void getCurrent (vpColVector &current, const int &id=1)
 
void getPosition (vpColVector &position, const int &id=1)
 
void setPosition (const vpColVector &position, const int &id=1)
 
void setPosition (const vpColVector &position, double speed_factor, double stiffness, const int &id=1)
 
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 qbSoftHand device.

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

Note
Before using this class under Linux (Ubuntu, Debian, Fedora...) it is mandatory to add user to the dialout group. To do so, you must execute:
$ sudo adduser user_name dialout
otherwise you will get an error:
vpQbDevice fails while opening [/dev/ttyUSB0] and sets errno [Permission denied].

The following example shows how to close and open the SoftHand with a given speed factor and stiffness used to stop the command applied to the motors when the measured current is larger than the stiffness multiplied by the maximum allowed current that can be applied to the motors.

#include <visp3/robot/vpQbSoftHand.h>
int main()
{
vpQbSoftHand qbsofthand;
double speed_factor = 0.5; // half speed
double stiffness = 0.7; // 70% of the max allowed current supported by the motors
std::cout << "** Close the hand with blocking positioning function" << std::endl;
q[0] = 1;
qbsofthand.setPosition(q, speed_factor, stiffness);
std::cout << "** Open the hand with blocking positioning function" << std::endl;
q[0] = 0;
qbsofthand.setPosition(q, speed_factor, stiffness);
}
Examples:
testQbSoftHand.cpp.

Definition at line 93 of file vpQbSoftHand.h.

Constructor & Destructor Documentation

◆ vpQbSoftHand()

vpQbSoftHand::vpQbSoftHand ( )

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

Definition at line 50 of file vpQbSoftHand.cpp.

◆ ~vpQbSoftHand()

vpQbSoftHand::~vpQbSoftHand ( )
virtual

Close all the still open serial ports.

See also
close()

Definition at line 59 of file vpQbSoftHand.cpp.

Member Function Documentation

◆ activate() [1/2]

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

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.

◆ activate() [2/2]

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

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.

◆ close()

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

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.

◆ deactivate()

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

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.

◆ getCurrent()

void vpQbSoftHand::getCurrent ( vpColVector current,
const int &  id = 1 
)

Retrieve the motor currents of the given device.

Parameters
idThe ID of the device of interest, in range [1, 128].
[out]currentThe one-element device motor current vector, expressed in mA.
Examples:
testQbSoftHand.cpp.

Definition at line 68 of file vpQbSoftHand.cpp.

References vpException::fatalError, vpQbDevice::getCurrents(), vpQbDevice::init(), vpQbDevice::isInConnectedSet(), vpQbDevice::isReliable(), vpQbDevice::m_init_done, vpQbDevice::m_max_repeats, and vpColVector::resize().

Referenced by setPosition().

◆ getCurrentMax()

double vpQbDevice::getCurrentMax ( ) const
inherited

Return the maximum current supported by the device.

Examples:
testQbSoftHand.cpp.

Definition at line 540 of file vpQbDevice.cpp.

Referenced by setPosition().

◆ getCurrents()

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

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 getCurrent().

◆ getInfo()

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

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.

◆ getMeasurements()

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

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.

◆ getParameters()

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

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.

◆ getPosition()

void vpQbSoftHand::getPosition ( vpColVector position,
const int &  id = 1 
)

Retrieve the motor position of the given device.

Parameters
idThe ID of the device of interest, in range [1, 128].
[out]positionThe device one-element position vector, expressed in range [0, 1] with 0 corresponding to an opened hand and 1 a closed hand.
See also
getMeasurements()
Examples:
testQbSoftHand.cpp.

Definition at line 94 of file vpQbSoftHand.cpp.

References vpException::fatalError, vpQbDevice::getPositionLimits(), vpQbDevice::getPositions(), vpQbDevice::init(), vpQbDevice::isInConnectedSet(), vpQbDevice::isReliable(), vpQbDevice::m_init_done, vpQbDevice::m_max_repeats, and vpColVector::resize().

Referenced by setPosition().

◆ getPositionLimits()

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

Definition at line 612 of file vpQbDevice.cpp.

Referenced by getPosition(), and setPosition().

◆ getPositions()

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

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 getPosition().

◆ getSerialPortsAndDevices()

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

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.

◆ init()

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

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 vpQbDevice::m_init_done.

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

◆ isActive()

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

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.

◆ isConnected()

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

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.

◆ isInConnectedSet()

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

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 getCurrent(), getPosition(), and setPosition().

◆ isInOpenMap()

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

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.

◆ isReliable()

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

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 getCurrent(), getPosition(), and setPosition().

◆ open()

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

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.

◆ setCommandsAndWait()

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

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.

◆ setCommandsAsync()

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

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 setPosition().

◆ setMaxRepeats()

void vpQbDevice::setMaxRepeats ( const int &  max_repeats)
inherited

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 vpQbDevice::m_max_repeats.

Referenced by vpQbDevice::vpQbDevice().

◆ setPosition() [1/2]

void vpQbSoftHand::setPosition ( const vpColVector position,
const int &  id = 1 
)

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

Parameters
idThe ID of the device of interest, in range [1, 128].
positionThe one-element position vector in range [0, 1] with 0 corresponding to an opened hand and 1 a closed hand.
Examples:
testQbSoftHand.cpp.

Definition at line 120 of file vpQbSoftHand.cpp.

References vpException::fatalError, vpQbDevice::getPositionLimits(), vpQbDevice::init(), vpQbDevice::isInConnectedSet(), vpQbDevice::isReliable(), vpQbDevice::m_init_done, vpQbDevice::m_max_repeats, vpQbDevice::setCommandsAsync(), and vpArray2D< Type >::size().

Referenced by setPosition().

◆ setPosition() [2/2]

void vpQbSoftHand::setPosition ( const vpColVector position,
double  speed_factor,
double  stiffness,
const int &  id = 1 
)

Send the reference command to the motors of the device with given id in a blocking fashion.

Parameters
idThe ID of the device of interest, in range [1, 128].
positionThe one-element position vector in range [0, 1] with 0 corresponding to an opened hand and 1 a closed hand.
speed_factorThe speed factor in range [0.01, 1] with 1 corresponding to the fastest mouvement.
stiffnessStiffness parameter in range [0, 1] is the scale factor applied to the maximum allowed current in order to limit the current into the motors. When set at zero, you can send any position command to the motors, but he will not move. When set to 1, it means that the maximum current returned by getCurrentMax() could be reached during positionning.

Definition at line 163 of file vpQbSoftHand.cpp.

References vpMath::equal(), getCurrent(), vpQbDevice::getCurrentMax(), getPosition(), vpQbDevice::getPositionLimits(), vpTime::measureTimeMs(), setPosition(), and vpTime::wait().

Member Data Documentation

◆ m_init_done

bool vpQbDevice::m_init_done
protectedinherited

Flag used to indicate if the device is initialized.

Definition at line 115 of file vpQbDevice.h.

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

◆ m_max_repeats

int vpQbDevice::m_max_repeats
protectedinherited

Max number of trials to send a command.

Definition at line 114 of file vpQbDevice.h.

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