iCub-main
Loading...
Searching...
No Matches
CanBusFtSensor.h
Go to the documentation of this file.
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3// Copyright: (C) 2013 iCub Facility
4// Authors: Marco Randazzo <marco.randazzo@iit.it> Valentina Vasco <valentina.vasco@iit.it>
5// CopyPolicy: Released under the terms of the GNU GPL v2.0.
6
7#ifndef __CANBUSFTSENSOR_H__
8#define __CANBUSFTSENSOR_H__
9
10#include <mutex>
11#include <yarp/os/PeriodicThread.h>
12#include <yarp/dev/PolyDriver.h>
13#include <yarp/dev/CanBusInterface.h>
14#include <yarp/dev/MultipleAnalogSensorsInterfaces.h>
15#include <yarp/sig/Vector.h>
16
17using namespace yarp::os;
18using namespace yarp::dev;
19
44class CanBusFtSensor : public PeriodicThread,
45 public DeviceDriver,
46 public yarp::dev::ISixAxisForceTorqueSensors
47{
48 enum AnalogDataFormat
49 {
50 ANALOG_FORMAT_ERR = 0,
51 ANALOG_FORMAT_8_BIT = 8,
52 ANALOG_FORMAT_16_BIT = 16,
53 };
54
55 enum SensorStatus
56 {
57 ANALOG_IDLE=0,
58 ANALOG_OK=1,
59 ANALOG_NOT_RESPONDING=-1,
60 ANALOG_SATURATION=-2,
61 ANALOG_ERROR=-3,
62 };
63
64protected:
65 PolyDriver driver;
66 ICanBus *pCanBus;
67 ICanBufferFactory *pCanBufferFactory;
68 CanBuffer inBuffer;
69 CanBuffer outBuffer;
71
72 mutable std::mutex mtx;
73
74 unsigned int channelsNum;
75 unsigned short boardId;
76 short status;
77 double timeStamp;
78 AnalogDataFormat dataFormat;
79 yarp::sig::Vector data;
80 yarp::sig::Vector scaleFactor;
81 unsigned short useCalibration;
83 std::string sensorName;
84 std::string frameName;
85
86public:
87 CanBusFtSensor(int period=20) : PeriodicThread((double)period/1000.0)
88 {}
89
90
92 {
93 }
94
95 virtual bool open(yarp::os::Searchable& config);
96 virtual bool close();
97
98 virtual bool threadInit();
99 virtual void threadRelease();
100 virtual void run();
101
102 // ISixAxisForceTorqueSensors
103 virtual size_t getNrOfSixAxisForceTorqueSensors() const override;
104 virtual yarp::dev::MAS_status getSixAxisForceTorqueSensorStatus(size_t sens_index) const override;
105 virtual bool getSixAxisForceTorqueSensorName(size_t sens_index, std::string &name) const override;
106 virtual bool getSixAxisForceTorqueSensorFrameName(size_t sens_index, std::string &frameName) const override;
107 virtual bool getSixAxisForceTorqueSensorMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const override;
108
109 //internal methods
110 private:
111 bool decode8 (const unsigned char *msg, int msg_id, double *data);
112 bool decode16(const unsigned char *msg, int msg_id, double *data);
113 bool sensor_start (yarp::os::Searchable& config);
114 bool sensor_stop ();
115 bool readFullScaleAnalog(int ch);
116};
117
118
119#endif
canbusftsensor : driver for CAN communication with IIT's analog sensor boards, including the MAIS and...
virtual bool open(yarp::os::Searchable &config)
std::string frameName
ICanBus * pCanBus
unsigned short boardId
virtual yarp::dev::MAS_status getSixAxisForceTorqueSensorStatus(size_t sens_index) const override
CanBuffer outBuffer
virtual bool getSixAxisForceTorqueSensorFrameName(size_t sens_index, std::string &frameName) const override
virtual void run()
yarp::sig::Vector data
unsigned short useCalibration
PolyDriver driver
virtual size_t getNrOfSixAxisForceTorqueSensors() const override
ICanBufferFactory * pCanBufferFactory
AnalogDataFormat dataFormat
virtual bool getSixAxisForceTorqueSensorName(size_t sens_index, std::string &name) const override
std::string sensorName
unsigned int channelsNum
virtual bool threadInit()
CanBusFtSensor(int period=20)
yarp::sig::Vector scaleFactor
CanBuffer inBuffer
virtual bool getSixAxisForceTorqueSensorMeasure(size_t sens_index, yarp::sig::Vector &out, double &timestamp) const override
virtual void threadRelease()
virtual bool close()
out
Definition sine.m:8