Visual Servoing Platform  version 3.3.0
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
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 108 of file vpComedi.h.

Constructor & Destructor Documentation

◆ vpComedi()

vpComedi::vpComedi ( )

Default constructor.

Definition at line 50 of file vpComedi.cpp.

◆ ~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 60 of file vpComedi.cpp.

Member Function Documentation

◆ close()

void vpComedi::close ( )

Close the connection to the device.

Definition at line 92 of file vpComedi.cpp.

◆ getHandler()

comedi_t* vpComedi::getHandler ( ) const
inline

Get native Comedi handler.

Definition at line 118 of file vpComedi.h.

◆ 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 121 of file vpComedi.h.

◆ getNChannel()

unsigned int vpComedi::getNChannel ( ) const
inline

Get number of channels.

Examples
testComedi.cpp.

Definition at line 123 of file vpComedi.h.

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

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

◆ 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 130 of file vpComedi.h.

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

◆ getSubDevice()

unsigned int vpComedi::getSubDevice ( ) const
inline

Get comedi subdevice.

Definition at line 132 of file vpComedi.h.

◆ open()

void vpComedi::open ( )

Open the connection to the device.

Examples
testComedi.cpp.

Definition at line 65 of file vpComedi.cpp.

◆ 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 141 of file vpComedi.h.

◆ 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 147 of file vpComedi.h.

◆ setDevice()

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

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

Examples
testComedi.cpp.

Definition at line 150 of file vpComedi.h.

◆ 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 157 of file vpComedi.h.

◆ setSubDevice()

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

Set comedi analog input subdevice.

Definition at line 159 of file vpComedi.h.

Member Data Documentation

◆ m_aref

unsigned int vpComedi::m_aref
protected

Analog reference

Definition at line 172 of file vpComedi.h.

◆ m_chanlist

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

Channel list

Definition at line 176 of file vpComedi.h.

◆ m_device

std::string vpComedi::m_device
protected

Comedi device name (default: /dev/comedi0)

Definition at line 168 of file vpComedi.h.

◆ m_handler

comedi_t* vpComedi::m_handler
protected

Comedi handler

Definition at line 169 of file vpComedi.h.

◆ m_maxdata

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

Max data value

Definition at line 175 of file vpComedi.h.

◆ m_nchannel

unsigned int vpComedi::m_nchannel
protected

Number of channels

Definition at line 173 of file vpComedi.h.

◆ m_range

unsigned int vpComedi::m_range
protected

Range of a channel

Definition at line 171 of file vpComedi.h.

◆ m_range_info

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

Range information

Definition at line 174 of file vpComedi.h.

◆ m_subdevice

unsigned int vpComedi::m_subdevice
protected

Input subdevice

Definition at line 170 of file vpComedi.h.

vpComedi::close
void close()
Definition: vpComedi.cpp:92
vpTime::wait
VISP_EXPORT int wait(double t0, double t)
Definition: vpTime.cpp:172
vpColVector::t
vpRowVector t() const
Definition: vpColVector.cpp:781
vpComedi::setChannelNumbers
void setChannelNumbers(const unsigned int &nchannel)
Definition: vpComedi.h:147
vpComedi
Definition: vpComedi.h:108
vpComedi::open
void open()
Definition: vpComedi.cpp:65
vpComedi::setDevice
void setDevice(const std::string &device)
Set comedi device name. Default value is /dev/comedi0.
Definition: vpComedi.h:150
vpComedi::getPhyDataUnits
std::string getPhyDataUnits() const
Definition: vpComedi.cpp:157
vpComedi::getPhyData
vpColVector getPhyData() const
Definition: vpComedi.cpp:135