Statistics
| Branch: | Tag: | Revision:

humotion / examples / yarp_icub / include / icub_jointinterface.h @ ea29304b

History | View | Annotate | Download (3.818 KB)

1 8c6c1163 Simon Schulz
#pragma once
2
#include <humotion/server/joint_interface.h>
3
#include <boost/bimap.hpp>
4
#include <yarp/dev/PolyDriver.h>
5 ea7a702d Simon Schulz
#include <yarp/dev/IControlMode.h>
6 8c6c1163 Simon Schulz
#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 0d0f5ca1 Simon Schulz
class iCubFaceInterface;
22 8c6c1163 Simon Schulz
23
class iCubJointInterface : public humotion::server::JointInterface{
24
public:
25
    iCubJointInterface(std::string scope);
26
    ~iCubJointInterface();
27
28 ea29304b Simon Schulz
    //void store_incoming_position(int humotion_id, double position, double timestamp);
29
    //void store_incoming_velocity(int humotion_id, double position, double timestamp);
30 8c6c1163 Simon Schulz
    void run();
31
32 35b3ca25 Simon Schulz
    int convert_icub_jointid_to_humotion(int id);
33
    int convert_humotion_jointid_to_icub(int id);
34
35 8c6c1163 Simon Schulz
    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 35b3ca25 Simon Schulz
    yarp::dev::PolyDriver *get_yarp_polydriver() { return &yarp_polydriver_; }
58
59 8c6c1163 Simon Schulz
    static const int MAIN_LOOP_FREQUENCY = 50;
60
61
protected:
62
    void disable_joint(int e);
63 35b3ca25 Simon Schulz
    void publish_target(int e, float position, float velocity);
64 8c6c1163 Simon Schulz
    void enable_joint(int e);
65
    void execute_motion();
66
67
private:
68 35b3ca25 Simon Schulz
    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
    //yarp::dev::IEncodersTimed *yarp_iencs_;
78
    yarp::dev::IControlLimits *yarp_ilimits_;
79
    yarp::dev::IAmplifierControl *yarp_amp_;
80
    yarp::dev::IPidControl *yarp_pid_;
81
    yarp::dev::IControlMode *yarp_icontrol_;
82
83
    yarp::sig::Vector yarp_commands_;
84
85
    float target_angle_[ICUB_JOINT_ID_ENUM_SIZE];
86
    float target_velocity_[ICUB_JOINT_ID_ENUM_SIZE];
87
88
89
    void init_controller();
90
    void init_id_map();
91
    void init_pv_mix_pid();
92
    void insert_icupid_to_humotionid_mapping(int icubid, int humotionid);
93
94
95
    void store_icub_joint_target(int icub_id, float position, float velocity);
96
97
    //*******************************************
98
99
100 ea7a702d Simon Schulz
    void set_joint_enable_state(int e, bool enabled);
101 35b3ca25 Simon Schulz
    //double target_angle[ICUB_JOINT_ID_ENUM_SIZE];
102
    //double target_angle_previous[ICUB_JOINT_ID_ENUM_SIZE];
103 8c6c1163 Simon Schulz
104
    iCubDataReceiver *icub_data_receiver;
105
    void init_joints();
106
107
    std::string scope;
108
    yarp::sig::Vector positions;
109
    yarp::sig::Vector velocities;
110 35b3ca25 Simon Schulz
111 8c6c1163 Simon Schulz
112
    void store_min_max(yarp::dev::IControlLimits *ilimits, int id, int e);
113
114
    float last_pos_eye_vergence;
115
    float last_pos_eye_pan;
116
    float last_vel_eye_vergence;
117
    float last_vel_eye_pan;
118
119
    void store_joint(int id, float value);
120 87b50988 Simon Schulz
    void set_target_in_positionmode(int id);
121
    void set_target_in_velocitymode(int id);
122 8c6c1163 Simon Schulz
123
124
    int convert_enum_to_motorid(int e);
125
    int convert_motorid_to_enum(int id);
126
127 35b3ca25 Simon Schulz
    iCubFaceInterface *face_interface_;
128 8c6c1163 Simon Schulz
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
};