Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpComedi Class Reference

#include <vpComedi.h>

Inheritance diagram for vpComedi:

Public Member Functions

 vpComedi ()
virtual ~vpComedi ()

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

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)
std::vector< lsampl_t > getRawData () const

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
void open()
Definition vpComedi.cpp:61
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>
#ifdef ENABLE_VISP_NAMESPACE
using namespace VISP_NAMESPACE_NAME;
#endif
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();
}
vpRowVector t() const
void setChannelNumbers(const unsigned int &nchannel)
Definition vpComedi.h:148
void setDevice(const std::string &device)
Set comedi device name. Default value is /dev/comedi0.
Definition vpComedi.h:151
vpColVector getPhyData() const
Definition vpComedi.cpp:131
std::string getPhyDataUnits() const
Definition vpComedi.cpp:153
void close()
Definition vpComedi.cpp:88
VISP_EXPORT int wait(double t0, double t)
Examples
testComedi.cpp.

Definition at line 109 of file vpComedi.h.

Constructor & Destructor Documentation

◆ vpComedi()

BEGIN_VISP_NAMESPACE vpComedi::vpComedi ( )

Default constructor.

Definition at line 47 of file vpComedi.cpp.

References m_aref, m_chanlist, m_device, m_handler, m_maxdata, m_nchannel, m_range, m_range_info, and m_subdevice.

◆ ~vpComedi()

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 56 of file vpComedi.cpp.

References close().

Member Function Documentation

◆ close()

void vpComedi::close ( )

Close the connection to the device.

Definition at line 88 of file vpComedi.cpp.

References m_handler.

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

◆ getHandler()

comedi_t * vpComedi::getHandler ( ) const
inline

Get native Comedi handler.

Definition at line 119 of file vpComedi.h.

References m_handler.

◆ getMaxData()

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.

References m_maxdata.

◆ getNChannel()

unsigned int vpComedi::getNChannel ( ) const
inline

Get number of channels.

Examples
testComedi.cpp.

Definition at line 124 of file vpComedi.h.

References m_nchannel.

◆ getPhyData()

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

◆ getPhyDataUnits()

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 153 of file vpComedi.cpp.

References vpException::fatalError, m_handler, and m_range_info.

◆ getRangeInfo()

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.

References m_range_info.

◆ getRawData()

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 103 of file vpComedi.cpp.

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

Referenced by getPhyData().

◆ getSubDevice()

unsigned int vpComedi::getSubDevice ( ) const
inline

Get comedi subdevice.

Definition at line 133 of file vpComedi.h.

References m_subdevice.

◆ open()

void vpComedi::open ( )

Open the connection to the device.

Examples
testComedi.cpp.

Definition at line 61 of file vpComedi.cpp.

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

Referenced by vpForceTorqueAtiSensor::open().

◆ setAnalogReference()

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.

References m_aref.

◆ setChannelNumbers()

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.

References m_nchannel.

Referenced by vpForceTorqueAtiSensor::open().

◆ setDevice()

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.

References m_device.

◆ setRange()

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.

References m_range.

◆ setSubDevice()

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

Set comedi analog input subdevice.

Definition at line 160 of file vpComedi.h.

References m_subdevice.

Member Data Documentation

◆ m_aref

unsigned int vpComedi::m_aref
protected

Analog reference

Definition at line 173 of file vpComedi.h.

Referenced by getRawData(), open(), setAnalogReference(), and vpComedi().

◆ m_chanlist

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

Channel list

Definition at line 177 of file vpComedi.h.

Referenced by open(), and vpComedi().

◆ m_device

std::string vpComedi::m_device
protected

Comedi device name (default: /dev/comedi0)

Definition at line 169 of file vpComedi.h.

Referenced by getRawData(), open(), setDevice(), and vpComedi().

◆ m_handler

comedi_t* vpComedi::m_handler
protected

Comedi handler

Definition at line 170 of file vpComedi.h.

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

◆ m_maxdata

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

Max data value

Definition at line 176 of file vpComedi.h.

Referenced by getMaxData(), getPhyData(), open(), and vpComedi().

◆ m_nchannel

unsigned int vpComedi::m_nchannel
protected

Number of channels

Definition at line 174 of file vpComedi.h.

Referenced by getNChannel(), getPhyData(), getRawData(), open(), setChannelNumbers(), and vpComedi().

◆ m_range

unsigned int vpComedi::m_range
protected

Range of a channel

Definition at line 172 of file vpComedi.h.

Referenced by getRawData(), open(), setRange(), and vpComedi().

◆ m_range_info

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

Range information

Definition at line 175 of file vpComedi.h.

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

◆ m_subdevice

unsigned int vpComedi::m_subdevice
protected

Input subdevice

Definition at line 171 of file vpComedi.h.

Referenced by getRawData(), getSubDevice(), open(), setSubDevice(), and vpComedi().