Statistics
| Branch: | Tag: | Revision:

humotion / examples / yarp_icub / include / icub_jointinterface.h @ 18e9b892

History | View | Annotate | Download (3.792 KB)

1
#pragma once
2
#include <humotion/server/joint_interface.h>
3
#include <boost/bimap.hpp>
4
#include <yarp/dev/PolyDriver.h>
5
#include <yarp/dev/IControlMode.h>
6
#include <yarp/dev/IControlLimits2.h>
7
#include <yarp/dev/ControlBoardInterfaces.h>
8
#include <yarp/os/Time.h>
9
#include <yarp/sig/Vector.h>
10
#include "icub_jointinterface.h"
11
#include <humotion/server/server.h>
12
#include <yarp/os/Network.h>
13
#include <yarp/os/RateThread.h>
14
#include <yarp/os/Time.h>
15
#include <yarp/os/Property.h>
16
#include <yarp/os/Port.h>
17
#include <yarp/dev/ControlBoardInterfaces.h>
18
#include "icub_data_receiver.h"
19

    
20
class iCubDataReceiver;
21
class iCubFaceInterface;
22

    
23
class iCubJointInterface : public humotion::server::JointInterface{
24
public:
25
    iCubJointInterface(std::string scope);
26
    ~iCubJointInterface();
27

    
28
    //void store_incoming_position(int humotion_id, double position, double timestamp);
29
    //void store_incoming_velocity(int humotion_id, double position, double timestamp);
30
    void run();
31

    
32
    int convert_icub_jointid_to_humotion(int id);
33
    int convert_humotion_jointid_to_icub(int id);
34

    
35
    enum JOINT_ID_ENUM{
36
        ICUB_ID_NECK_TILT = 0,
37
        ICUB_ID_NECK_ROLL = 1,
38
        ICUB_ID_NECK_PAN  = 2,
39
        ICUB_ID_EYES_BOTH_UD = 3,
40
        ICUB_ID_EYES_PAN = 4,
41
        ICUB_ID_EYES_VERGENCE = 5,
42
        ICUB_ID_EYES_LEFT_LID_LOWER,
43
        ICUB_ID_EYES_LEFT_LID_UPPER,
44
        ICUB_ID_EYES_RIGHT_LID_LOWER,
45
        ICUB_ID_EYES_RIGHT_LID_UPPER,
46
        ICUB_ID_EYES_LEFT_BROW,
47
        ICUB_ID_EYES_RIGHT_BROW,
48
        ICUB_ID_LIP_LEFT_UPPER,
49
        ICUB_ID_LIP_LEFT_LOWER,
50
        ICUB_ID_LIP_CENTER_UPPER,
51
        ICUB_ID_LIP_CENTER_LOWER,
52
        ICUB_ID_LIP_RIGHT_UPPER,
53
        ICUB_ID_LIP_RIGHT_LOWER,
54
        ICUB_JOINT_ID_ENUM_SIZE
55
    };
56

    
57
    yarp::dev::PolyDriver *get_yarp_polydriver() { return &yarp_polydriver_; }
58

    
59
    static const int MAIN_LOOP_FREQUENCY = 50;
60

    
61
protected:
62
    void disable_joint(int e);
63
    void publish_target(int e, float position, float velocity);
64
    void enable_joint(int e);
65
    void execute_motion();
66

    
67
private:
68
    yarp::dev::PolyDriver yarp_polydriver_;
69

    
70
    std::vector<double> pv_mix_last_error_;
71
    std::vector<double> pv_mix_pid_p_;
72
    std::vector<double> pv_mix_pid_d_;
73

    
74
    // yarp views
75
    yarp::dev::IVelocityControl *yarp_ivel_;
76
    //yarp::dev::IPositionControl *yarp_ipos_;
77

    
78
    //yarp::dev::IEncodersTimed *yarp_iencs_;
79
    yarp::dev::IControlLimits *yarp_ilimits_;
80
    yarp::dev::IAmplifierControl *yarp_amp_;
81
    yarp::dev::IPidControl *yarp_pid_;
82
    yarp::dev::IControlMode *yarp_icontrol_;
83

    
84
    yarp::sig::Vector yarp_commands_;
85

    
86
    float target_angle_[ICUB_JOINT_ID_ENUM_SIZE];
87
    float target_velocity_[ICUB_JOINT_ID_ENUM_SIZE];
88

    
89

    
90
    void init_controller();
91
    void init_id_map();
92
    void init_pv_mix_pid();
93
    void insert_icupid_to_humotionid_mapping(int icubid, int humotionid);
94

    
95

    
96
    void store_icub_joint_target(int icub_id, float position, float velocity);
97

    
98
    //*******************************************
99

    
100

    
101
    void set_joint_enable_state(int e, bool enabled);
102
    //double target_angle[ICUB_JOINT_ID_ENUM_SIZE];
103
    //double target_angle_previous[ICUB_JOINT_ID_ENUM_SIZE];
104

    
105
    iCubDataReceiver *icub_data_receiver;
106
    void init_joints();
107

    
108
    std::string scope;
109
    //yarp::sig::Vector positions;
110
    //yarp::sig::Vector velocities;
111

    
112

    
113
    void store_min_max(yarp::dev::IControlLimits *ilimits, int icub_id);
114

    
115
   //float last_pos_eye_vergence;
116
    //float last_pos_eye_pan;
117
   // float last_vel_eye_vergence;
118
    //float last_vel_eye_pan;
119

    
120
    //void store_joint(int id, float value);
121
    void set_target_in_velocitymode(int id);
122

    
123

    
124
    //int convert_enum_to_motorid(int e);
125
    //int convert_motorid_to_enum(int id);
126

    
127
    iCubFaceInterface *face_interface_;
128

    
129
    typedef boost::bimap<int, int > enum_id_bimap_t;
130
    typedef enum_id_bimap_t::value_type enum_id_bimap_entry_t;
131
    enum_id_bimap_t enum_id_bimap;
132
};