iCub-main
Loading...
Searching...
No Matches
FeatureInterface.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2014 iCub Facility, Istituto Italiano di Tecnologia
3 * Authors: Alberto Cardellino
4 * CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
5 *
6 */
7
8
9
10#include "FeatureInterface.h"
12
13#include <ethManager.h>
14#include "embObjMotionControl.h"
15#include "embObjAnalogSensor.h"
16#include "embObjSkin.h"
17
18#include "EoProtocol.h"
19
20#include <yarp/os/Time.h>
21
22#ifdef _SETPOINT_TEST_
23#include <time.h>
24#include <sys/time.h>
25#include "EOYtheSystem.h"
26#endif
27
28
29
30//static TheEthManager *_interface2ethManager = NULL;
31
32//void initCallback(void *p)
33//{
34// if(_interface2ethManager == NULL )
35// {
36// _interface2ethManager = (TheEthManager*) p;
37// }
38//}
39
40//fakestdbool_t addEncoderTimeStamp(FEAT_ID *id, int jointNum)
41//{
42// embObjMotionControl *tmp = (embObjMotionControl *)(_interface2ethManager->getHandle(id->boardNum, id->ep));
43// if(tmp != NULL)
44// {
45// tmp->refreshEncoderTimeStamp(jointNum);
46// return fakestdbool_true;
47// }
48
49// return fakestdbool_false;
50//}
51
52//fakestdbool_t findAndFill(FEAT_ID *id, void *sk_array, eOprotID32_t id32)
53//{
54// // new with table, data stored in eoSkin;
55// // specie di view grezza, usare dynamic cast?
56// static int error = 0;
57// static int notYetInitted = 0;
58// IiCubFeature *skin;
59// EmbObjSkin *tmp = (EmbObjSkin *)(_interface2ethManager->getHandle(id->boardNum, id->ep));
60
61// if(NULL == tmp)
62// {
63// if(0 == (error%1000) )
64// yError() << "Got a SKIN message from EMS with EP " << id->ep << "board number " << id->boardNum << "but no class was instatiated for it";
65
66// error++;
67// return fakestdbool_false;
68// }
69// else
70// {
71// skin = dynamic_cast<IiCubFeature *>(tmp);
72// if(NULL != skin)
73// {
74// skin->fillData((void *)sk_array, id32);
75// }
76// else
77// {
78// if(0 == (notYetInitted%1000))
79// yWarning() << "Got a SKIN message with EP "<< id->ep << "board number " << id->boardNum << " not yet initialized";
80
81// notYetInitted++;
82// return fakestdbool_false;
83// }
84// }
85// return fakestdbool_true;
86//}
87
88//void *get_MChandler_fromEP(uint8_t boardnum, eOprotEndpoint_t ep)
89//{
90// void *h = NULL;
91// h = _interface2ethManager->getHandle(boardnum, ep);
92// return h;
93//}
94
95//fakestdbool_t handle_AS_data(FEAT_ID *id, void *as_array, eOprotID32_t id32)
96//{
97// IiCubFeature *iAnalog;
98
99// // if the following is required ... include "EoAnalogSensors.h"
100// // eOas_arrayofupto12bytes_t *debug_tmp = (eOas_arrayofupto12bytes_t *) as_array;
101
102// // specie di view grezza, usare dynamic cast?
103// embObjAnalogSensor *tmp = (embObjAnalogSensor *)(_interface2ethManager->getHandle(id->boardNum, id->ep));
104
105// if(NULL == tmp)
106// {
110// return fakestdbool_false;
111// }
112// else
113// {
114// iAnalog = dynamic_cast<IiCubFeature *>(tmp);
115// iAnalog->fillData(as_array, id32);
116// }
117
118// return fakestdbool_true;
119//}
120
121//fakestdbool_t MCmutex_post(void *p, uint32_t prognum)
122//{
123// eoThreadEntry *th = NULL;
124// embObjMotionControl *handler = (embObjMotionControl *) p;
125// int threadId;
126// eoThreadFifo *fuffy = handler->requestQueue->getFifo(prognum);
127
128// if( (threadId = fuffy->pop()) < 0)
129// {
130// yError() << "Received an answer message nobody is waiting for (MCmutex_post)";
131// return fakestdbool_false;
132// }
133// else
134// {
135// th = handler->requestQueue->threadPool->getThreadTable(threadId);
136// if(NULL == th)
137// yError() << "MCmutex_post error at line " << __LINE__;
138// th->push();
139// return fakestdbool_true;
140// }
141
142// return fakestdbool_false;
143//}
144
145
146//FEAT_boardnumber_t nvBoardNum2FeatIdBoardNum(eOprotBRD_t nvboardnum)
147//{
148// if(eo_prot_BRDdummy == nvboardnum)
149// {
150// return(FEAT_boardnumber_dummy);
151// }
152
153// return(nvboardnum+1);
154//}
155
157{
158 if(FEAT_boardnumber_dummy == fid_boardnum)
159 {
160 return(eo_prot_BRDdummy);
161 }
162
163 return(fid_boardnum-1);
164}
165
166//double feat_yarp_time_now(void)
167//{
168// return(yarp::os::Time::now());
169//}
170
171#ifdef _SETPOINT_TEST_
172//static void s_print_test_data(int jointNum, setpoint_test_data_t *test_data_ptr, uint64_t diff_ms)
173//{
174// printf("\n\n ******* IN CBK J_STATUS n=%d, diff=(ms)%llu, rec_pkt=%u , process_pkt=%u, exit_rx_phase_cond=%d\n\n",jointNum, diff_ms, test_data_ptr->numofrecpkt, test_data_ptr->numofprocesspkt, (int)test_data_ptr->exit_rx_phase_cond);
175//}
176
177void check_received_debug_data(FEAT_ID *id, int jointNum, setpoint_test_data_t *test_data_ptr)
178{
179 static int old_diff_packets[10][8] = {0}; // scheda/joint
180 struct timespec curr_time;
181 static int count = 0;
182 static bool ep_printed_6 = false;
183 static bool ep_printed_8 = false;
184 uint64_t curr_time_us;
185 uint64_t diff_ms = 0;
187
188 if(!((tmp->getFeat_id().boardNum == 6) || (tmp->getFeat_id().boardNum == 8)))
189 return;
190
191
192 if(tmp == 0)
193 {
194 printf("error in heck_received_debug_data\n");
195 }
196
197// //prendo il numero di endpoint per le schede 6 e 7
198//
199// if( (!ep_printed_6) && (tmp->getFeat_id().boardNum == 6))
200// {
201// yError() << "++++++++++++++++++++++++ board num "<< tmp->getFeat_id().boardNum << "ep = " << tmp->getFeat_id().ep;
202// ep_printed_6 = true;
203// }
204//
205// if( (!ep_printed_8) && (tmp->getFeat_id().boardNum == 8))
206// {
207// yError() << "++++++++++++++++++++++++ board num "<< tmp->getFeat_id().boardNum << "ep = " << tmp->getFeat_id().ep;
208// ep_printed_8 = true;
209// }
210
211
212
213 //only for joint num 0 verify loop time
214 if((jointNum == 0) && ((tmp->getFeat_id().boardNum == 6) || (tmp->getFeat_id().boardNum == 8)))
215 {
216// if(test_data_ptr->looptime >10)
217// {
218// printf("--------- LOOP TIME----- %s, %u\n", tmp->getFeat_id().name, test_data_ptr->looptime);
219// }
220 if(test_data_ptr->diff_packets != old_diff_packets[tmp->getFeat_id().boardNum][jointNum])
221 {
222 yError() << "board" << tmp->getFeat_id().name << "joint" << jointNum << "--------- diff_packets ----- " << test_data_ptr->diff_packets;
223 old_diff_packets[tmp->getFeat_id().boardNum][jointNum] = test_data_ptr->diff_packets;
224 }
225 }
226
227 //check if received values are default
228 if((test_data_ptr->time == 0xABABABABABABABAB) &&
229 (test_data_ptr->setpoint == 0xCCCCCCCC) &&
230 (test_data_ptr->numofrecpkt == 0xFF) &&
231 (test_data_ptr->numofprocesspkt == 0xEE)
232// (test_data_ptr->exit_rx_phase_cond == 0xDD)
233 )
234 {
235// tmp->j_debug_data[jointNum].last_time = test_data_ptr->time;
236 return; //no setpoint are received!!
237 }
238
239// if(test_data_ptr->numofsepoint > 1)
240// yError() << "*** for EMS" << tmp->getFeat_id().boardNum << "joint " << jointNum << "setpoint num =" << test_data_ptr->numofsepoint;
241
242 if(jointNum == 0)
243 {
244 if((test_data_ptr->numofrecpkt != test_data_ptr->numofprocesspkt) || (test_data_ptr->numofrecpkt > 1))
245 {
246 struct timeval err_time;
247 gettimeofday(&err_time, NULL);
248 yError() << "[" << err_time.tv_sec <<"." <<err_time.tv_usec << "] QUEUEUEUEUE" << tmp->getFeat_id().boardNum << "joint " << jointNum << "recv " << test_data_ptr->numofrecpkt << "processed " << test_data_ptr->numofprocesspkt;
249 }
250 }
251
252 if(jointNum == 0)
253 {
254 if((test_data_ptr->exit_cond != 0) && (test_data_ptr->exit_cond != -5))
255 {
256 struct timeval err_time;
257 gettimeofday(&err_time, NULL);
258 yError() << "[" << err_time.tv_sec <<"." <<err_time.tv_usec << "] board " << tmp->getFeat_id().boardNum << "exit_cond" << test_data_ptr->exit_cond;
259 }
260 }
261
262 tmp->j_debug_data[jointNum].mutex.wait();
263
264 if(test_data_ptr->setpoint == tmp->j_debug_data[jointNum].pos)
265 {
266 if(tmp->j_debug_data[jointNum].gotIt)
267 {
268 tmp->j_debug_data[jointNum].mutex.post();
269 return; // siamo felici
270 }
271
272 else
273 {
274 tmp->j_debug_data[jointNum].gotIt = true;
275 curr_time_us = eoy_sys_abstime_get(eoy_sys_GetHandle());
276 diff_ms = (curr_time_us - test_data_ptr->time) /1000;
277 struct timeval err_time;
278 gettimeofday(&err_time, NULL);
279
280 yWarning() << "Got Ack for EMS" << tmp->getFeat_id().boardNum << "joint " << jointNum << "with time " << diff_ms << "and count_old " << tmp->j_debug_data[jointNum].count_old << "[" << err_time.tv_sec <<"." <<err_time.tv_usec << "]";
281// tmp->j_debug_data[jointNum].count_old = 0;
282 }
283 }
284 else if(test_data_ptr->setpoint == tmp->j_debug_data[jointNum].last_pos)
285 {
286 tmp->j_debug_data[jointNum].count_old++;
287
288 if(tmp->j_debug_data[jointNum].count_old == 10)
289 yWarning() << "*** for EMS" << tmp->getFeat_id().boardNum << "joint " << jointNum << "count_old =" << tmp->j_debug_data[jointNum].count_old;
290 }
291 else
292 {
293 if(!tmp->j_debug_data[jointNum].wtf)
294 {
295 struct timeval err_time;
296 gettimeofday(&err_time, NULL);
297
298 yError() << "[" << err_time.tv_sec <<"." <<err_time.tv_usec << "] LOST PACKET for EMS" << tmp->getFeat_id().boardNum << "joint " << jointNum << "and count_old " << tmp->j_debug_data[jointNum].count_old;
299 }
300
301 tmp->j_debug_data[jointNum].wtf = true;
302 }
303
304 tmp->j_debug_data[jointNum].mutex.post();
305
306// if(test_data_ptr->time == tmp->j_debug_data[jointNum].last_time)
307// {
308// //verifico se ho perso un setpoint in direzione pc104-->ems
313//
314// return; //la scheda non ha piu' riceviuto set point
315// }
316// else
317// {
318// tmp->j_debug_data[jointNum].last_time = test_data_ptr->time;
319// }
320//
321// curr_time_us = eoy_sys_abstime_get(eoy_sys_GetHandle());
322// diff_ms = (curr_time_us - test_data_ptr->time) /1000;
323//
324//
325// if( (diff_ms >3) || (test_data_ptr->numofrecpkt != test_data_ptr->numofprocesspkt) || (test_data_ptr->exit_rx_phase_cond != proccessed_all_rec_pkt) )
326// {
327// if( (tmp->getFeat_id().boardNum == 6) || (tmp->getFeat_id().boardNum == 8) )
328// s_print_test_data(jointNum, test_data_ptr, diff_ms);
329// }
330// else
331// {
332// printf("| ");
333// fflush(stdout);
334// }
335//
336//
337// if( (tmp->j_debug_data[jointNum].pos != test_data_ptr->setpoint) && ((tmp->getFeat_id().boardNum == 6) || (tmp->getFeat_id().boardNum == 8)) )
338// {
339// printf("******* IN CBK J_STATUS %s, n=%d received pos %d instead of %d\n", tmp->getFeat_id().name, jointNum, test_data_ptr->setpoint, tmp->j_debug_data[jointNum].pos);
340// }
341
342}
343#endif
344
345// eof
346
347
348
349
embObjMotionControl : driver for iCub motor control boards EMS on a ETH bus.
static eth::TheEthManager * _interface2ethManager
eOprotEndpoint_t ep
eOprotBRD_t featIdBoardNum2nvBoardNum(FEAT_boardnumber_t fid_boardnum)
uint8_t FEAT_boardnumber_t
#define FEAT_boardnumber_dummy