Statistics
| Branch: | Tag: | Revision:

humotion / examples / yarp_icub / include / icub_jointinterface.h @ 3e3a8bd9

History | View | Annotate | Download (3.339 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
    //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 ea7a702d Simon Schulz
        //ICUB_ID_EYES_LEFT_LR,
43
        //ICUB_ID_EYES_RIGHT_LR,
44 8c6c1163 Simon Schulz
        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 ea7a702d Simon Schulz
    void set_joint_enable_state(int e, bool enabled);
69 8c6c1163 Simon Schulz
    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 ea7a702d Simon Schulz
    yarp::dev::IEncodersTimed *iencs;
85 8c6c1163 Simon Schulz
    yarp::dev::IControlLimits *ilimits;
86 ea7a702d Simon Schulz
    yarp::dev::IAmplifierControl *amp;
87
    yarp::dev::IPidControl *pid;
88
    yarp::dev::IControlMode *icontrol;
89 87b50988 Simon Schulz
    std::vector<double> last_position_error;
90
    std::vector<double> PID_P;
91
    std::vector<double> PID_D;
92 8c6c1163 Simon Schulz
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 87b50988 Simon Schulz
    void set_target_in_positionmode(int id);
102
    void set_target_in_velocitymode(int id);
103 8c6c1163 Simon Schulz
104
105
    int convert_enum_to_motorid(int e);
106
    int convert_motorid_to_enum(int id);
107
108 0d0f5ca1 Simon Schulz
    iCubFaceInterface *face_interface;
109 8c6c1163 Simon Schulz
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
};