Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (3.438 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

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

    
27
    //void fetch_position(Device *dev, double timestamp);
28
    //void fetch_speed(Device *dev, double timestamp);
29
    void fetch_position(int id, double value, double timestamp);
30
    void fetch_speed(int id, double value, double timestamp);
31
    void run();
32

    
33
    enum JOINT_ID_ENUM{
34
        ICUB_ID_NECK_TILT = 0,
35
        ICUB_ID_NECK_ROLL = 1,
36
        ICUB_ID_NECK_PAN  = 2,
37
        ICUB_ID_EYES_BOTH_UD = 3,
38
        ICUB_ID_EYES_PAN = 4,
39
        ICUB_ID_EYES_VERGENCE = 5,
40
        //the following ids are used for remapping:
41
        //ICUB_ID_EYES_LEFT_LR,
42
        //ICUB_ID_EYES_RIGHT_LR,
43
        ICUB_ID_EYES_LEFT_LID_LOWER,
44
        ICUB_ID_EYES_LEFT_LID_UPPER,
45
        ICUB_ID_EYES_RIGHT_LID_LOWER,
46
        ICUB_ID_EYES_RIGHT_LID_UPPER,
47
        ICUB_ID_EYES_LEFT_BROW,
48
        ICUB_ID_EYES_RIGHT_BROW,
49
        ICUB_ID_LIP_LEFT_UPPER,
50
        ICUB_ID_LIP_LEFT_LOWER,
51
        ICUB_ID_LIP_CENTER_UPPER,
52
        ICUB_ID_LIP_CENTER_LOWER,
53
        ICUB_ID_LIP_RIGHT_UPPER,
54
        ICUB_ID_LIP_RIGHT_LOWER,
55
        ICUB_JOINT_ID_ENUM_SIZE
56
    };
57

    
58
    static const int MAIN_LOOP_FREQUENCY = 50;
59

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

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

    
72
    void set_eyelid_angle(double angle);
73
    void set_eyebrow_angle(int id);
74
    void set_mouth();
75

    
76
    iCubDataReceiver *icub_data_receiver;
77
    void init_joints();
78
    double lid_angle;
79
    int lid_opening_previous;
80
    int previous_mouth_state;
81

    
82
    std::string scope;
83
    yarp::dev::PolyDriver dd;
84
    yarp::sig::Vector positions;
85
    yarp::sig::Vector velocities;
86
    yarp::sig::Vector commands;
87

    
88
    yarp::os::BufferedPort<yarp::os::Bottle> emotion_port[4];
89

    
90
    yarp::dev::IVelocityControl *ivel;
91
    yarp::dev::IPositionControl *ipos;
92
    yarp::dev::IEncodersTimed *iencs;
93
    yarp::dev::IControlLimits *ilimits;
94
    yarp::dev::IAmplifierControl *amp;
95
    yarp::dev::IPidControl *pid;
96
    yarp::dev::IControlMode *icontrol;
97

    
98
    void store_min_max(yarp::dev::IControlLimits *ilimits, int id, int e);
99

    
100
    float last_pos_eye_vergence;
101
    float last_pos_eye_pan;
102
    float last_vel_eye_vergence;
103
    float last_vel_eye_pan;
104

    
105
    void store_joint(int id, float value);
106
    void set_target_in_positionmode(int id, double value);
107
    void set_target_in_velocitymode(int id, double value);
108

    
109

    
110
    int convert_enum_to_motorid(int e);
111
    int convert_motorid_to_enum(int id);
112

    
113

    
114
    typedef boost::bimap<int, int > enum_id_bimap_t;
115
    typedef enum_id_bimap_t::value_type enum_id_bimap_entry_t;
116
    enum_id_bimap_t enum_id_bimap;
117
};