humotion / examples / yarp_icub / src / icub_data_receiver.cpp @ 5f29f640
History | View | Annotate | Download (1.25 KB)
1 | 8c6c1163 | Simon Schulz | #include "icub_data_receiver.h" |
---|---|---|---|
2 | #include <yarp/os/Property.h> |
||
3 | using namespace yarp::dev; |
||
4 | using namespace yarp::sig; |
||
5 | using namespace yarp::os; |
||
6 | using namespace std; |
||
7 | |||
8 | iCubDataReceiver::iCubDataReceiver(int period, IEncoders *_iencs, iCubJointInterface *_icub_jointinterface):RateThread(period){
|
||
9 | iencs = _iencs; |
||
10 | icub_jointinterface = _icub_jointinterface; |
||
11 | int joints;
|
||
12 | iencs->getAxes(&joints); |
||
13 | positions.resize(joints); |
||
14 | velocities.resize(joints); |
||
15 | } |
||
16 | |||
17 | bool iCubDataReceiver::threadInit(){ return true; } |
||
18 | void iCubDataReceiver::threadRelease(){ }
|
||
19 | |||
20 | double iCubDataReceiver::get_timestamp_ms(){
|
||
21 | struct timespec spec;
|
||
22 | clock_gettime(CLOCK_REALTIME, &spec); |
||
23 | return spec.tv_sec+spec.tv_nsec/1000000000.0; |
||
24 | } |
||
25 | |||
26 | void iCubDataReceiver::run(){
|
||
27 | //grab pos+vel data:
|
||
28 | iencs->getEncoders(positions.data()); |
||
29 | iencs->getEncoderSpeeds(velocities.data()); |
||
30 | double timestamp = get_timestamp_ms();
|
||
31 | |||
32 | //publish data to humotion
|
||
33 | for(int i=0; i<positions.size(); i++){ |
||
34 | icub_jointinterface->fetch_position(i, positions[i], timestamp); |
||
35 | icub_jointinterface->fetch_speed(i, velocities[i], timestamp); |
||
36 | } |
||
37 | |||
38 | //tell humotion to update lid angle (hack)
|
||
39 | icub_jointinterface->fetch_position(100, 0.0, timestamp); |
||
40 | //fixme: use real id
|
||
41 | } |