Revision 6a2d467f

View differences:

examples/humotion_meka/CMakeLists.txt
1
PROJECT(meka_humotion_server)
2
cmake_minimum_required(VERSION 2.8)
3
SET(MAIN ${PROJECT_NAME})
4

  
5
set(ENV{ROS_LANG_DISABLE} "genjava")
6
set(ROS_BUILD_TYPE Debug)
7

  
8
################################################################
9
# check for ROS support:
10
find_package(catkin REQUIRED COMPONENTS roscpp std_msgs sensor_msgs message_generation genmsg)
11
IF (catkin_FOUND)
12
    set(ROS_FOUND 1)
13
    message(STATUS "ROS Support is ON")
14
    add_definitions(-DROS_SUPPORT=1)
15
ENDIF (catkin_FOUND)
16

  
17
IF (NOT catkin_FOUND)
18
  message(FATAL_ERROR "Error: could not find ROS!")
19
ENDIF ()
20

  
21
FIND_PACKAGE(Boost REQUIRED COMPONENTS system thread)
22
FIND_PACKAGE(humotion)
23

  
24
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
25
#add_message_files(
26
#    FILES
27
#)
28

  
29
#generate_messages(
30
#    DEPENDENCIES
31
#    std_msgs
32
#)
33

  
34
#hack to allow sub dir calls work
35

  
36
catkin_package(
37
    INCLUDE_DIRS include
38
    LIBRARIES humotion
39
    #CATKIN_DEPENDS message_runtime
40
    #DEPENDS system_lib
41
)
42

  
43
include_directories( ${catkin_INCLUDE_DIRS})
44

  
45
# add include directories
46
INCLUDE_DIRECTORIES(${YARP_INCLUDE_DIRS} ${ICUB_INCLUDE_DIRS} ${humotion_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} include/)
47
link_directories(${Boost_LIBRARY_DIRS} ${humotion_LIBRARY_DIRS})
48

  
49
# add required linker flags
50

  
51
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ICUB_LINK_FLAGS}")
52
file(GLOB DUMMY_HEADER_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} include/*.h)
53

  
54
#add_dependencies(${MAIN} ${catkin_EXPORTED_TARGETS})
55
ADD_EXECUTABLE(${MAIN} src/main.cpp src/mekajointinterface.cpp ${DUMMY_HEADER_LIST})
56

  
57
TARGET_LINK_LIBRARIES(${MAIN} ${Boost_LIBRARIES} ${catkin_LIBRARIES} ${humotion_LIBRARIES})
58
set_property(TARGET ${MAIN} PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
59

  
60

  
61
#INSTALL(TARGETS ${MAIN} DESTINATION bin)
62
install(TARGETS ${MAIN}
63
    ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
64
    LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
65
    RUNTIME DESTINATION bin 
66
)
67

  
examples/humotion_meka/include/mekajointinterface.h
1
#pragma once
2
#include <humotion/server/joint_interface.h>
3
#include <humotion/server/server.h>
4
#include <boost/bimap.hpp>
5
//#include "meka_data_receiver.h"
6
//class MekaDataReceiver;
7
#include "ros/ros.h"
8
#include "sensor_msgs/JointState.h"
9
#include "trajectory_msgs/JointTrajectory.h"
10
#include <m3meka_msgs/M3ControlStates.h>
11

  
12
class MekaJointInterface : public humotion::server::JointInterface{
13
public:
14
    MekaJointInterface(std::string _input_scope, std::string control_scope, std::string _output_scope);
15
    ~MekaJointInterface();
16

  
17
    //void fetch_position(Device *dev, double timestamp);
18
    //void fetch_speed(Device *dev, double timestamp);
19
    //void fetch_position(int id, double value, double timestamp);
20
    //void fetch_speed(int id, double value, double timestamp);
21
    void run();
22

  
23
    static const int MAIN_LOOP_FREQUENCY = 50;
24

  
25
protected:
26
    void disable_joint(int e);
27
    void publish_target(int e, float position, float velocity);
28
    void enable_joint(int e);
29
    void execute_motion();
30

  
31
private:
32
    void incoming_controlstate(const m3meka_msgs::M3ControlStates &control_state);
33
    void incoming_jointstates(const sensor_msgs::JointState & msg);
34
    void store_dummy_data(int id, double timestamp);
35
    void store_min_max(int id, float min, float max);
36
    ros::Subscriber joint_state_subscriber;
37
    ros::Subscriber control_state_subscriber;
38
    ros::Publisher target_publisher;
39

  
40
    double get_timestamp_s();
41

  
42
    void set_eyelid_angle(double angle);
43
    void set_eyebrow_angle(int id);
44
    void set_mouth();
45

  
46
    //iCubDataReceiver *icub_data_receiver;
47
    void init_joints();
48
    double lid_angle;
49
    int lid_opening_previous;
50
    int previous_mouth_state;
51

  
52
    std::string input_scope;
53
    std::string control_scope;
54
    std::string output_scope;
55

  
56
    float last_pos_eye_vergence;
57
    float last_pos_eye_pan;
58
    float last_vel_eye_vergence;
59
    float last_vel_eye_pan;
60

  
61
    bool controller_enabled;
62

  
63
    void store_joint(int id, float value);
64
    void set_target_in_positionmode(int id, double value);
65
    void set_target_in_velocitymode(int id, double value);
66

  
67

  
68
    int convert_enum_to_motorid(int e);
69
    int convert_motorid_to_enum(int id);
70

  
71

  
72
    typedef boost::bimap<int, int > enum_id_bimap_t;
73
    typedef enum_id_bimap_t::value_type enum_id_bimap_entry_t;
74
    enum_id_bimap_t enum_id_bimap;
75
};
examples/humotion_meka/package.xml
1
<?xml version="1.0"?>
2
<package>
3
  <name>meka_humotion_server</name>
4
  <version>0.0.1</version>
5
  <description>humotion server for the mekabot</description>
6

  
7
  <!-- One maintainer tag required, multiple allowed, one person per tag --> 
8
  <maintainer email="sschulz@todo.todo">Simon Schulz</maintainer>
9

  
10

  
11
  <!-- One license tag required, multiple allowed, one license per tag -->
12
  <!-- Commonly used license strings: -->
13
  <!--   BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
14
  <license>TODO</license>
15

  
16

  
17
  <!-- Url tags are optional, but mutiple are allowed, one per tag -->
18
  <!-- Optional attribute type can be: website, bugtracker, or repository -->
19
  <!-- Example: -->
20
  <url type="website">https://projects.cit-ec.uni-bielefeld.de/git/flobidev.core.git</url> -->
21

  
22

  
23
  <!-- Author tags are optional, mutiple are allowed, one per tag -->
24
  <!-- Authors do not have to be maintianers, but could be -->
25
  <!-- Example: -->
26
  <!-- <author email="jane.doe@example.com">Jane Doe</author> -->
27

  
28

  
29
  <!-- The *_depend tags are used to specify dependencies -->
30
  <!-- Dependencies can be catkin packages or system dependencies -->
31
  <!-- Examples: -->
32
  <!-- Use build_depend for packages you need at compile time: -->
33
  <!-- Use buildtool_depend for build tool packages: -->
34
  <!--   <buildtool_depend>catkin</buildtool_depend> -->
35
  <!-- Use run_depend for packages you need at runtime: -->
36
  <!-- <run_depend>message_runtime</run_depend> -->
37
  <!-- Use test_depend for packages you need only for testing: -->
38
  <!--   <test_depend>gtest</test_depend> -->
39
  <buildtool_depend>catkin</buildtool_depend>
40
  <build_depend>roscpp</build_depend>
41
  <build_depend>std_msgs</build_depend>
42
  <!-- <run_depend>roscpp</run_depend> -->
43
  <!-- <run_depend>std_msgs</run_depend> -->
44

  
45
  <!--<build_depend>actionlib</build_depend>
46
  <build_depend>actionlib_msgs</build_depend>
47
  <run_depend>actionlib</run_depend> -->
48
  <!-- <run_depend>actionlib_msgs</run_depend> -->
49

  
50
  <!-- The export tag contains other, unspecified, tags -->
51
  <export>
52
    <!-- You can specify that this package is a metapackage here: -->
53
    <!-- <metapackage/> -->
54

  
55
    <!-- Other tools can request additional information be placed here -->
56

  
57
  </export>
58
</package>
examples/humotion_meka/src/main.cpp
1
#include <stdio.h>
2
#include <humotion/server/server.h>
3
#include <string>
4
#include <iostream>
5
//#include "meka_data_receiver.h"
6
#include "mekajointinterface.h"
7

  
8
using namespace std;
9

  
10
int main(int argc, char *argv[]){
11
    /*Property params;
12
    params.fromCommand(argc, argv);
13

  
14
    if (!params.check("robot")){
15
        fprintf(stderr, "Please specify the name of the robot\n");
16
        fprintf(stderr, "--robot name (e.g. icub or icubSim)\n");
17
        return -1;
18
    }
19

  
20
    string robotName=params.find("robot").asString().c_str();
21
    string scope="/"+robotName;
22

  
23
*/
24

  
25
    if (argc != 5){
26
        printf("> ERROR: invalid number of parameters passed to server!\n\n");
27
        printf("usage   : %s <humotion base topic> <jointstates topic> <controlstates topic> <control output topic>\n\n",argv[0]);
28
        printf("example : %s /meka /joint_states  /meka_roscontrol_state_manager/state /meka_roscontrol/head_position_trajectory_controller/command)\n\n",argv[0]);
29
        exit(EXIT_FAILURE);
30
    }
31

  
32
    //create humotion interface
33
    string humotion_scope      = argv[1];
34
    string jointstates_scope   = argv[2];
35
    string controlstates_scope = argv[3];
36
    string control_scope       = argv[4];
37

  
38

  
39
    MekaJointInterface *jointinterface = new MekaJointInterface(jointstates_scope, controlstates_scope, control_scope);
40
    humotion::server::Server *humotion_server = new humotion::server::Server(humotion_scope, "ROS", jointinterface);
41

  
42
    //finally run it
43
    jointinterface->run();
44

  
45
    while(humotion_server->ok()){
46
        usleep(100000);
47
    }
48

  
49
    printf("> ros connection died, will exit now\n");
50

  
51
    return 0;
52
}
examples/humotion_meka/src/mekajointinterface.cpp
1
#include "mekajointinterface.h"
2
using namespace std;
3

  
4
//WARNING: DO NOT CHANGE THIS; VELOCITYMODE IS NOT YET IMPLEMENTED
5
#define POSITION_CONTROL 1
6

  
7
void MekaJointInterface::incoming_controlstate(const m3meka_msgs::M3ControlStates &control_state){
8
    //incoming controller status
9
    for (unsigned int i = 0; i<control_state.group_name.size(); i++){
10
        if (control_state.group_name[i] == "head"){
11
            //enable/disable based on controller status
12
            if (control_state.state[i] == m3meka_msgs::M3ControlStates::START){
13
                //controller up and running
14
                if (!controller_enabled){
15
                    printf("> incoming control state (%d), enabling jointstate output\n",control_state.state[i]);
16
                    controller_enabled = true;
17
                }
18
            }else{
19
                //controller in estop/stopped etc
20
                if (controller_enabled){
21
                    printf("> incoming control state (%d), DISABLING jointstate output\n",control_state.state[i]);
22
                    controller_enabled = false;
23
                }
24
            }
25
        }
26
    }
27
}
28

  
29
void MekaJointInterface::incoming_jointstates(const sensor_msgs::JointState & msg){
30
    //fetch current timestamp
31
    double timestamp = msg.header.stamp.toSec();
32

  
33
    //iterate through incoming joints and filter out joints we need:
34
    for(int i=0; i<msg.name.size(); i++){
35

  
36
        string name = msg.name[i];
37
        //printf("incoming data for joint '%s'\n", name.c_str());
38

  
39
        int id = -1;
40
        if (name == "head_j1"){
41
            id = ID_NECK_PAN;
42
        }else if(name == "head_j0"){
43
            id = ID_NECK_TILT;
44
        }
45

  
46
        //store data:
47
        if (id != -1){
48
            //printf("> storing joint data for joint id %d\n", id);
49
            if (i >= msg.position.size()){
50
                printf("> joint state msg is missing position data for joint '%s'...\n", name.c_str());
51
                return;
52
            }
53
            if (i >= msg.velocity.size()){
54
                //printf("> joint state msg is missing velocity data for joint '%s'...\n", name.c_str());
55
                //exit(EXIT_FAILURE);
56
                return;
57
            }
58
            //ok, safe to access data
59
            if (id == ID_NECK_PAN){
60
                //joint is inverted
61
                JointInterface::store_incoming_position(id, -180.0 / M_PI * msg.position[i], timestamp);
62
                JointInterface::store_incoming_speed(   id, -180.0 / M_PI * msg.velocity[i], timestamp);
63
            }else if (id == ID_NECK_TILT){
64
                JointInterface::store_incoming_position(id, 180.0 / M_PI * msg.position[i], timestamp);
65
                JointInterface::store_incoming_speed(   id, 180.0 / M_PI * msg.velocity[i], timestamp);
66
            }
67
        }
68
    }
69

  
70
    //dummy data uses current time
71
    timestamp = get_timestamp_s();
72

  
73
    //store dummy positions for joints we do not know about:
74
    store_dummy_data(ID_LIP_LEFT_UPPER, timestamp);
75
    store_dummy_data(ID_LIP_LEFT_LOWER, timestamp);
76
    store_dummy_data(ID_LIP_CENTER_UPPER, timestamp);
77
    store_dummy_data(ID_LIP_CENTER_LOWER, timestamp);
78
    store_dummy_data(ID_LIP_RIGHT_UPPER, timestamp);
79
    store_dummy_data(ID_LIP_RIGHT_LOWER, timestamp);
80

  
81
    store_dummy_data(ID_NECK_ROLL, timestamp);
82
    store_dummy_data(ID_EYES_BOTH_UD, timestamp);
83
    store_dummy_data(ID_EYES_LEFT_LR, timestamp);
84
    store_dummy_data(ID_EYES_RIGHT_LR, timestamp);
85
    store_dummy_data(ID_EYES_LEFT_LID_LOWER, timestamp);
86
    store_dummy_data(ID_EYES_LEFT_LID_UPPER, timestamp);
87
    store_dummy_data(ID_EYES_LEFT_BROW, timestamp);
88
    store_dummy_data(ID_EYES_RIGHT_LID_LOWER, timestamp);
89
    store_dummy_data(ID_EYES_RIGHT_LID_UPPER, timestamp);
90
    store_dummy_data(ID_EYES_RIGHT_BROW, timestamp);
91

  
92
}
93

  
94
void MekaJointInterface::store_dummy_data(int id, double timestamp){
95
    JointInterface::store_incoming_position(id, 0.0, timestamp);
96
    JointInterface::store_incoming_speed(id, 0.0, timestamp);
97
}
98

  
99
//! constructor
100
MekaJointInterface::MekaJointInterface(string _input_scope, string control_scope, string _output_scope) : humotion::server::JointInterface(){
101
    input_scope = _input_scope;
102
    output_scope = _output_scope;
103

  
104
    controller_enabled = false;
105

  
106
    //subscribe to meka joint states
107
    int argc = 0;
108
    ros::init(argc, (char**)NULL, "meka_humotion");
109
    ros::NodeHandle n;
110

  
111
    printf("> listening on jointstates on '%s'\n",input_scope.c_str());
112
    joint_state_subscriber = n.subscribe(input_scope, 150, &MekaJointInterface::incoming_jointstates, this);
113

  
114
    printf("> listening on controlstates on '%s'\n",control_scope.c_str());
115
    control_state_subscriber = n.subscribe(control_scope, 150, &MekaJointInterface::incoming_controlstate, this);
116

  
117
    printf("> sending targets on '%s'\n", output_scope.c_str());
118
    target_publisher = n.advertise<trajectory_msgs::JointTrajectory>(output_scope, 100);
119

  
120
    //tell humotion about min/max joint values:
121
    init_joints();
122
}
123

  
124
//! destructor
125
MekaJointInterface::~MekaJointInterface(){
126
}
127

  
128

  
129

  
130
void MekaJointInterface::run(){
131
   ros::spin();
132
}
133

  
134

  
135
double MekaJointInterface::get_timestamp_s(){
136
    struct timespec spec;
137
    clock_gettime(CLOCK_REALTIME, &spec);
138
    return spec.tv_sec + spec.tv_nsec / 1.0e9;
139
}
140

  
141
//! set the target position of a joint
142
//! \param enum id of joint
143
//! \param float value
144
void MekaJointInterface::publish_target(int e, float position, float velocity){
145
   //we do this in execute motion for all joints at once...
146
}
147

  
148

  
149
//! actually execute the scheduled motion commands
150
void MekaJointInterface::execute_motion(){
151
    if (controller_enabled){
152
        //build msg
153
        trajectory_msgs::JointTrajectory msg;
154
        msg.joint_names.push_back("head_j0");
155
        msg.joint_names.push_back("head_j1");
156

  
157
        trajectory_msgs::JointTrajectoryPoint p;
158
        p.positions.push_back(get_target_position(ID_NECK_TILT) * M_PI / 180.0);
159
        //pan joint is inverted!
160
        p.positions.push_back(-get_target_position(ID_NECK_PAN) * M_PI / 180.0);
161
        //printf("targets pan=%4.1f tilt=%4.1f (eye p %4.1f t %4.2f)\n",joint_target[ID_NECK_TILT],joint_target[ID_NECK_PAN],joint_target[ID_EYES_LEFT_LR],joint_target[ID_EYES_BOTH_UD]);
162

  
163
        p.time_from_start = ros::Duration(1.2 * 1.0 / humotion::server::Server::MOTION_UPDATERATE);
164

  
165
        msg.points.push_back(p);
166

  
167
        target_publisher.publish(msg);
168
    }
169
}
170

  
171

  
172
//! prepare and enable a joint
173
//! NOTE: this should also prefill the min/max positions for this joint
174
//! \param the enum id of a joint
175
void MekaJointInterface::enable_joint(int e){
176
    //meka does not support this, joints are always enabled
177
}
178

  
179
//! shutdown and disable a joint
180
//! \param the enum id of a joint
181
void MekaJointInterface::disable_joint(int e){
182
    //meka does not support this, joints are always enabled
183
}
184

  
185
void MekaJointInterface::store_min_max(int id, float min, float max){
186
    joint_min[id] = min;
187
    joint_max[id] = max;
188
}
189

  
190
void MekaJointInterface::init_joints(){
191
    store_min_max(ID_NECK_TILT, -37, 1);
192
    store_min_max(ID_NECK_PAN, -70, 70);
193

  
194
    store_min_max(ID_NECK_ROLL, -1, 1);
195
    store_min_max(ID_EYES_BOTH_UD, -1, 1);
196
    store_min_max(ID_EYES_LEFT_LR, -1, 1);
197
    store_min_max(ID_EYES_RIGHT_LR, -1, 1);
198
    store_min_max(ID_EYES_LEFT_LID_UPPER, -1, 1);
199
    store_min_max(ID_EYES_LEFT_LID_LOWER, -1, 1);
200
    store_min_max(ID_EYES_RIGHT_LID_UPPER, -1, 1);
201
    store_min_max(ID_EYES_RIGHT_LID_LOWER, -1, 1);
202
    store_min_max(ID_EYES_LEFT_BROW, -1, 1);
203
    store_min_max(ID_EYES_RIGHT_BROW, -1, 1);
204
    store_min_max(ID_LIP_CENTER_UPPER, -1, 1);
205
    store_min_max(ID_LIP_CENTER_LOWER, -1, 1);
206
    store_min_max(ID_LIP_LEFT_UPPER, -1, 1);
207
    store_min_max(ID_LIP_LEFT_LOWER, -1, 1);
208
    store_min_max(ID_LIP_RIGHT_UPPER, -1, 1);
209
    store_min_max(ID_LIP_RIGHT_LOWER, -1, 1);
210
}
211

  
examples/humotion_yarp_icub/CMakeLists.txt
1
PROJECT(humotion_yarp_icub)
2
cmake_minimum_required(VERSION 2.8)
3

  
4
FIND_PACKAGE(YARP)
5
FIND_PACKAGE(ICUB)
6
FIND_PACKAGE(Boost REQUIRED COMPONENTS system thread)
7
FIND_PACKAGE(humotion)
8

  
9
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
10

  
11
# add include directories
12
INCLUDE_DIRECTORIES(${YARP_INCLUDE_DIRS} ${ICUB_INCLUDE_DIRS} ${humotion_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} include/)
13
link_directories(${Boost_LIBRARY_DIRS} ${humotion_LIBRARY_DIRS})
14

  
15
# add required linker flags
16
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ICUB_LINK_FLAGS}")
17
SET(MAIN icub_humotion_server)
18

  
19
file(GLOB DUMMY_HEADER_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} include/*.h)
20

  
21
ADD_EXECUTABLE(${MAIN} src/main.cpp src/icub_jointinterface.cpp src/icub_faceinterface.cpp src/icub_data_receiver.cpp ${DUMMY_HEADER_LIST})
22

  
23
# we now add the YARP and iCub libraries to our project.
24
TARGET_LINK_LIBRARIES(${MAIN} ${Boost_LIBRARIES} ${YARP_LIBRARIES} ${ICUB_LIBRARIES} ${humotion_LIBRARIES})
25
set_property(TARGET ${MAIN} PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
26

  
27
INSTALL(TARGETS ${MAIN} DESTINATION bin)
28

  
29

  
30
#############
31
## style guide ##
32
#############
33
set(ENABLE_CPPLINT 1)
34
include(${CMAKE_CURRENT_SOURCE_DIR}/../../stylecheck/CpplintWrapper.cmake)
35
CPPLINT_RECURSIVE(cpplint_include
36
  ${CMAKE_CURRENT_SOURCE_DIR}/include
37
  ${CMAKE_CURRENT_SOURCE_DIR}/include
38
  ${CMAKE_CURRENT_BINARY_DIR}/include)
39
CPPLINT_RECURSIVE(cpplint_src
40
  ${CMAKE_CURRENT_SOURCE_DIR}/src
41
  ${CMAKE_CURRENT_SOURCE_DIR}/src
42
  ${CMAKE_CURRENT_BINARY_DIR}/src)
43
add_dependencies(${MAIN} cpplint_src cpplint_include)
44

  
45
#workaround for qtcreator ide integration. do not remove!
46
file(GLOB_RECURSE NODE_DUMMY_TARGETS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.h *.cfg *.yaml *.xml *.launch)
47
add_custom_target(_dummy_target SOURCES ${NODE_DUMMY_TARGETS})
48

  
examples/humotion_yarp_icub/CMakeLists.txt.user
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE QtCreatorProject>
3
<!-- Written by QtCreator 3.0.1, 2016-02-15T14:37:35. -->
4
<qtcreator>
5
 <data>
6
  <variable>ProjectExplorer.Project.ActiveTarget</variable>
7
  <value type="int">0</value>
8
 </data>
9
 <data>
10
  <variable>ProjectExplorer.Project.EditorSettings</variable>
11
  <valuemap type="QVariantMap">
12
   <value type="bool" key="EditorConfiguration.AutoIndent">true</value>
13
   <value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
14
   <value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
15
   <valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
16
    <value type="QString" key="language">Cpp</value>
17
    <valuemap type="QVariantMap" key="value">
18
     <value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
19
    </valuemap>
20
   </valuemap>
21
   <valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
22
    <value type="QString" key="language">QmlJS</value>
23
    <valuemap type="QVariantMap" key="value">
24
     <value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
25
    </valuemap>
26
   </valuemap>
27
   <value type="int" key="EditorConfiguration.CodeStyle.Count">2</value>
28
   <value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
29
   <value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
30
   <value type="int" key="EditorConfiguration.IndentSize">4</value>
31
   <value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
32
   <value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
33
   <value type="int" key="EditorConfiguration.PaddingMode">1</value>
34
   <value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
35
   <value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
36
   <value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
37
   <value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
38
   <value type="int" key="EditorConfiguration.TabSize">8</value>
39
   <value type="bool" key="EditorConfiguration.UseGlobal">true</value>
40
   <value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
41
   <value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
42
   <value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
43
   <value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
44
   <value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
45
  </valuemap>
46
 </data>
47
 <data>
48
  <variable>ProjectExplorer.Project.PluginSettings</variable>
49
  <valuemap type="QVariantMap"/>
50
 </data>
51
 <data>
52
  <variable>ProjectExplorer.Project.Target.0</variable>
53
  <valuemap type="QVariantMap">
54
   <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop</value>
55
   <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop</value>
56
   <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{0ff36a7d-682d-4601-a9c1-275f77eefc70}</value>
57
   <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
58
   <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
59
   <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
60
   <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
61
    <value type="bool" key="CMakeProjectManager.CMakeBuildConfiguration.UseNinja">false</value>
62
    <value type="QString" key="CMakeProjectManager.CMakeBuildConfiguration.UserArguments">-DCMAKE_INSTALL_PREFIX=/vol/icub/sschulz/releases/roman16-humotion-nightly/</value>
63
    <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/homes/sschulz/src/flobi/humotion/examples/hum </value>
64
    <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
65
     <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
66
      <value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value>
67
      <valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets"/>
68
      <value type="bool" key="CMakeProjectManager.MakeStep.Clean">false</value>
69
      <value type="bool" key="CMakeProjectManager.MakeStep.UseNinja">false</value>
70
      <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
71
      <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
72
      <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
73
      <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
74
     </valuemap>
75
     <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
76
     <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
77
     <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
78
     <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
79
    </valuemap>
80
    <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
81
     <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
82
      <value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments">clean</value>
83
      <valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets"/>
84
      <value type="bool" key="CMakeProjectManager.MakeStep.Clean">true</value>
85
      <value type="bool" key="CMakeProjectManager.MakeStep.UseNinja">false</value>
86
      <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
87
      <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
88
      <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
89
      <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
90
     </valuemap>
91
     <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
92
     <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
93
     <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
94
     <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
95
    </valuemap>
96
    <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
97
    <value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
98
    <valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
99
    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Default</value>
100
    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Default</value>
101
    <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
102
   </valuemap>
103
   <value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
104
   <valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
105
    <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
106
     <value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
107
     <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
108
     <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
109
     <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
110
    </valuemap>
111
    <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
112
    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy locally</value>
113
    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
114
    <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
115
   </valuemap>
116
   <value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
117
   <valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/>
118
   <valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
119
    <valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
120
    <value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
121
    <value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
122
    <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
123
    <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
124
    <value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
125
    <value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
126
    <value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
127
    <value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
128
    <value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">1</value>
129
    <value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
130
    <valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
131
    <value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">1</value>
132
    <value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
133
    <value type="bool" key="Analyzer.Valgrind.ShowReachable">false</value>
134
    <value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
135
    <value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value>
136
    <valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
137
     <value type="int">0</value>
138
     <value type="int">1</value>
139
     <value type="int">2</value>
140
     <value type="int">3</value>
141
     <value type="int">4</value>
142
     <value type="int">5</value>
143
     <value type="int">6</value>
144
     <value type="int">7</value>
145
     <value type="int">8</value>
146
     <value type="int">9</value>
147
     <value type="int">10</value>
148
     <value type="int">11</value>
149
     <value type="int">12</value>
150
     <value type="int">13</value>
151
     <value type="int">14</value>
152
    </valuelist>
153
    <value type="QString" key="CMakeProjectManager.CMakeRunConfiguation.Title">icub_humotion_server</value>
154
    <value type="QString" key="CMakeProjectManager.CMakeRunConfiguration.Arguments"></value>
155
    <value type="bool" key="CMakeProjectManager.CMakeRunConfiguration.UseTerminal">false</value>
156
    <value type="QString" key="CMakeProjectManager.CMakeRunConfiguration.UserWorkingDirectory"></value>
157
    <value type="int" key="PE.EnvironmentAspect.Base">2</value>
158
    <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
159
    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">icub_humotion_server</value>
160
    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
161
    <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeRunConfiguration.icub_humotion_server</value>
162
    <value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
163
    <value type="bool" key="RunConfiguration.UseCppDebugger">true</value>
164
    <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">false</value>
165
    <value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
166
    <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
167
    <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
168
   </valuemap>
169
   <value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
170
  </valuemap>
171
 </data>
172
 <data>
173
  <variable>ProjectExplorer.Project.TargetCount</variable>
174
  <value type="int">1</value>
175
 </data>
176
 <data>
177
  <variable>ProjectExplorer.Project.Updater.EnvironmentId</variable>
178
  <value type="QByteArray">{44110186-3313-405d-bf42-c546b33c1fcb}</value>
179
 </data>
180
 <data>
181
  <variable>ProjectExplorer.Project.Updater.FileVersion</variable>
182
  <value type="int">15</value>
183
 </data>
184
</qtcreator>
examples/humotion_yarp_icub/include/humotion_yarp_icub/icub_data_receiver.h
1
/*
2
* This file is part of humotion
3
*
4
* Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
* http://opensource.cit-ec.de/projects/humotion
6
*
7
* This file may be licensed under the terms of the
8
* GNU Lesser General Public License Version 3 (the ``LGPL''),
9
* or (at your option) any later version.
10
*
11
* Software distributed under the License is distributed
12
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
* express or implied. See the LGPL for the specific language
14
* governing rights and limitations.
15
*
16
* You should have received a copy of the LGPL along with this
17
* program. If not, go to http://www.gnu.org/licenses/lgpl.html
18
* or write to the Free Software Foundation, Inc.,
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
*
21
* The development of this software was supported by the
22
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
* The Excellence Cluster EXC 277 is a grant of the Deutsche
24
* Forschungsgemeinschaft (DFG) in the context of the German
25
* Excellence Initiative.
26
*/
27

  
28
#ifndef EXAMPLES_YARP_ICUB_INCLUDE_ICUB_DATA_RECEIVER_H_
29
#define EXAMPLES_YARP_ICUB_INCLUDE_ICUB_DATA_RECEIVER_H_
30

  
31
#include <humotion/server/joint_interface.h>
32
#include <humotion/server/server.h>
33

  
34
#include <boost/bimap.hpp>
35
#include <yarp/dev/ControlBoardInterfaces.h>
36
#include <yarp/dev/IControlLimits2.h>
37
#include <yarp/dev/PolyDriver.h>
38
#include <yarp/os/Network.h>
39
#include <yarp/os/Property.h>
40
#include <yarp/os/RateThread.h>
41
#include <yarp/os/Time.h>
42
#include <yarp/sig/Vector.h>
43

  
44
#include "icub_humotion/icub_jointinterface.h"
45

  
46
// forward declaration to solve loop
47
class iCubJointInterface;
48

  
49
class iCubDataReceiver : public yarp::os::RateThread{
50
public:
51
    iCubDataReceiver(int period, iCubJointInterface *icub_jointinterface);
52
    bool threadInit();
53
    void threadRelease();
54
    void run();
55
private:
56
    void store_incoming_position(int icub_id, double value, double timestamp);
57
    void store_incoming_velocity(int icub_id, double velocity, double timestamp);
58
    yarp::sig::Vector calculate_velocities(yarp::sig::Vector positions,
59
                              yarp::sig::Vector timestamps);
60

  
61
    void dump_incoming_data();
62

  
63
    float target_eye_pan_;
64
    float target_eye_vergence_;
65

  
66
    float target_eye_pan_velocity_;
67
    float target_eye_vergence_velocity_;
68

  
69
    yarp::sig::Vector positions_;
70
    yarp::sig::Vector timestamps_;
71
    yarp::sig::Vector velocities_;
72
    yarp::sig::Vector commands_;
73

  
74
    yarp::sig::Vector previous_positions_;
75
    yarp::sig::Vector previous_timestamps_;
76

  
77
    iCubJointInterface *icub_jointinterface_;
78
    yarp::dev::IEncodersTimed *iencs_;
79
};
80

  
81
#endif  // EXAMPLES_YARP_ICUB_INCLUDE_ICUB_DATA_RECEIVER_H_
examples/humotion_yarp_icub/include/humotion_yarp_icub/icub_faceinterface.h
1
/*
2
* This file is part of humotion
3
*
4
* Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
* http://opensource.cit-ec.de/projects/humotion
6
*
7
* This file may be licensed under the terms of the
8
* GNU Lesser General Public License Version 3 (the ``LGPL''),
9
* or (at your option) any later version.
10
*
11
* Software distributed under the License is distributed
12
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
* express or implied. See the LGPL for the specific language
14
* governing rights and limitations.
15
*
16
* You should have received a copy of the LGPL along with this
17
* program. If not, go to http://www.gnu.org/licenses/lgpl.html
18
* or write to the Free Software Foundation, Inc.,
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
*
21
* The development of this software was supported by the
22
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
* The Excellence Cluster EXC 277 is a grant of the Deutsche
24
* Forschungsgemeinschaft (DFG) in the context of the German
25
* Excellence Initiative.
26
*/
27
#pragma once
28
#include <yarp/dev/ControlBoardInterfaces.h>
29
#include <yarp/os/Network.h>
30
#include "icub_jointinterface.h"
31
/*
32
 * #include <humotion/server/server.h>
33
#include <yarp/os/RateThread.h>
34
#include <yarp/os/Time.h>
35
#include <yarp/os/Property.h>
36
#include <yarp/os/Port.h>
37
#include <yarp/dev/ControlBoardInterfaces.h>
38
#include "icub_data_receiver.h"
39
*/
40

  
41

  
42
class iCubFaceInterface {
43
public:
44
    iCubFaceInterface(std::string scope);
45
    ~iCubFaceInterface();
46

  
47

  
48
    void set_eyelid_angle(float angle);
49
    void set_eyebrow_angle(int id, float *target_angle);
50
    void set_mouth(float *target_angle);
51

  
52
private:
53
    double lid_angle;
54
    int lid_opening_previous;
55
    int previous_mouth_state;
56
    double target_angle_previous[iCubJointInterface::ICUB_JOINT_ID_ENUM_SIZE];
57
    std::string scope;
58
    yarp::os::BufferedPort<yarp::os::Bottle> emotion_port[4];
59

  
60
};
examples/humotion_yarp_icub/include/humotion_yarp_icub/icub_jointinterface.h
1
/*
2
* This file is part of humotion
3
*
4
* Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
* http://opensource.cit-ec.de/projects/humotion
6
*
7
* This file may be licensed under the terms of the
8
* GNU Lesser General Public License Version 3 (the ``LGPL''),
9
* or (at your option) any later version.
10
*
11
* Software distributed under the License is distributed
12
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
* express or implied. See the LGPL for the specific language
14
* governing rights and limitations.
15
*
16
* You should have received a copy of the LGPL along with this
17
* program. If not, go to http://www.gnu.org/licenses/lgpl.html
18
* or write to the Free Software Foundation, Inc.,
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
*
21
* The development of this software was supported by the
22
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
* The Excellence Cluster EXC 277 is a grant of the Deutsche
24
* Forschungsgemeinschaft (DFG) in the context of the German
25
* Excellence Initiative.
26
*/
27

  
28
#pragma once
29
#include <humotion/server/joint_interface.h>
30
#include <boost/bimap.hpp>
31
#include <yarp/dev/PolyDriver.h>
32
#include <yarp/dev/IControlMode.h>
33
#include <yarp/dev/IControlLimits2.h>
34
#include <yarp/dev/ControlBoardInterfaces.h>
35
#include <yarp/os/Time.h>
36
#include <yarp/sig/Vector.h>
37
#include "icub_jointinterface.h"
38
#include <humotion/server/server.h>
39
#include <yarp/os/Network.h>
40
#include <yarp/os/RateThread.h>
41
#include <yarp/os/Time.h>
42
#include <yarp/os/Property.h>
43
#include <yarp/os/Port.h>
44
#include <yarp/dev/ControlBoardInterfaces.h>
45
#include "icub_data_receiver.h"
46

  
47
class iCubDataReceiver;
48
class iCubFaceInterface;
49

  
50
class iCubJointInterface : public humotion::server::JointInterface{
51
public:
52
    iCubJointInterface(std::string scope);
53
    ~iCubJointInterface();
54

  
55
    //void store_incoming_position(int humotion_id, double position, double timestamp);
56
    //void store_incoming_velocity(int humotion_id, double position, double timestamp);
57
    void run();
58

  
59
    int convert_icub_jointid_to_humotion(int id);
60
    int convert_humotion_jointid_to_icub(int id);
61

  
62
    enum JOINT_ID_ENUM{
63
        ICUB_ID_NECK_TILT = 0,
64
        ICUB_ID_NECK_ROLL = 1,
65
        ICUB_ID_NECK_PAN  = 2,
66
        ICUB_ID_EYES_BOTH_UD = 3,
67
        ICUB_ID_EYES_PAN = 4,
68
        ICUB_ID_EYES_VERGENCE = 5,
69
        ICUB_ID_EYES_LEFT_LID_LOWER,
70
        ICUB_ID_EYES_LEFT_LID_UPPER,
71
        ICUB_ID_EYES_RIGHT_LID_LOWER,
72
        ICUB_ID_EYES_RIGHT_LID_UPPER,
73
        ICUB_ID_EYES_LEFT_BROW,
74
        ICUB_ID_EYES_RIGHT_BROW,
75
        ICUB_ID_LIP_LEFT_UPPER,
76
        ICUB_ID_LIP_LEFT_LOWER,
77
        ICUB_ID_LIP_CENTER_UPPER,
78
        ICUB_ID_LIP_CENTER_LOWER,
79
        ICUB_ID_LIP_RIGHT_UPPER,
80
        ICUB_ID_LIP_RIGHT_LOWER,
81
        ICUB_JOINT_ID_ENUM_SIZE
82
    };
83

  
84
    yarp::dev::PolyDriver *get_yarp_polydriver() { return &yarp_polydriver_; }
85

  
86
    static const int MAIN_LOOP_FREQUENCY = 50;
87

  
88
protected:
89
    void disable_joint(int e);
90
    void publish_target(int e, float position, float velocity);
91
    void enable_joint(int e);
92
    void execute_motion();
93

  
94
private:
95
    yarp::dev::PolyDriver yarp_polydriver_;
96

  
97
    std::vector<double> pv_mix_last_error_;
98
    std::vector<double> pv_mix_pid_p_;
99
    std::vector<double> pv_mix_pid_d_;
100

  
101
    // yarp views
102
    yarp::dev::IVelocityControl *yarp_ivel_;
103
    //yarp::dev::IPositionControl *yarp_ipos_;
104

  
105
    //yarp::dev::IEncodersTimed *yarp_iencs_;
106
    yarp::dev::IControlLimits *yarp_ilimits_;
107
    yarp::dev::IAmplifierControl *yarp_amp_;
108
    yarp::dev::IPidControl *yarp_pid_;
109
    yarp::dev::IControlMode *yarp_icontrol_;
110

  
111
    yarp::sig::Vector yarp_commands_;
112

  
113
    float target_angle_[ICUB_JOINT_ID_ENUM_SIZE];
114
    float target_velocity_[ICUB_JOINT_ID_ENUM_SIZE];
115

  
116

  
117
    void init_controller();
118
    void init_id_map();
119
    void init_pv_mix_pid();
120
    void insert_icupid_to_humotionid_mapping(int icubid, int humotionid);
121

  
122

  
123
    void store_icub_joint_target(int icub_id, float position, float velocity);
124

  
125
    //*******************************************
126

  
127

  
128
    void set_joint_enable_state(int e, bool enabled);
129
    //double target_angle[ICUB_JOINT_ID_ENUM_SIZE];
130
    //double target_angle_previous[ICUB_JOINT_ID_ENUM_SIZE];
131

  
132
    iCubDataReceiver *icub_data_receiver;
133
    void init_joints();
134

  
135
    std::string scope;
136
    //yarp::sig::Vector positions;
137
    //yarp::sig::Vector velocities;
138

  
139

  
140
    void store_min_max(yarp::dev::IControlLimits *ilimits, int icub_id);
141

  
142
   //float last_pos_eye_vergence;
143
    //float last_pos_eye_pan;
144
   // float last_vel_eye_vergence;
145
    //float last_vel_eye_pan;
146

  
147
    //void store_joint(int id, float value);
148
    void set_target_in_velocitymode(int id);
149

  
150

  
151
    //int convert_enum_to_motorid(int e);
152
    //int convert_motorid_to_enum(int id);
153

  
154
    iCubFaceInterface *face_interface_;
155

  
156
    typedef boost::bimap<int, int > enum_id_bimap_t;
157
    typedef enum_id_bimap_t::value_type enum_id_bimap_entry_t;
158
    enum_id_bimap_t enum_id_bimap;
159
};
examples/humotion_yarp_icub/src/icub_data_receiver.cpp
1
/*
2
* This file is part of humotion
3
*
4
* Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
* http://opensource.cit-ec.de/projects/humotion
6
*
7
* This file may be licensed under the terms of the
8
* GNU Lesser General Public License Version 3 (the ``LGPL''),
9
* or (at your option) any later version.
10
*
11
* Software distributed under the License is distributed
12
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
* express or implied. See the LGPL for the specific language
14
* governing rights and limitations.
15
*
16
* You should have received a copy of the LGPL along with this
17
* program. If not, go to http://www.gnu.org/licenses/lgpl.html
18
* or write to the Free Software Foundation, Inc.,
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
*
21
* The development of this software was supported by the
22
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
* The Excellence Cluster EXC 277 is a grant of the Deutsche
24
* Forschungsgemeinschaft (DFG) in the context of the German
25
* Excellence Initiative.
26
*/
27

  
28
#include <boost/format.hpp>
29
#include <humotion/server/joint_interface.h>
30
#include <yarp/os/Property.h>
31

  
32
#include "humotion_yarp_icub/icub_data_receiver.h"
33

  
34
using std::cout;
35
using std::cerr;
36
using std::string;
37
using humotion::server::JointInterface;
38
using yarp::dev::IEncodersTimed;
39
using yarp::sig::Vector;
40

  
41
#define ICUB_DATA_RECEIVER_USE_ENCODERSPEED 0
42
#define ICUB_DATA_RECEIVER_DUMP_DATA 0
43

  
44
//! constructor
45
//! \param period_ms for the yarp rate thread
46
//! \param icub_jointinterface
47
iCubDataReceiver::iCubDataReceiver(int period_ms, iCubJointInterface *icub_jointinterface)
48
    : yarp::os::RateThread(period_ms) {
49

  
50
    // store pointer to icub jointinterface
51
    icub_jointinterface_ = icub_jointinterface;
52

  
53
    // fetch iencs view from yarp
54
    yarp::dev::PolyDriver *poly_driver = icub_jointinterface->get_yarp_polydriver();
55
    bool success = poly_driver->view(iencs_);
56
    if (!success) {
57
        cerr << "ERROR: polydriver failed to init iencs view\n";
58
        exit(EXIT_FAILURE);
59
    }
60

  
61
    // resize data storage vectors to match the number of axes
62
    int joints;
63
    iencs_->getAxes(&joints);
64
    positions_.resize(joints);
65
    velocities_.resize(joints);
66
    timestamps_.resize(joints);
67
}
68

  
69
//! yarp rate thread initializer
70
bool iCubDataReceiver::threadInit() {
71
    return true;
72
}
73

  
74
//! yarp thread release function
75
void iCubDataReceiver::threadRelease() {
76
}
77

  
78
//! manully calculate joint velocities (instead of using joint encoder speeds)
79
//! \param positions vector with current encoder position
80
//! \param timestamps vector with the associated timestamps
81
//! \return velocities as vector
82
Vector iCubDataReceiver::calculate_velocities(Vector positions, Vector timestamps) {
83
    Vector velocities;
84
    velocities.resize(positions.size());
85

  
86
    if (previous_positions_.size() == 0) {
87
        // first run, no valid old position available, return zero velocities
88
        // by setting all all elements to zero
89
        velocities = 0.0;
90
    } else {
91
        // calculate speed based on positions:
92
        for (int i=0; i < positions.size(); i++) {
93
            float diff = positions[i] - previous_positions_[i];
94
            float timediff = timestamps[i] - previous_timestamps_[i];
95
            // calc speed:
96
            velocities[i] = diff / timediff;
97
        }
98
    }
99

  
100
    previous_positions_ = positions;
101
    previous_timestamps_ = timestamps;
102

  
103
    return velocities;
104
}
105

  
106
//! main loop routine, called by yarp rate thread
107
void iCubDataReceiver::run() {
108
    float velocity;
109

  
110
    // grab pos+vel data:
111
    iencs_->getEncodersTimed(positions_.data(), timestamps_.data());
112

  
113
    #if ICUB_DATA_RECEIVER_USE_ENCODERSPEED
114
    // fetch data from icub. NOTE: make sure to enable the vel broadcast in the ini file!
115
    if (!iencs_->getEncoderSpeeds(velocities_.data())) {
116
        cout << "Failed to fetch encoder speeds...\n";
117
        return;
118
    }
119
    #else
120
    // manually calculate the speed based on old position:
121
    velocities_ = calculate_velocities(positions_, timestamps_);
122
    #endif
123

  
124
    // publish data to humotion
125
    for (int i = 0; i < positions_.size(); i++) {
126
        // store position values
127
        store_incoming_position(i, positions_[i], timestamps_[i]);
128
        // store velocity
129
        store_incoming_velocity(i, velocities_[i], timestamps_[i]);
130
    }
131

  
132
    // small hack to tell humotion to update the lid angle
133
    // fixme: use real id
134
    store_incoming_position(100, 0.0, timestamps_[0]);
135

  
136
    #if ICUB_DATA_RECEIVER_DUMP_DATA
137
    dump_incoming_data();
138
    #endif
139
}
140

  
141
//! store incoming position for a given icub joint
142
//! \param icub _id icub joint id
143
//! \param position
144
//! \param timestamp
145
void iCubDataReceiver::store_incoming_position(int icub_id, double position, double timestamp) {
146
    //cout << "store_incoming_position(icub=" << icub_id << ", " << position << ")\n";
147

  
148
    // store joint position in humotion backend
149
    if ((icub_id == iCubJointInterface::ICUB_ID_EYES_PAN) ||
150
            (icub_id == iCubJointInterface::ICUB_ID_EYES_VERGENCE)) {
151
        // the icub handles eyes differently
152
        // instead of using seperate left/right pan the icub uses
153
        // a combined pan angle and vergence. therfore we have to convert this here:
154
        if (icub_id == iCubJointInterface::ICUB_ID_EYES_PAN) {
155
            target_eye_pan_ = position;
156
        } else {
157
            target_eye_vergence_ = -position;
158
        }
159

  
160
        float right = target_eye_pan_ + target_eye_vergence_/2.0;
161
        float left  = target_eye_pan_ - target_eye_vergence_/2.0;
162

  
163
        icub_jointinterface_->store_incoming_position(JointInterface::ID_EYES_LEFT_LR,
164
                                                     left, timestamp);
165
        icub_jointinterface_->store_incoming_position(JointInterface::ID_EYES_RIGHT_LR,
166
                                                     right, timestamp);
167
    } else if (icub_id == 100) {
168
        //HACK
169
        //icub_jointinterface->store_incoming_position(ID_EYES_RIGHT_LID_UPPER,
170
        //                                             lid_angle, timestamp);
171
    } else {
172
        if (icub_id == iCubJointInterface::ID_NECK_PAN) {
173
            // icub uses an inverted neck pan specification
174
            position = -position;
175
        }
176

  
177
        // known configured mapping between joint ids
178
        int humotion_id = icub_jointinterface_->convert_icub_jointid_to_humotion(icub_id);
179
        icub_jointinterface_->store_incoming_position(humotion_id, position, timestamp);
180
    }
181
}
182

  
183
//! store incoming velocity for a given icub joint
184
//! \param icub_id icub joint id
185
//! \param velocity
186
//! \param timestamp
187
void iCubDataReceiver::store_incoming_velocity(int icub_id, double velocity, double timestamp) {
188
    //cout << "store_incoming_velocity(icub=" << icub_id << ", " << velocity << ")\n";
189

  
190
    // store joint position in humotion backend
191
    if ((icub_id == iCubJointInterface::ICUB_ID_EYES_PAN) ||
192
            (icub_id == iCubJointInterface::ICUB_ID_EYES_VERGENCE)) {
193
        // the icub handles eyes differently
194
        // instead of using seperate left/right pan the icub uses
195
        // a combined pan angle and vergence. therfore we have to convert this here:
196
        if (icub_id == iCubJointInterface::ICUB_ID_EYES_PAN) {
197
            target_eye_pan_velocity_ = velocity;
198
        } else {
199
            target_eye_vergence_velocity_ = -velocity;
200
        }
201

  
202
        float right = target_eye_pan_velocity_ + target_eye_vergence_velocity_/2.0;
203
        float left  = target_eye_pan_velocity_ - target_eye_vergence_velocity_/2.0;
204

  
205
        icub_jointinterface_->store_incoming_velocity(JointInterface::ID_EYES_LEFT_LR,
206
                                                     left, timestamp);
207
        icub_jointinterface_->store_incoming_velocity(JointInterface::ID_EYES_RIGHT_LR,
208
                                                     right, timestamp);
209
    } else if (icub_id == 100) {
210
        //HACK
211
        //icub_jointinterface->store_incoming_position(ID_EYES_RIGHT_LID_UPPER,
212
        //                                             lid_angle, timestamp);
213
    } else {
214
        if (icub_id == iCubJointInterface::ID_NECK_PAN) {
215
            // icub uses an inverted neck pan specification
216
            velocity = -velocity;
217
        }
218

  
219
        // known configured mapping between joint ids
220
        int humotion_id = icub_jointinterface_->convert_icub_jointid_to_humotion(icub_id);
221
        icub_jointinterface_->store_incoming_velocity(humotion_id, velocity, timestamp);
222
    }
223
}
224

  
225
//! helper for debugging purposes, feed this data into gnuplot for visual inspection
226
void iCubDataReceiver::dump_incoming_data() {
227
    // use gnuplot for viz:
228
    // ./icub_humotion_server --robot icub | grep "INCOMING" |tee  log
229
    // @gnuplot: plot "log" using 0:1 w l t "p neck tilt", "log" using 0:2 w l t "v neck tilt", \
230
    //                "log" using 0:5 w l t "p neck pan", "log" using 0:6 w l t "v neck pan", \
231
    //                "log" using 0:7 w l t "p eyes ud", "log" using 0:8 w l t "v eyes ud", \
232
    //                "log" using 0:9 w l t "p eyes vergence", "log" using 0:10 w l t "v eyes vergence"
233
    cout << "\n";
234
            // publish data to humotion
235
    for(int i=0; i<positions_.size(); i++){
236
        cout << positions_[i] << " ";
237
        cout << velocities_[i] << " ";
238
    }
239
    cout << " #INCOMING_DATA_DUMP\n";
240
}
241

  
242

  
examples/humotion_yarp_icub/src/icub_faceinterface.cpp
1
/*
2
* This file is part of humotion
3
*
4
* Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
5
* http://opensource.cit-ec.de/projects/humotion
6
*
7
* This file may be licensed under the terms of the
8
* GNU Lesser General Public License Version 3 (the ``LGPL''),
9
* or (at your option) any later version.
10
*
11
* Software distributed under the License is distributed
12
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
* express or implied. See the LGPL for the specific language
14
* governing rights and limitations.
15
*
16
* You should have received a copy of the LGPL along with this
17
* program. If not, go to http://www.gnu.org/licenses/lgpl.html
18
* or write to the Free Software Foundation, Inc.,
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
*
21
* The development of this software was supported by the
22
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
23
* The Excellence Cluster EXC 277 is a grant of the Deutsche
24
* Forschungsgemeinschaft (DFG) in the context of the German
25
* Excellence Initiative.
26
*/
27

  
28
#include "humotion_yarp_icub/icub_faceinterface.h"
29

  
30
#include <algorithm>
31
#include <string>
32
#include <boost/format.hpp>
33

  
34
using yarp::os::Network;
35
using yarp::os::Bottle;
36
using std::cout;
37
using std::cerr;
38
using std::string;
39

  
40
//! constructor
41
iCubFaceInterface::iCubFaceInterface(std::string _scope) {
42
    scope = _scope;
43

  
44
    // attach to facial expressions:
45
    std::string emotion_scope = scope + "/face/raw/in";
46
    cout << "opening connection to '"<< emotion_scope << "'\n";
47

  
48
    for (int i = 0; i < 4; i++) {
49
        // strange, if we use one output port only the first command is executed?! flushing issues?
50
        std::string emotion_port_out = "/emotionwriter" + std::to_string((unsigned long long)i);
51
        if (!emotion_port[i].open(emotion_port_out.c_str())) {
52
            cerr << "ERROR: failed to open emotion port '" << emotion_port_out << "'\n";
53
            exit(EXIT_FAILURE);
54
        }
55
        if (!Network::connect(emotion_port_out.c_str(), emotion_scope.c_str())) {
56
            cerr << "ERROR: failed to connect to emotion port '" << emotion_port_out << "'\n";
57
            exit(EXIT_FAILURE);
58
        }
59
    }
60
}
61

  
62
//! destructor
63
iCubFaceInterface::~iCubFaceInterface() {
64
}
65

  
66
//! special command to set eyelid angle
67
//! \param angle in degrees
68
void iCubFaceInterface::set_eyelid_angle(float angle) {
69
    if (emotion_port[0].getOutputCount() > 0) {
70
        // try to set the value based on the upper one
71
        // some guesses from the sim: S30 = 0° / S40 = 10°
72
        int opening = (25.0 + 0.8*angle);
73
        opening = std::min(48, std::max(24, opening));
74

  
75
        if (opening == lid_opening_previous) {
76
            // no update necessary
77
            return;
78
        }
79

  
80
        lid_angle = angle;
81
        lid_opening_previous = opening;
82

  
83
        char buf[20];
84
        snprintf(buf, sizeof(buf), "S%2d", opening);
85

  
86
        // cout << "SETTING EYELID '" << buf << "' (" << angle << " -> " << opening << "\n";
87
        Bottle &cmd = emotion_port[0].prepare();
88
        cmd.clear();
89
        cmd.addString(buf);
90
        emotion_port[0].writeStrict();
91
    } else {
92
        cerr << "ERROR: no icub emotion output\n";
93
        exit(EXIT_FAILURE);
94
    }
95
}
96

  
97
//! special command to set the eyebrow angle
98
//! \param id {0=left, 1=right)
99
//! \param angle in degrees
100
void iCubFaceInterface::set_eyebrow_angle(int id, float *target_angle) {
101
    int port_id;
102
    if (id == iCubJointInterface::ICUB_ID_EYES_LEFT_BROW) {
103
        port_id = 1;
104
    } else {
105
        port_id = 2;
106
    }
107

  
108
    if (emotion_port[port_id].getOutputCount() > 0) {
109
        double angle = target_angle[id];
110
        int icub_val = 0;
111

  
112
        // swap rotation direction for eyebrow
113
        if (id == iCubJointInterface::ICUB_ID_EYES_LEFT_BROW) {
114
            angle = -angle;
115
        }
116

  
117
        // convert to icub representation
118
        if (angle < -20) {
119
            icub_val = 1;
120
        } else if (angle < 10) {
121
            icub_val = 2;
122
        } else if (angle < 20) {
123
            icub_val = 4;
124
        } else {
125
            icub_val = 8;
126
        }
127

  
128
        // make sure to update only on new values
129
        if (icub_val == target_angle_previous[id]) {
130
                // no updata necessary
131
                return;
132
        }
133

  
134
        // store actual value
135
        target_angle_previous[id] = icub_val;
136

  
137

  
138
        std::string cmd_s;
139
        if (id == iCubJointInterface::ICUB_ID_EYES_LEFT_BROW) {
140
            cmd_s = "L0" + std::to_string((unsigned long long)icub_val);
141
        } else {
142
            cmd_s = "R0" + std::to_string((unsigned long long)icub_val);
143
        }
144

  
145
        cout << "SETTING EYEBROW " << id << " (" << angle << " -> " << cmd_s << ")\n";
146

  
147
        Bottle &cmd = emotion_port[port_id].prepare();
148
        cmd.clear();
149
        cmd.addString(cmd_s);
150
        emotion_port[port_id].writeStrict();
151
    } else {
152
        cerr << "ERROR: no icub emotion output\n";
153
        exit(EXIT_FAILURE);
154
    }
155
}
156

  
157
void iCubFaceInterface::set_mouth(float *target_angle) {
158
    // convert from 6DOF mouth displacement to icub leds:
159
    int led_value = 0;
160

  
161
    // fetch center opening
162
    double center_opening = target_angle[iCubJointInterface::ICUB_ID_LIP_CENTER_LOWER] -
163
            target_angle[iCubJointInterface::ICUB_ID_LIP_CENTER_UPPER];
164
    bool mouth_open = (center_opening > 15.0) ? true : false;
165

  
166
    // side of mouth high or low?
167
    double center_avg = (target_angle[iCubJointInterface::ICUB_ID_LIP_CENTER_LOWER] +
168
            target_angle[iCubJointInterface::ICUB_ID_LIP_CENTER_UPPER])/2.0;
169
    double left_avg   = (target_angle[iCubJointInterface::ICUB_ID_LIP_LEFT_LOWER] +
170
            target_angle[iCubJointInterface::ICUB_ID_LIP_LEFT_UPPER])/2.0;
171
    double right_avg  = (target_angle[iCubJointInterface::ICUB_ID_LIP_RIGHT_LOWER] +
172
            target_angle[iCubJointInterface::ICUB_ID_LIP_RIGHT_UPPER])/2.0;
173

  
174
    // happy, neutral or sad?
175
    double diff_l = center_avg - left_avg;
176
    double diff_r = center_avg - right_avg;
177
    double diff   = (diff_l+diff_r)/2.0;
178

  
179
    if (diff > 2.0) {
180
        if (mouth_open) {
181
            led_value = 0x14;
182
        } else {
183
            if (diff > 2.6) {
184
                led_value = 0x0A;
185
            } else {
186
                led_value = 0x0B;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff