Statistics
| Branch: | Tag: | Revision:

humotion / examples / meka / include / mekajointinterface.h @ 473a6a6c

History | View | Annotate | Download (2.617 KB)

1
#pragma once
2
#include <humotion/server/joint_interface.h>
3
#include <humotion/server/server.h>
4
#include <boost/bimap.hpp>
5
//#include "meka_data_receiver.h"
6
//class MekaDataReceiver;
7
#include "ros/ros.h"
8
#include "sensor_msgs/JointState.h"
9

    
10
class MekaJointInterface : public humotion::server::JointInterface{
11
public:
12
    MekaJointInterface(std::string scope);
13
    ~MekaJointInterface();
14

    
15
    //void fetch_position(Device *dev, double timestamp);
16
    //void fetch_speed(Device *dev, double timestamp);
17
    //void fetch_position(int id, double value, double timestamp);
18
    //void fetch_speed(int id, double value, double timestamp);
19
    void run();
20

    
21
    enum JOINT_ID_ENUM{
22
        ICUB_ID_NECK_TILT = 0,
23
        ICUB_ID_NECK_ROLL = 1,
24
        ICUB_ID_NECK_PAN  = 2,
25
        ICUB_ID_EYES_BOTH_UD = 3,
26
        ICUB_ID_EYES_PAN = 4,
27
        ICUB_ID_EYES_VERGENCE = 5,
28
        //the following ids are used for remapping:
29
        ICUB_ID_EYES_LEFT_LR,
30
        ICUB_ID_EYES_RIGHT_LR,
31
        ICUB_ID_EYES_LEFT_LID_LOWER,
32
        ICUB_ID_EYES_LEFT_LID_UPPER,
33
        ICUB_ID_EYES_RIGHT_LID_LOWER,
34
        ICUB_ID_EYES_RIGHT_LID_UPPER,
35
        ICUB_ID_EYES_LEFT_BROW,
36
        ICUB_ID_EYES_RIGHT_BROW,
37
        ICUB_ID_LIP_LEFT_UPPER,
38
        ICUB_ID_LIP_LEFT_LOWER,
39
        ICUB_ID_LIP_CENTER_UPPER,
40
        ICUB_ID_LIP_CENTER_LOWER,
41
        ICUB_ID_LIP_RIGHT_UPPER,
42
        ICUB_ID_LIP_RIGHT_LOWER,
43
        ICUB_JOINT_ID_ENUM_SIZE
44
    };
45

    
46
    static const int MAIN_LOOP_FREQUENCY = 50;
47

    
48
protected:
49
    void disable_joint(int e);
50
    void publish_target_position(int e);
51
    void enable_joint(int e);
52
    void execute_motion();
53

    
54
private:
55
    void incoming_jointstates(const sensor_msgs::JointState & msg);
56
    ros::Subscriber joint_state_subscriber;
57

    
58

    
59
    double get_timestamp_ms();
60
    double target_angle[ICUB_JOINT_ID_ENUM_SIZE];
61
    double target_angle_previous[ICUB_JOINT_ID_ENUM_SIZE];
62

    
63
    void set_eyelid_angle(double angle);
64
    void set_eyebrow_angle(int id);
65
    void set_mouth();
66

    
67
    //iCubDataReceiver *icub_data_receiver;
68
    void init_joints();
69
    double lid_angle;
70
    int lid_opening_previous;
71
    int previous_mouth_state;
72

    
73
    std::string scope;
74

    
75
    float last_pos_eye_vergence;
76
    float last_pos_eye_pan;
77
    float last_vel_eye_vergence;
78
    float last_vel_eye_pan;
79

    
80
    void store_joint(int id, float value);
81
    void set_target_in_positionmode(int id, double value);
82
    void set_target_in_velocitymode(int id, double value);
83

    
84

    
85
    int convert_enum_to_motorid(int e);
86
    int convert_motorid_to_enum(int id);
87

    
88

    
89
    typedef boost::bimap<int, int > enum_id_bimap_t;
90
    typedef enum_id_bimap_t::value_type enum_id_bimap_entry_t;
91
    enum_id_bimap_t enum_id_bimap;
92
};