Statistics
| Branch: | Tag: | Revision:

humotion / examples / yarp_icub / src / icub_data_receiver.cpp @ 4dbb1a71

History | View | Annotate | Download (1.694 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 7adf90be Simon Schulz
iCubDataReceiver::iCubDataReceiver(int period, IEncodersTimed *_iencs, iCubJointInterface *_icub_jointinterface):RateThread(period){
9 8c6c1163 Simon Schulz
    iencs = _iencs;
10
    icub_jointinterface = _icub_jointinterface;
11
    int joints;
12
    iencs->getAxes(&joints);
13
    positions.resize(joints);
14
    velocities.resize(joints);
15 7adf90be Simon Schulz
    timestamps.resize(joints);
16 8c6c1163 Simon Schulz
}
17
18
bool iCubDataReceiver::threadInit(){ return true; }
19
void iCubDataReceiver::threadRelease(){ }
20
21
double iCubDataReceiver::get_timestamp_ms(){
22
    struct timespec spec;
23
    clock_gettime(CLOCK_REALTIME, &spec);
24
    return spec.tv_sec+spec.tv_nsec/1000000000.0;
25
}
26
27
void iCubDataReceiver::run(){
28 7adf90be Simon Schulz
29 8c6c1163 Simon Schulz
    //grab pos+vel data:
30 7adf90be Simon Schulz
    iencs->getEncodersTimed(positions.data(), timestamps.data());
31 8c6c1163 Simon Schulz
    iencs->getEncoderSpeeds(velocities.data());
32 7adf90be Simon Schulz
33
    //double timestamp = get_timestamp_ms();
34 8c6c1163 Simon Schulz
35
    //publish data to humotion
36 4dbb1a71 sschulz
    printf("\nMMM");
37 8c6c1163 Simon Schulz
    for(int i=0; i<positions.size(); i++){
38 7adf90be Simon Schulz
        icub_jointinterface->fetch_position(i, positions[i], timestamps[i]);
39
        icub_jointinterface->fetch_speed(i, velocities[i], timestamps[i]);
40 55a4b313 Simon Schulz
        if (i==iCubJointInterface::ICUB_ID_NECK_PAN){
41 4dbb1a71 sschulz
            //printf("\nMMM p=%f v=%f\n",positions[i],velocities[i]);
42 55a4b313 Simon Schulz
        }
43 4dbb1a71 sschulz
        printf("%d=%f  ", i,velocities[i]);
44 8c6c1163 Simon Schulz
    }
45 4dbb1a71 sschulz
    
46
    printf("\n");
47 8c6c1163 Simon Schulz
48 0d0f5ca1 Simon Schulz
    //printf("\n%f %f %f TIME\n", get_timestamp_ms(), timestamps[2], positions[2]);
49 adf38895 Simon Schulz
    //printf("TIMEDIFF %f\n", get_timestamp_ms() - timestamps[2]);
50 0d0f5ca1 Simon Schulz
51 8c6c1163 Simon Schulz
    //tell humotion to update lid angle (hack)
52 7adf90be Simon Schulz
    icub_jointinterface->fetch_position(100, 0.0, get_timestamp_ms());
53 8c6c1163 Simon Schulz
    //fixme: use real id
54
}