Statistics
| Branch: | Tag: | Revision:

humotion / examples / yarp_icub / include / icub_jointinterface.h @ 6c028e11

History | View | Annotate | Download (3.73 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 6c028e11 Simon Schulz
    void store_incoming_position(int humotion_id, double position, double timestamp);
29 8c6c1163 Simon Schulz
    void run();
30
31 35b3ca25 Simon Schulz
    int convert_icub_jointid_to_humotion(int id);
32
    int convert_humotion_jointid_to_icub(int id);
33
34 8c6c1163 Simon Schulz
    enum JOINT_ID_ENUM{
35
        ICUB_ID_NECK_TILT = 0,
36
        ICUB_ID_NECK_ROLL = 1,
37
        ICUB_ID_NECK_PAN  = 2,
38
        ICUB_ID_EYES_BOTH_UD = 3,
39
        ICUB_ID_EYES_PAN = 4,
40
        ICUB_ID_EYES_VERGENCE = 5,
41
        ICUB_ID_EYES_LEFT_LID_LOWER,
42
        ICUB_ID_EYES_LEFT_LID_UPPER,
43
        ICUB_ID_EYES_RIGHT_LID_LOWER,
44
        ICUB_ID_EYES_RIGHT_LID_UPPER,
45
        ICUB_ID_EYES_LEFT_BROW,
46
        ICUB_ID_EYES_RIGHT_BROW,
47
        ICUB_ID_LIP_LEFT_UPPER,
48
        ICUB_ID_LIP_LEFT_LOWER,
49
        ICUB_ID_LIP_CENTER_UPPER,
50
        ICUB_ID_LIP_CENTER_LOWER,
51
        ICUB_ID_LIP_RIGHT_UPPER,
52
        ICUB_ID_LIP_RIGHT_LOWER,
53
        ICUB_JOINT_ID_ENUM_SIZE
54
    };
55
56 35b3ca25 Simon Schulz
    yarp::dev::PolyDriver *get_yarp_polydriver() { return &yarp_polydriver_; }
57
58 8c6c1163 Simon Schulz
    static const int MAIN_LOOP_FREQUENCY = 50;
59
60
protected:
61
    void disable_joint(int e);
62 35b3ca25 Simon Schulz
    void publish_target(int e, float position, float velocity);
63 8c6c1163 Simon Schulz
    void enable_joint(int e);
64
    void execute_motion();
65
66
private:
67 35b3ca25 Simon Schulz
    yarp::dev::PolyDriver yarp_polydriver_;
68
69
    std::vector<double> pv_mix_last_error_;
70
    std::vector<double> pv_mix_pid_p_;
71
    std::vector<double> pv_mix_pid_d_;
72
73
    // yarp views
74
    yarp::dev::IVelocityControl *yarp_ivel_;
75
    yarp::dev::IPositionControl *yarp_ipos_;
76
    //yarp::dev::IEncodersTimed *yarp_iencs_;
77
    yarp::dev::IControlLimits *yarp_ilimits_;
78
    yarp::dev::IAmplifierControl *yarp_amp_;
79
    yarp::dev::IPidControl *yarp_pid_;
80
    yarp::dev::IControlMode *yarp_icontrol_;
81
82
    yarp::sig::Vector yarp_commands_;
83
84
    float target_angle_[ICUB_JOINT_ID_ENUM_SIZE];
85
    float target_velocity_[ICUB_JOINT_ID_ENUM_SIZE];
86
87
88
    void init_controller();
89
    void init_id_map();
90
    void init_pv_mix_pid();
91
    void insert_icupid_to_humotionid_mapping(int icubid, int humotionid);
92
93
94
    void store_icub_joint_target(int icub_id, float position, float velocity);
95
96
    //*******************************************
97
98
99 ea7a702d Simon Schulz
    void set_joint_enable_state(int e, bool enabled);
100 35b3ca25 Simon Schulz
    //double target_angle[ICUB_JOINT_ID_ENUM_SIZE];
101
    //double target_angle_previous[ICUB_JOINT_ID_ENUM_SIZE];
102 8c6c1163 Simon Schulz
103
    iCubDataReceiver *icub_data_receiver;
104
    void init_joints();
105
106
    std::string scope;
107
    yarp::sig::Vector positions;
108
    yarp::sig::Vector velocities;
109 35b3ca25 Simon Schulz
110 8c6c1163 Simon Schulz
111
    void store_min_max(yarp::dev::IControlLimits *ilimits, int id, int e);
112
113
    float last_pos_eye_vergence;
114
    float last_pos_eye_pan;
115
    float last_vel_eye_vergence;
116
    float last_vel_eye_pan;
117
118
    void store_joint(int id, float value);
119 87b50988 Simon Schulz
    void set_target_in_positionmode(int id);
120
    void set_target_in_velocitymode(int id);
121 8c6c1163 Simon Schulz
122
123
    int convert_enum_to_motorid(int e);
124
    int convert_motorid_to_enum(int id);
125
126 35b3ca25 Simon Schulz
    iCubFaceInterface *face_interface_;
127 8c6c1163 Simon Schulz
128
    typedef boost::bimap<int, int > enum_id_bimap_t;
129
    typedef enum_id_bimap_t::value_type enum_id_bimap_entry_t;
130
    enum_id_bimap_t enum_id_bimap;
131
};