Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (3.234 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
#include <yarp/dev/IControlLimits2.h>
6
#include <yarp/dev/ControlBoardInterfaces.h>
7
#include <yarp/os/Time.h>
8
#include <yarp/sig/Vector.h>
9
#include "icub_jointinterface.h"
10
#include <humotion/server/server.h>
11
#include <yarp/os/Network.h>
12
#include <yarp/os/RateThread.h>
13
#include <yarp/os/Time.h>
14
#include <yarp/os/Property.h>
15
#include <yarp/os/Port.h>
16
#include <yarp/dev/ControlBoardInterfaces.h>
17
#include "icub_data_receiver.h"
18
19
class iCubDataReceiver;
20
21
class iCubJointInterface : public humotion::server::JointInterface{
22
public:
23
    iCubJointInterface(std::string scope);
24
    ~iCubJointInterface();
25
26
    //void fetch_position(Device *dev, double timestamp);
27
    //void fetch_speed(Device *dev, double timestamp);
28
    void fetch_position(int id, double value, double timestamp);
29
    void fetch_speed(int id, double value, double timestamp);
30
    void run();
31
32
    enum JOINT_ID_ENUM{
33
        ICUB_ID_NECK_TILT = 0,
34
        ICUB_ID_NECK_ROLL = 1,
35
        ICUB_ID_NECK_PAN  = 2,
36
        ICUB_ID_EYES_BOTH_UD = 3,
37
        ICUB_ID_EYES_PAN = 4,
38
        ICUB_ID_EYES_VERGENCE = 5,
39
        //the following ids are used for remapping:
40
        ICUB_ID_EYES_LEFT_LR,
41
        ICUB_ID_EYES_RIGHT_LR,
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
    static const int MAIN_LOOP_FREQUENCY = 50;
58
59
protected:
60
    void disable_joint(int e);
61
    void publish_target_position(int e);
62
    void enable_joint(int e);
63
    void execute_motion();
64
65
private:
66
    double get_timestamp_ms();
67
    double target_angle[ICUB_JOINT_ID_ENUM_SIZE];
68
    double target_angle_previous[ICUB_JOINT_ID_ENUM_SIZE];
69
70
    void set_eyelid_angle(double angle);
71
    void set_eyebrow_angle(int id);
72
    void set_mouth();
73
74
    iCubDataReceiver *icub_data_receiver;
75
    void init_joints();
76
    double lid_angle;
77
    int lid_opening_previous;
78
    int previous_mouth_state;
79
80
    std::string scope;
81
    yarp::dev::PolyDriver dd;
82
    yarp::sig::Vector positions;
83
    yarp::sig::Vector velocities;
84
    yarp::sig::Vector commands;
85
86
    yarp::os::BufferedPort<yarp::os::Bottle> emotion_port[4];
87
88
    yarp::dev::IVelocityControl *ivel;
89
    yarp::dev::IPositionControl *ipos;
90
    yarp::dev::IEncoders *iencs;
91
    yarp::dev::IControlLimits *ilimits;
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, double value);
102
    void set_target_in_velocitymode(int id, double value);
103
104
105
    int convert_enum_to_motorid(int e);
106
    int convert_motorid_to_enum(int id);
107
108
109
    typedef boost::bimap<int, int > enum_id_bimap_t;
110
    typedef enum_id_bimap_t::value_type enum_id_bimap_entry_t;
111
    enum_id_bimap_t enum_id_bimap;
112
};