Visual Servoing Platform  version 3.4.0
vpComedi Class Reference

#include <vpComedi.h>

+ Inheritance diagram for vpComedi:

Public Member Functions

 vpComedi ()
 
virtual ~vpComedi ()
 
Inherited functionalities from vpComedi
void close ()
 
comedi_t * getHandler () const
 
std::vector< lsampl_t > getMaxData () const
 
unsigned int getNChannel () const
 
vpColVector getPhyData () const
 
std::string getPhyDataUnits () const
 
std::vector< comedi_range * > getRangeInfo () const
 
unsigned int getSubDevice () const
 
void open ()
 
void setAnalogReference (const unsigned int &aref)
 
void setChannelNumbers (const unsigned int &nchannel)
 
void setDevice (const std::string &device)
 
void setRange (const unsigned int &range)
 
void setSubDevice (const unsigned int &subdevice)
 

Protected Member Functions

std::vector< lsampl_t > getRawData () const
 

Protected Attributes

Protected Member Functions Inherited from vpComedi
std::string m_device
 
comedi_t * m_handler
 
unsigned int m_subdevice
 
unsigned int m_range
 
unsigned int m_aref
 
unsigned int m_nchannel
 
std::vector< comedi_range * > m_range_info
 
std::vector< lsampl_t > m_maxdata
 
std::vector< unsigned int > m_chanlist
 

Detailed Description

Interface for data acquisition devices supported by Comedi. Comedi is a linux control and measurement device interface. For more information see http://www.comedi.org.

This class was tested with ATI Gamma 65-SI FT sensor connected to a National Instrument NI DAQmx PCI-6220 board.

Warning
If you experience an exception like
Could not open device /dev/comedi0
you may set up udev permissions for Comedi device files. Once Comedi is installed you also need to make sure that the user has appropriate permissions for accessing the Comedi device files. That is you need to be able to have read and write access to the /dev/comedi* files. One elegant way to achieve this to create a new group and tell udev to add the Comedi device files to this group. To this end:
  1. Login as root
  2. Create a new group "iocard":
    $ addgroup --system iocard
  3. Add udev rules to the /etc/udev/rules.d directory:
    $ echo 'KERNEL=="comedi*", MODE="0660", GROUP="iocard"' >
    /etc/udev/rules.d/95-comedi.rules
  4. Add users to the "iocard" group:
    $ adduser <username> iocard
  5. Reboot

The following example shows how to run an synchronous data acquisition at 500 Hz, calling getPhyData() each 2 ms:

#include <visp3/sensor/vpComedi.h>
int main()
{
vpComedi comedi;
comedi.setDevice("/dev/comedi0");
comedi.setChannelNumbers(6); // to read a F/T tensor
comedi.open();
for(unsigned int i=0; i < 500; i++) {
std::cout << "Physical data (in " << comedi.getPhyDataUnits() << "): " << comedi.getPhyData().t() << std::endl;
}
comedi.close();
}
Examples:
testComedi.cpp.

Definition at line 109 of file vpComedi.h.

Constructor & Destructor Documentation

vpComedi::vpComedi ( )

Default constructor.

Definition at line 51 of file vpComedi.cpp.

vpComedi::~vpComedi ( )
virtual

Destructor that closes the connection to the device if it is not already done calling close().

See also
close()

Definition at line 61 of file vpComedi.cpp.

References close().

Member Function Documentation

void vpComedi::close ( )

Close the connection to the device.

Definition at line 93 of file vpComedi.cpp.

References m_handler.

Referenced by vpForceTorqueAtiSensor::close(), and ~vpComedi().

comedi_t* vpComedi::getHandler ( ) const
inline

Get native Comedi handler.

Definition at line 119 of file vpComedi.h.

std::vector<lsampl_t> vpComedi::getMaxData ( ) const
inline

Get max data per channel. The returned vector is of dimension the number of channels.

Definition at line 122 of file vpComedi.h.

unsigned int vpComedi::getNChannel ( ) const
inline

Get number of channels.

Examples:
testComedi.cpp.

Definition at line 124 of file vpComedi.h.

vpColVector vpComedi::getPhyData ( ) const

Get physical data from device with units in Volts or mA. To know which unit is used, call getPhyDataUnits().

Examples:
testComedi.cpp.

Definition at line 136 of file vpComedi.cpp.

References vpException::fatalError, getRawData(), vpMath::isNaN(), m_handler, m_maxdata, m_nchannel, and m_range_info.

Referenced by vpForceTorqueAtiSensor::bias(), vpForceTorqueAtiSensor::getForceTorque(), and vpForceTorqueAtiSensor::unbias().

std::string vpComedi::getPhyDataUnits ( ) const

Get units (V or mA) of the physical data acquired by getPhyData() or getPhyDataAsync().

Examples:
testComedi.cpp.

Definition at line 158 of file vpComedi.cpp.

References vpException::fatalError, m_handler, and m_range_info.

std::vector<comedi_range *> vpComedi::getRangeInfo ( ) const
inline

Get data range information per channel. The returned vector is of dimension the number of channels.

Definition at line 131 of file vpComedi.h.

std::vector< lsampl_t > vpComedi::getRawData ( ) const
protected

Get raw data from device. If you selected an analog input subdevice, the output is an unsigned number, for example between 0 and 65535 for a 16 bit analog input, with 0 representing the lowest voltage of the ADC, and a hardware-dependent maximum value representing the highest voltage.

Definition at line 108 of file vpComedi.cpp.

References vpException::fatalError, m_aref, m_device, m_handler, m_nchannel, m_range, and m_subdevice.

Referenced by getPhyData().

unsigned int vpComedi::getSubDevice ( ) const
inline

Get comedi subdevice.

Definition at line 133 of file vpComedi.h.

void vpComedi::open ( )
void vpComedi::setAnalogReference ( const unsigned int &  aref)
inline

Set analog reference type.

Parameters
aref: The aref parameter specifies an analog reference to use: AREF_GROUND, AREF_COMMON, AREF_DIFF, or AREF_OTHER.

Definition at line 142 of file vpComedi.h.

void vpComedi::setChannelNumbers ( const unsigned int &  nchannel)
inline

Number of channels to read from sensor. For a 6-dim force/torque sensor use 6.

Examples:
testComedi.cpp.

Definition at line 148 of file vpComedi.h.

Referenced by vpForceTorqueAtiSensor::open().

void vpComedi::setDevice ( const std::string &  device)
inline

Set comedi device name. Default value is /dev/comedi0.

Examples:
testComedi.cpp.

Definition at line 151 of file vpComedi.h.

void vpComedi::setRange ( const unsigned int &  range)
inline

Set the range parameter that is the zero-based index of one of the gain ranges supported by the channel. This is a number from 0 to N-1 where N is the number of ranges supported by the channel.

Definition at line 158 of file vpComedi.h.

void vpComedi::setSubDevice ( const unsigned int &  subdevice)
inline

Set comedi analog input subdevice.

Definition at line 160 of file vpComedi.h.

Member Data Documentation

unsigned int vpComedi::m_aref
protected

Analog reference

Definition at line 173 of file vpComedi.h.

Referenced by getRawData(), and open().

std::vector<unsigned int> vpComedi::m_chanlist
protected

Channel list

Definition at line 177 of file vpComedi.h.

Referenced by open().

std::string vpComedi::m_device
protected

Comedi device name (default: /dev/comedi0)

Definition at line 169 of file vpComedi.h.

Referenced by getRawData(), and open().

comedi_t* vpComedi::m_handler
protected

Comedi handler

Definition at line 170 of file vpComedi.h.

Referenced by close(), getPhyData(), getPhyDataUnits(), getRawData(), and open().

std::vector<lsampl_t> vpComedi::m_maxdata
protected

Max data value

Definition at line 176 of file vpComedi.h.

Referenced by getPhyData(), and open().

unsigned int vpComedi::m_nchannel
protected

Number of channels

Definition at line 174 of file vpComedi.h.

Referenced by getPhyData(), getRawData(), and open().

unsigned int vpComedi::m_range
protected

Range of a channel

Definition at line 172 of file vpComedi.h.

Referenced by getRawData(), and open().

std::vector<comedi_range *> vpComedi::m_range_info
protected

Range information

Definition at line 175 of file vpComedi.h.

Referenced by getPhyData(), getPhyDataUnits(), and open().

unsigned int vpComedi::m_subdevice
protected

Input subdevice

Definition at line 171 of file vpComedi.h.

Referenced by getRawData(), and open().