10 #ifndef __SKIN_MESH_THREAD_CAN_H__
11 #define __SKIN_MESH_THREAD_CAN_H__
16 #include <yarp/os/PeriodicThread.h>
17 #include <yarp/dev/ControlBoardInterfaces.h>
18 #include <yarp/dev/PolyDriver.h>
19 #include <yarp/dev/CanBusInterface.h>
37 using namespace yarp::os;
61 mbSimpleDraw=config.check(
"light");
65 for (
int t=0; t<16; ++t)
71 cardId=0x300 | (config.find(
"cardid").asInt32() << 4);
72 netId=config.find(
"CanDeviceNum").asInt32();
73 deviceName=config.find(
"CanDeviceName").asString();
74 std::string part=
"/skinGui/";
75 part.append(config.find(
"robotPart").asString());
77 int width =config.find(
"width" ).asInt32();
78 int height=config.find(
"height").asInt32();
79 bool useCalibration = config.check(
"useCalibration");
80 if (useCalibration==
true)
82 printf(
"Reading datadirectly from CAN! Calibration unsupported\n");
83 useCalibration =
false;
87 printf(
"Using raw skin values (255-0)\n");
90 yarp::os::Bottle sensorSetConfig=config.findGroup(
"SENSORS").tail();
92 for (
int t=0; t<sensorSetConfig.size(); ++t)
94 yarp::os::Bottle sensorConfig(sensorSetConfig.get(t).toString());
96 std::string type(sensorConfig.get(0).asString());
97 if (type ==
"triangle" ||
98 type ==
"fingertip" ||
99 type ==
"fingertip2L" ||
100 type ==
"cer_sh_pdl" ||
101 type ==
"fingertip2R" ||
102 type ==
"triangle_10pad" ||
106 type ==
"fingertip3R" ||
107 type ==
"fingertip3L" ||
108 type ==
"fingertip4R" ||
109 type ==
"fingertip4L" ||
110 type ==
"fingertipMID" ||
113 int id=sensorConfig.get(1).asInt32();
114 double xc=sensorConfig.get(2).asFloat64();
115 double yc=sensorConfig.get(3).asFloat64();
116 double th=sensorConfig.get(4).asFloat64();
117 double gain=sensorConfig.get(5).asFloat64();
118 int lrMirror=sensorConfig.get(6).asInt32();
119 int layoutNum=sensorConfig.get(7).asInt32();
121 printf(
"%d %f\n",
id,gain);
127 printf(
"WARNING: triangle %d already exists.\n",
id);
131 if (type==
"triangle")
133 sensor[id]=
new Triangle(xc,yc,th,gain,layoutNum,lrMirror);
135 else if (type==
"triangle_10pad")
139 else if (type==
"fingertip")
141 sensor[id]=
new Fingertip(xc,yc,th,gain,layoutNum,lrMirror);
143 else if (type==
"fingertip2L")
145 sensor[id]=
new Fingertip2L(xc,yc,th,gain,layoutNum,lrMirror);
147 else if (type==
"fingertip3L")
149 sensor[id]=
new Fingertip3L(xc,yc,th,gain,layoutNum,lrMirror);
151 else if(type ==
"fingertip4L")
153 sensor[id]=
new Fingertip4L(xc,yc,th,gain,layoutNum,lrMirror);
155 else if(type ==
"cer_sh_pdl")
157 sensor[id] =
new CER_SH_PDL(xc, yc, th, gain, layoutNum, lrMirror);
159 else if(type ==
"fingertip2R")
161 sensor[id]=
new Fingertip2R(xc,yc,th,gain,layoutNum,lrMirror);
163 else if(type ==
"fingertip3R")
165 sensor[id]=
new Fingertip3R(xc,yc,th,gain,layoutNum,lrMirror);
167 else if (type ==
"fingertip4R")
169 sensor[id]=
new Fingertip4R(xc,yc,th,gain,layoutNum,lrMirror);
171 else if (type ==
"fingertipMID")
173 sensor[id]=
new FingertipMID(xc,yc,th,gain,layoutNum,lrMirror);
175 else if (type ==
"quad16")
177 sensor[id]=
new Quad16(xc,yc,th,gain,layoutNum,lrMirror);
179 else if(type ==
"palmR")
181 sensor[id]=
new PalmR(xc,yc,th,gain,layoutNum,lrMirror);
183 else if(type ==
"palmL")
185 sensor[id]=
new PalmL(xc,yc,th,gain,layoutNum,lrMirror);
192 printf(
"WARNING: %d is invalid triangle Id [0:15].\n",
id);
197 printf(
"WARNING: sensor of type %s unknown, discarded.\n",type.c_str());
201 resize(width,height);
206 for (
int t=0; t<16; ++t)
208 if (sensor[t])
delete sensor[t];
212 virtual bool threadInit();
213 virtual void threadRelease();
218 std::lock_guard<std::mutex> lck(mtx);
219 for (
int t=0; t<16; ++t)
221 if (sensor[t]) sensor[t]->
resize(width,height,40);
225 void eval(
unsigned char *image)
227 std::lock_guard<std::mutex> lck(mtx);
228 for (
int t=0; t<16; ++t)
238 sensor[t]->
eval(image);
244 void draw(
unsigned char *image)
246 for (
int t=0; t<16; ++t)
248 if (sensor[t]) sensor[t]->
draw(image);
void draw(unsigned char *image)
void eval(unsigned char *image)
ICanBufferFactory * pCanBufferFactory
SkinMeshThreadCan(Searchable &config, int period)
void resize(int width, int height)
void eval(unsigned char *image)
void resize(int width, int height, int margin)
virtual void draw(unsigned char *image)
void eval_light(unsigned char *image)