iCub-main
Loading...
Searching...
No Matches
CanBusSkin.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) 2010 RobotCub Consortium
4// Authors: Lorenzo Natale, Francesco Giovannini
5// CopyPolicy: Released under the terms of the GNU GPL v2.0.
6
7#ifndef __CANBUSSKIN_H__
8#define __CANBUSSKIN_H__
9
10#include <mutex>
11#include <string>
12
13#include <yarp/os/PeriodicThread.h>
14#include <yarp/dev/ControlBoardInterfaces.h>
15#include <yarp/dev/IAnalogSensor.h>
16#include <yarp/dev/PolyDriver.h>
17#include <yarp/dev/CanBusInterface.h>
18#include <yarp/sig/Vector.h>
19#include <yarp/os/BufferedPort.h>
20
21
22#include "SkinConfigReader.h"
23#include <SkinDiagnostics.h>
24
25
26class CanBusSkin : public yarp::os::PeriodicThread, public yarp::dev::IAnalogSensor, public yarp::dev::DeviceDriver
27{
28private:
29
30 bool _verbose;
31
32
33 /* *************************************************************************************** */
34 // CAN Message parameters
35 // 4C Message
36 yarp::os::Bottle msg4C_Timer;
37 yarp::os::Bottle msg4C_CDCOffsetL;
38 yarp::os::Bottle msg4C_CDCOffsetH;
39 yarp::os::Bottle msg4C_TimeL;
40 yarp::os::Bottle msg4C_TimeH;
41
42 //4E Message
43 yarp::os::Bottle msg4E_Shift;
44 yarp::os::Bottle msg4E_Shift3_1;
45 yarp::os::Bottle msg4E_NoLoad;
46 yarp::os::Bottle msg4E_Param;
47 yarp::os::Bottle msg4E_EnaL;
48 yarp::os::Bottle msg4E_EnaH;
49 /* *************************************************************************************** */
50
52 yarp::os::BufferedPort<yarp::sig::Vector> portSkinDiagnosticsOut;
53
54 /****************** new cfg **********************************/
55 SkinBoardCfgParam _brdCfg;
56 SkinTriangleCfgParam _triangCfg;
57 bool _newCfg;
58 SkinConfigReader _cfgReader;
59 int _canBusNum;
60 /*************************************************************/
61
62 /****************** diagnostic********************************/
63 bool _isDiagnosticPresent; // is the diagnostic available from the firmware
64 /*************************************************************/
65
66protected:
67 yarp::dev::PolyDriver driver;
68 yarp::dev::ICanBus *pCanBus;
69 yarp::dev::ICanBufferFactory *pCanBufferFactory;
70 yarp::dev::CanBuffer inBuffer;
71 yarp::dev::CanBuffer outBuffer;
72
73 std::mutex mtx;
74
76 int netID;
77
78 yarp::sig::VectorOf<int> cardId;
80
81 yarp::sig::Vector data;
82
84 yarp::sig::VectorOf<iCub::skin::diagnostics::DetectedError> errors;
85
86public:
87 CanBusSkin();
89
90 virtual bool open(yarp::os::Searchable& config);
91 virtual bool close();
92 virtual bool threadInit();
93 virtual void threadRelease();
94 virtual void run();
95
96 //IAnalogSensor interface
97 virtual int read(yarp::sig::Vector &out);
98 virtual int getState(int ch);
99 virtual int getChannels();
100 virtual int calibrateSensor();
101 virtual int calibrateChannel(int ch, double v);
102
103 virtual int calibrateSensor(const yarp::sig::Vector& v);
104 virtual int calibrateChannel(int ch);
105
106private:
112 bool diagnoseSkin(void);
113
123 void checkParameterListLength(const std::string &i_paramName, yarp::os::Bottle &i_paramList, const int &i_length, const yarp::os::Value &i_defaultValue);
124
128 bool sendCANMessage4C(void);
129 bool checkFirmwareVersion(void);
130
134 bool sendCANMessage4E(void);
135
139 bool sendCANMessage(uint8_t destAddr, uint8_t command, void *data);
140
144 bool readOldConfiguration(yarp::os::Searchable& config);
145
149 bool readNewConfiguration(yarp::os::Searchable& config);
150
154 bool readNewSpecialConfiguration(yarp::os::Searchable& config);
155};
156
157#endif
virtual int getState(int ch)
yarp::sig::VectorOf< iCub::skin::diagnostics::DetectedError > errors
The detected skin errors.
Definition CanBusSkin.h:84
virtual void threadRelease()
yarp::dev::CanBuffer inBuffer
Definition CanBusSkin.h:70
yarp::sig::VectorOf< int > cardId
Definition CanBusSkin.h:78
yarp::sig::Vector data
Definition CanBusSkin.h:81
yarp::dev::CanBuffer outBuffer
Definition CanBusSkin.h:71
yarp::dev::ICanBufferFactory * pCanBufferFactory
Definition CanBusSkin.h:69
virtual bool threadInit()
yarp::dev::ICanBus * pCanBus
Definition CanBusSkin.h:68
virtual int getChannels()
virtual int read(yarp::sig::Vector &out)
virtual bool close()
std::mutex mtx
Definition CanBusSkin.h:73
yarp::dev::PolyDriver driver
Definition CanBusSkin.h:67
virtual void run()
virtual bool open(yarp::os::Searchable &config)
virtual int calibrateSensor()
int netID
The CAN net ID.
Definition CanBusSkin.h:76
virtual int calibrateChannel(int ch, double v)
int sensorsNum
Definition CanBusSkin.h:79
out
Definition sine.m:8