Statistics
| Branch: | Tag: | Revision:

humotion / examples / yarp_icub / include / icub_jointinterface.h @ 8136fb72

History | View | Annotate | Download (3.339 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 fetch_position(Device *dev, double timestamp);
29
    //void fetch_speed(Device *dev, double timestamp);
30
    void fetch_position(int id, double value, double timestamp);
31
    void fetch_speed(int id, double value, double timestamp);
32
    void run();
33

    
34
    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
        //the following ids are used for remapping:
42
        //ICUB_ID_EYES_LEFT_LR,
43
        //ICUB_ID_EYES_RIGHT_LR,
44
        ICUB_ID_EYES_LEFT_LID_LOWER,
45
        ICUB_ID_EYES_LEFT_LID_UPPER,
46
        ICUB_ID_EYES_RIGHT_LID_LOWER,
47
        ICUB_ID_EYES_RIGHT_LID_UPPER,
48
        ICUB_ID_EYES_LEFT_BROW,
49
        ICUB_ID_EYES_RIGHT_BROW,
50
        ICUB_ID_LIP_LEFT_UPPER,
51
        ICUB_ID_LIP_LEFT_LOWER,
52
        ICUB_ID_LIP_CENTER_UPPER,
53
        ICUB_ID_LIP_CENTER_LOWER,
54
        ICUB_ID_LIP_RIGHT_UPPER,
55
        ICUB_ID_LIP_RIGHT_LOWER,
56
        ICUB_JOINT_ID_ENUM_SIZE
57
    };
58

    
59
    static const int MAIN_LOOP_FREQUENCY = 50;
60

    
61
protected:
62
    void disable_joint(int e);
63
    void publish_target_position(int e);
64
    void enable_joint(int e);
65
    void execute_motion();
66

    
67
private:
68
    void set_joint_enable_state(int e, bool enabled);
69
    double get_timestamp_ms();
70
    double target_angle[ICUB_JOINT_ID_ENUM_SIZE];
71
    double target_angle_previous[ICUB_JOINT_ID_ENUM_SIZE];
72

    
73
    iCubDataReceiver *icub_data_receiver;
74
    void init_joints();
75

    
76
    std::string scope;
77
    yarp::dev::PolyDriver dd;
78
    yarp::sig::Vector positions;
79
    yarp::sig::Vector velocities;
80
    yarp::sig::Vector commands;
81

    
82
    yarp::dev::IVelocityControl *ivel;
83
    yarp::dev::IPositionControl *ipos;
84
    yarp::dev::IEncodersTimed *iencs;
85
    yarp::dev::IControlLimits *ilimits;
86
    yarp::dev::IAmplifierControl *amp;
87
    yarp::dev::IPidControl *pid;
88
    yarp::dev::IControlMode *icontrol;
89
    std::vector<double> last_position_error;
90
    std::vector<double> PID_P;
91
    std::vector<double> PID_D;
92

    
93
    void store_min_max(yarp::dev::IControlLimits *ilimits, int id, int e);
94

    
95
    float last_pos_eye_vergence;
96
    float last_pos_eye_pan;
97
    float last_vel_eye_vergence;
98
    float last_vel_eye_pan;
99

    
100
    void store_joint(int id, float value);
101
    void set_target_in_positionmode(int id);
102
    void set_target_in_velocitymode(int id);
103

    
104

    
105
    int convert_enum_to_motorid(int e);
106
    int convert_motorid_to_enum(int id);
107

    
108
    iCubFaceInterface *face_interface;
109

    
110
    typedef boost::bimap<int, int > enum_id_bimap_t;
111
    typedef enum_id_bimap_t::value_type enum_id_bimap_entry_t;
112
    enum_id_bimap_t enum_id_bimap;
113
};