Revision f95312df
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-16T13:25:29. --> |
|
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_HUMOTION_YARP_ICUB_INCLUDE_HUMOTION_YARP_ICUB_ICUB_DATA_RECEIVER_H_ |
|
29 |
#define EXAMPLES_HUMOTION_YARP_ICUB_INCLUDE_HUMOTION_YARP_ICUB_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 "humotion_yarp_icub/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 |
|
|
56 |
private: |
|
57 |
void store_incoming_position(int icub_id, double value, double timestamp); |
|
58 |
void store_incoming_velocity(int icub_id, double velocity, double timestamp); |
|
59 |
yarp::sig::Vector calculate_velocities(yarp::sig::Vector positions, |
|
60 |
yarp::sig::Vector timestamps); |
|
61 |
|
|
62 |
void dump_incoming_data(); |
|
63 |
|
|
64 |
float target_eye_pan_; |
|
65 |
float target_eye_vergence_; |
|
66 |
|
|
67 |
float target_eye_pan_velocity_; |
|
68 |
float target_eye_vergence_velocity_; |
|
69 |
|
|
70 |
yarp::sig::Vector positions_; |
|
71 |
yarp::sig::Vector timestamps_; |
|
72 |
yarp::sig::Vector velocities_; |
|
73 |
yarp::sig::Vector commands_; |
|
74 |
|
|
75 |
yarp::sig::Vector previous_positions_; |
|
76 |
yarp::sig::Vector previous_timestamps_; |
|
77 |
|
|
78 |
iCubJointInterface *icub_jointinterface_; |
|
79 |
yarp::dev::IEncodersTimed *iencs_; |
|
80 |
}; |
|
81 |
|
|
82 |
#endif // EXAMPLES_HUMOTION_YARP_ICUB_INCLUDE_HUMOTION_YARP_ICUB_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 |
#ifndef EXAMPLES_HUMOTION_YARP_ICUB_INCLUDE_HUMOTION_YARP_ICUB_ICUB_FACEINTERFACE_H_ |
|
28 |
#define EXAMPLES_HUMOTION_YARP_ICUB_INCLUDE_HUMOTION_YARP_ICUB_ICUB_FACEINTERFACE_H_ |
|
29 |
|
|
30 |
#include "humotion_yarp_icub/icub_jointinterface.h" |
|
31 |
|
|
32 |
#include <yarp/dev/ControlBoardInterfaces.h> |
|
33 |
#include <yarp/os/Network.h> |
|
34 |
|
|
35 |
#include <string> |
|
36 |
|
|
37 |
class iCubFaceInterface { |
|
38 |
public: |
|
39 |
explicit iCubFaceInterface(std::string scope); |
|
40 |
~iCubFaceInterface(); |
|
41 |
|
|
42 |
|
|
43 |
void set_eyelid_angle(float angle); |
|
44 |
void set_eyebrow_angle(int id, float *target_angle); |
|
45 |
void set_mouth(float *target_angle); |
|
46 |
|
|
47 |
private: |
|
48 |
double lid_angle; |
|
49 |
int lid_opening_previous; |
|
50 |
int previous_mouth_state; |
|
51 |
double target_angle_previous[iCubJointInterface::ICUB_JOINT_ID_ENUM_SIZE]; |
|
52 |
std::string scope; |
|
53 |
yarp::os::BufferedPort<yarp::os::Bottle> emotion_port[4]; |
|
54 |
}; |
|
55 |
|
|
56 |
#endif // EXAMPLES_HUMOTION_YARP_ICUB_INCLUDE_HUMOTION_YARP_ICUB_ICUB_FACEINTERFACE_H_ |
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 |
#ifndef EXAMPLES_HUMOTION_YARP_ICUB_INCLUDE_HUMOTION_YARP_ICUB_ICUB_JOINTINTERFACE_H_ |
|
29 |
#define EXAMPLES_HUMOTION_YARP_ICUB_INCLUDE_HUMOTION_YARP_ICUB_ICUB_JOINTINTERFACE_H_ |
|
30 |
|
|
31 |
#include "humotion_yarp_icub/icub_data_receiver.h" |
|
32 |
|
|
33 |
#include <humotion/server/joint_interface.h> |
|
34 |
#include <humotion/server/server.h> |
|
35 |
|
|
36 |
#include <boost/bimap.hpp> |
|
37 |
#include <yarp/dev/ControlBoardInterfaces.h> |
|
38 |
#include <yarp/dev/IControlLimits2.h> |
|
39 |
#include <yarp/dev/IControlMode.h> |
|
40 |
#include <yarp/dev/PolyDriver.h> |
|
41 |
#include <yarp/os/Network.h> |
|
42 |
#include <yarp/os/Port.h> |
|
43 |
#include <yarp/os/Property.h> |
|
44 |
#include <yarp/os/RateThread.h> |
|
45 |
#include <yarp/os/Time.h> |
|
46 |
#include <yarp/sig/Vector.h> |
|
47 |
|
|
48 |
#include <string> |
|
49 |
#include <vector> |
|
50 |
|
|
51 |
class iCubDataReceiver; |
|
52 |
class iCubFaceInterface; |
|
53 |
|
|
54 |
class iCubJointInterface : public humotion::server::JointInterface{ |
|
55 |
public: |
|
56 |
explicit iCubJointInterface(std::string scope); |
|
57 |
~iCubJointInterface(); |
|
58 |
|
|
59 |
void run(); |
|
60 |
|
|
61 |
int convert_icub_jointid_to_humotion(int id); |
|
62 |
int convert_humotion_jointid_to_icub(int id); |
|
63 |
|
|
64 |
enum JOINT_ID_ENUM{ |
|
65 |
ICUB_ID_NECK_TILT = 0, |
|
66 |
ICUB_ID_NECK_ROLL = 1, |
|
67 |
ICUB_ID_NECK_PAN = 2, |
|
68 |
ICUB_ID_EYES_BOTH_UD = 3, |
|
69 |
ICUB_ID_EYES_PAN = 4, |
|
70 |
ICUB_ID_EYES_VERGENCE = 5, |
|
71 |
ICUB_ID_EYES_LEFT_LID_LOWER, |
|
72 |
ICUB_ID_EYES_LEFT_LID_UPPER, |
|
73 |
ICUB_ID_EYES_RIGHT_LID_LOWER, |
|
74 |
ICUB_ID_EYES_RIGHT_LID_UPPER, |
|
75 |
ICUB_ID_EYES_LEFT_BROW, |
|
76 |
ICUB_ID_EYES_RIGHT_BROW, |
|
77 |
ICUB_ID_LIP_LEFT_UPPER, |
|
78 |
ICUB_ID_LIP_LEFT_LOWER, |
|
79 |
ICUB_ID_LIP_CENTER_UPPER, |
|
80 |
ICUB_ID_LIP_CENTER_LOWER, |
|
81 |
ICUB_ID_LIP_RIGHT_UPPER, |
|
82 |
ICUB_ID_LIP_RIGHT_LOWER, |
|
83 |
ICUB_JOINT_ID_ENUM_SIZE |
|
84 |
}; |
|
85 |
|
|
86 |
yarp::dev::PolyDriver *get_yarp_polydriver() { return &yarp_polydriver_; } |
|
87 |
|
|
88 |
static const int MAIN_LOOP_FREQUENCY = 50; |
|
89 |
|
|
90 |
protected: |
|
91 |
void disable_joint(int e); |
|
92 |
void publish_target(int e, float position, float velocity); |
|
93 |
void enable_joint(int e); |
|
94 |
void execute_motion(); |
|
95 |
|
|
96 |
private: |
|
97 |
yarp::dev::PolyDriver yarp_polydriver_; |
|
98 |
|
|
99 |
std::vector<double> pv_mix_last_error_; |
|
100 |
std::vector<double> pv_mix_pid_p_; |
|
101 |
std::vector<double> pv_mix_pid_d_; |
|
102 |
|
|
103 |
// yarp views |
|
104 |
yarp::dev::IVelocityControl *yarp_ivel_; |
|
105 |
yarp::dev::IControlLimits *yarp_ilimits_; |
|
106 |
yarp::dev::IAmplifierControl *yarp_amp_; |
|
107 |
yarp::dev::IPidControl *yarp_pid_; |
|
108 |
yarp::dev::IControlMode *yarp_icontrol_; |
|
109 |
|
|
110 |
yarp::sig::Vector yarp_commands_; |
|
111 |
|
|
112 |
float target_angle_[ICUB_JOINT_ID_ENUM_SIZE]; |
|
113 |
float target_velocity_[ICUB_JOINT_ID_ENUM_SIZE]; |
|
114 |
|
|
115 |
|
|
116 |
void init_controller(); |
|
117 |
void init_id_map(); |
|
118 |
void init_pv_mix_pid(); |
|
119 |
void insert_icupid_to_humotionid_mapping(int icubid, int humotionid); |
|
120 |
|
|
121 |
|
|
122 |
void store_icub_joint_target(int icub_id, float position, float velocity); |
|
123 |
|
|
124 |
|
|
125 |
void set_joint_enable_state(int e, bool enabled); |
|
126 |
|
|
127 |
iCubDataReceiver *icub_data_receiver; |
|
128 |
void init_joints(); |
|
129 |
|
|
130 |
std::string scope; |
|
131 |
|
|
132 |
void store_min_max(yarp::dev::IControlLimits *ilimits, int icub_id); |
|
133 |
|
|
134 |
void set_target_in_velocitymode(int id); |
|
135 |
|
|
136 |
iCubFaceInterface *face_interface_; |
|
137 |
|
|
138 |
typedef boost::bimap<int, int > enum_id_bimap_t; |
|
139 |
typedef enum_id_bimap_t::value_type enum_id_bimap_entry_t; |
|
140 |
enum_id_bimap_t enum_id_bimap; |
|
141 |
}; |
|
142 |
|
|
143 |
#endif // EXAMPLES_HUMOTION_YARP_ICUB_INCLUDE_HUMOTION_YARP_ICUB_ICUB_JOINTINTERFACE_H_ |
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 <string> |
|
33 |
|
|
34 |
#include "humotion_yarp_icub/icub_data_receiver.h" |
|
35 |
|
|
36 |
using std::cout; |
|
37 |
using std::cerr; |
|
38 |
using std::string; |
|
39 |
using humotion::server::JointInterface; |
|
40 |
using yarp::dev::IEncodersTimed; |
|
41 |
using yarp::sig::Vector; |
|
42 |
|
|
43 |
#define ICUB_DATA_RECEIVER_USE_ENCODERSPEED 0 |
|
44 |
#define ICUB_DATA_RECEIVER_DUMP_DATA 0 |
|
45 |
|
|
46 |
//! constructor |
|
47 |
//! \param period_ms for the yarp rate thread |
|
48 |
//! \param icub_jointinterface |
|
49 |
iCubDataReceiver::iCubDataReceiver(int period_ms, iCubJointInterface *icub_jointinterface) |
|
50 |
: yarp::os::RateThread(period_ms) { |
|
51 |
|
|
52 |
// store pointer to icub jointinterface |
|
53 |
icub_jointinterface_ = icub_jointinterface; |
|
54 |
|
|
55 |
// fetch iencs view from yarp |
|
56 |
yarp::dev::PolyDriver *poly_driver = icub_jointinterface->get_yarp_polydriver(); |
|
57 |
bool success = poly_driver->view(iencs_); |
|
58 |
if (!success) { |
|
59 |
cerr << "ERROR: polydriver failed to init iencs view\n"; |
|
60 |
exit(EXIT_FAILURE); |
|
61 |
} |
|
62 |
|
|
63 |
// resize data storage vectors to match the number of axes |
|
64 |
int joints; |
|
65 |
iencs_->getAxes(&joints); |
|
66 |
positions_.resize(joints); |
|
67 |
velocities_.resize(joints); |
|
68 |
timestamps_.resize(joints); |
|
69 |
} |
|
70 |
|
|
71 |
//! yarp rate thread initializer |
|
72 |
bool iCubDataReceiver::threadInit() { |
|
73 |
return true; |
|
74 |
} |
|
75 |
|
|
76 |
//! yarp thread release function |
|
77 |
void iCubDataReceiver::threadRelease() { |
|
78 |
} |
|
79 |
|
|
80 |
//! manully calculate joint velocities (instead of using joint encoder speeds) |
|
81 |
//! \param positions vector with current encoder position |
|
82 |
//! \param timestamps vector with the associated timestamps |
|
83 |
//! \return velocities as vector |
|
84 |
Vector iCubDataReceiver::calculate_velocities(Vector positions, Vector timestamps) { |
|
85 |
Vector velocities; |
|
86 |
velocities.resize(positions.size()); |
|
87 |
|
|
88 |
if (previous_positions_.size() == 0) { |
|
89 |
// first run, no valid old position available, return zero velocities |
|
90 |
// by setting all all elements to zero |
|
91 |
velocities = 0.0; |
|
92 |
} else { |
|
93 |
// calculate speed based on positions: |
|
94 |
for (int i=0; i < positions.size(); i++) { |
|
95 |
float diff = positions[i] - previous_positions_[i]; |
|
96 |
float timediff = timestamps[i] - previous_timestamps_[i]; |
|
97 |
// calc speed: |
|
98 |
velocities[i] = diff / timediff; |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
102 |
previous_positions_ = positions; |
|
103 |
previous_timestamps_ = timestamps; |
|
104 |
|
|
105 |
return velocities; |
|
106 |
} |
|
107 |
|
|
108 |
//! main loop routine, called by yarp rate thread |
|
109 |
void iCubDataReceiver::run() { |
|
110 |
float velocity; |
|
111 |
|
|
112 |
// grab pos+vel data: |
|
113 |
iencs_->getEncodersTimed(positions_.data(), timestamps_.data()); |
|
114 |
|
|
115 |
#if ICUB_DATA_RECEIVER_USE_ENCODERSPEED |
|
116 |
// fetch data from icub. NOTE: make sure to enable the vel broadcast in the ini file! |
|
117 |
if (!iencs_->getEncoderSpeeds(velocities_.data())) { |
|
118 |
cout << "Failed to fetch encoder speeds...\n"; |
|
119 |
return; |
|
120 |
} |
|
121 |
#else |
|
122 |
// manually calculate the speed based on old position: |
|
123 |
velocities_ = calculate_velocities(positions_, timestamps_); |
|
124 |
#endif |
|
125 |
|
|
126 |
// publish data to humotion |
|
127 |
for (int i = 0; i < positions_.size(); i++) { |
|
128 |
// store position values |
|
129 |
store_incoming_position(i, positions_[i], timestamps_[i]); |
|
130 |
// store velocity |
|
131 |
store_incoming_velocity(i, velocities_[i], timestamps_[i]); |
|
132 |
} |
|
133 |
|
|
134 |
// small hack to tell humotion to update the lid angle |
|
135 |
// fixme: use real id |
|
136 |
store_incoming_position(100, 0.0, timestamps_[0]); |
|
137 |
|
|
138 |
#if ICUB_DATA_RECEIVER_DUMP_DATA |
|
139 |
dump_incoming_data(); |
|
140 |
#endif |
|
141 |
} |
|
142 |
|
|
143 |
//! store incoming position for a given icub joint |
|
144 |
//! \param icub _id icub joint id |
|
145 |
//! \param position |
|
146 |
//! \param timestamp |
|
147 |
void iCubDataReceiver::store_incoming_position(int icub_id, double position, double timestamp) { |
|
148 |
// cout << "store_incoming_position(icub=" << icub_id << ", " << position << ")\n"; |
|
149 |
|
|
150 |
// store joint position in humotion backend |
|
151 |
if ((icub_id == iCubJointInterface::ICUB_ID_EYES_PAN) || |
|
152 |
(icub_id == iCubJointInterface::ICUB_ID_EYES_VERGENCE)) { |
|
153 |
// the icub handles eyes differently |
|
154 |
// instead of using seperate left/right pan the icub uses |
|
155 |
// a combined pan angle and vergence. therfore we have to convert this here: |
|
156 |
if (icub_id == iCubJointInterface::ICUB_ID_EYES_PAN) { |
|
157 |
target_eye_pan_ = position; |
|
158 |
} else { |
|
159 |
target_eye_vergence_ = -position; |
|
160 |
} |
|
161 |
|
|
162 |
float right = target_eye_pan_ + target_eye_vergence_/2.0; |
|
163 |
float left = target_eye_pan_ - target_eye_vergence_/2.0; |
|
164 |
|
|
165 |
icub_jointinterface_->store_incoming_position(JointInterface::ID_EYES_LEFT_LR, |
|
166 |
left, timestamp); |
|
167 |
icub_jointinterface_->store_incoming_position(JointInterface::ID_EYES_RIGHT_LR, |
|
168 |
right, timestamp); |
|
169 |
} else if (icub_id == 100) { |
|
170 |
//HACK |
|
171 |
// icub_jointinterface->store_incoming_position(ID_EYES_RIGHT_LID_UPPER, |
|
172 |
// lid_angle, timestamp); |
|
173 |
} else { |
|
174 |
if (icub_id == iCubJointInterface::ID_NECK_PAN) { |
|
175 |
// icub uses an inverted neck pan specification |
|
176 |
position = -position; |
|
177 |
} |
|
178 |
|
|
179 |
// known configured mapping between joint ids |
|
180 |
int humotion_id = icub_jointinterface_->convert_icub_jointid_to_humotion(icub_id); |
|
181 |
icub_jointinterface_->store_incoming_position(humotion_id, position, timestamp); |
|
182 |
} |
|
183 |
} |
|
184 |
|
|
185 |
//! store incoming velocity for a given icub joint |
|
186 |
//! \param icub_id icub joint id |
|
187 |
//! \param velocity |
|
188 |
//! \param timestamp |
|
189 |
void iCubDataReceiver::store_incoming_velocity(int icub_id, double velocity, double timestamp) { |
|
190 |
// cout << "store_incoming_velocity(icub=" << icub_id << ", " << velocity << ")\n"; |
|
191 |
|
|
192 |
// store joint position in humotion backend |
|
193 |
if ((icub_id == iCubJointInterface::ICUB_ID_EYES_PAN) || |
|
194 |
(icub_id == iCubJointInterface::ICUB_ID_EYES_VERGENCE)) { |
|
195 |
// the icub handles eyes differently |
|
196 |
// instead of using seperate left/right pan the icub uses |
|
197 |
// a combined pan angle and vergence. therfore we have to convert this here: |
|
198 |
if (icub_id == iCubJointInterface::ICUB_ID_EYES_PAN) { |
|
199 |
target_eye_pan_velocity_ = velocity; |
|
200 |
} else { |
|
201 |
target_eye_vergence_velocity_ = -velocity; |
|
202 |
} |
|
203 |
|
|
204 |
float right = target_eye_pan_velocity_ + target_eye_vergence_velocity_/2.0; |
|
205 |
float left = target_eye_pan_velocity_ - target_eye_vergence_velocity_/2.0; |
|
206 |
|
|
207 |
icub_jointinterface_->store_incoming_velocity(JointInterface::ID_EYES_LEFT_LR, |
|
208 |
left, timestamp); |
|
209 |
icub_jointinterface_->store_incoming_velocity(JointInterface::ID_EYES_RIGHT_LR, |
|
210 |
right, timestamp); |
|
211 |
} else if (icub_id == 100) { |
|
212 |
//HACK |
|
213 |
// icub_jointinterface->store_incoming_position(ID_EYES_RIGHT_LID_UPPER, |
|
214 |
// lid_angle, timestamp); |
|
215 |
} else { |
|
216 |
if (icub_id == iCubJointInterface::ID_NECK_PAN) { |
|
217 |
// icub uses an inverted neck pan specification |
|
218 |
velocity = -velocity; |
|
219 |
} |
|
220 |
|
|
221 |
// known configured mapping between joint ids |
|
222 |
int humotion_id = icub_jointinterface_->convert_icub_jointid_to_humotion(icub_id); |
|
223 |
icub_jointinterface_->store_incoming_velocity(humotion_id, velocity, timestamp); |
|
224 |
} |
|
225 |
} |
|
226 |
|
|
227 |
//! helper for debugging purposes, feed this data into gnuplot for visual inspection |
|
228 |
void iCubDataReceiver::dump_incoming_data() { |
|
229 |
// use gnuplot for viz: |
|
230 |
// ./icub_humotion_server --robot icub | grep "INCOMING" |tee log |
|
231 |
// @gnuplot: plot "log" using 0:1 w l t "p neck tilt", "log" using 0:2 w l t "v neck tilt", \ |
|
232 |
// "log" using 0:5 w l t "p neck pan", "log" using 0:6 w l t "v neck pan", \ |
|
233 |
// "log" using 0:7 w l t "p eyes ud", "log" using 0:8 w l t "v eyes ud", \ |
|
234 |
// "log" using 0:9 w l t "p eyes vergence", "log" using 0:10 w l t "v eyes verg" |
|
235 |
cout << "\n"; |
|
236 |
// publish data to humotion |
|
237 |
for (int i = 0; i < positions_.size(); i++) { |
|
238 |
cout << positions_[i] << " "; |
|
239 |
cout << velocities_[i] << " "; |
|
240 |
} |
|
241 |
cout << " #INCOMING_DATA_DUMP\n"; |
|
242 |
} |
|
243 |
|
|
244 |
|
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 <boost/format.hpp> |
|
31 |
#include <boost/lexical_cast.hpp> |
|
32 |
|
|
33 |
#include <algorithm> |
|
34 |
#include <string> |
|
35 |
|
|
36 |
using yarp::os::Network; |
|
37 |
using yarp::os::Bottle; |
|
38 |
using std::cout; |
|
39 |
using std::cerr; |
|
40 |
using std::string; |
|
41 |
|
|
42 |
//! constructor |
|
43 |
iCubFaceInterface::iCubFaceInterface(std::string _scope) { |
|
44 |
scope = _scope; |
|
45 |
|
|
46 |
// attach to facial expressions: |
|
47 |
std::string emotion_scope = scope + "/face/raw/in"; |
|
48 |
cout << "opening connection to '"<< emotion_scope << "'\n"; |
|
49 |
|
|
50 |
bool init_ok = true; |
|
51 |
for (int i = 0; i < 4; i++) { |
|
52 |
// strange, if we use one output port only the first command is executed?! flushing issues? |
|
53 |
std::string emotion_port_out = "/emotionwriter" + boost::lexical_cast<std::string>(i); |
|
54 |
if (!emotion_port[i].open(emotion_port_out.c_str())) { |
|
55 |
cerr << "ERROR: failed to open emotion port '" << emotion_port_out << "'\n"; |
|
56 |
init_ok = false; |
|
57 |
} |
|
58 |
if (!Network::connect(emotion_port_out.c_str(), emotion_scope.c_str())) { |
|
59 |
cerr << "ERROR: failed to connect to emotion port '" << emotion_port_out << "'\n"; |
|
60 |
init_ok = false; |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
if (!init_ok) { |
|
65 |
cerr << "ERROR: failed to set up emotion component\n"; |
|
66 |
cerr << " please make sure that the faceExpressions yarpdev is started\n"; |
|
67 |
cerr << " (e.g. yarpdev --name /icub/face/raw --device serial ... is running)\n"; |
|
68 |
exit(EXIT_FAILURE); |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
//! destructor |
|
73 |
iCubFaceInterface::~iCubFaceInterface() { |
|
74 |
} |
|
75 |
|
|
76 |
//! special command to set eyelid angle |
|
77 |
//! \param angle in degrees |
|
78 |
void iCubFaceInterface::set_eyelid_angle(float angle) { |
|
79 |
if (emotion_port[0].getOutputCount() > 0) { |
|
80 |
// try to set the value based on the upper one |
|
81 |
// some guesses from the sim: S30 = 0° / S40 = 10° |
|
82 |
int opening = (25.0 + 0.8*angle); |
|
83 |
opening = std::min(48, std::max(24, opening)); |
|
84 |
|
|
85 |
if (opening == lid_opening_previous) { |
|
86 |
// no update necessary |
|
87 |
return; |
|
88 |
} |
|
89 |
|
|
90 |
lid_angle = angle; |
|
91 |
lid_opening_previous = opening; |
|
92 |
|
|
93 |
char buf[20]; |
|
94 |
snprintf(buf, sizeof(buf), "S%2d", opening); |
|
95 |
|
|
96 |
// cout << "SETTING EYELID '" << buf << "' (" << angle << " -> " << opening << "\n"; |
|
97 |
Bottle &cmd = emotion_port[0].prepare(); |
|
98 |
cmd.clear(); |
|
99 |
cmd.addString(buf); |
|
100 |
emotion_port[0].writeStrict(); |
|
101 |
} else { |
|
102 |
cerr << "ERROR: no icub emotion output\n"; |
|
103 |
exit(EXIT_FAILURE); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
//! special command to set the eyebrow angle |
|
108 |
//! \param id {0=left, 1=right) |
|
109 |
//! \param angle in degrees |
|
110 |
void iCubFaceInterface::set_eyebrow_angle(int id, float *target_angle) { |
|
111 |
int port_id; |
|
112 |
if (id == iCubJointInterface::ICUB_ID_EYES_LEFT_BROW) { |
|
113 |
port_id = 1; |
|
114 |
} else { |
|
115 |
port_id = 2; |
|
116 |
} |
|
117 |
|
|
118 |
if (emotion_port[port_id].getOutputCount() > 0) { |
|
119 |
double angle = target_angle[id]; |
|
120 |
int icub_val = 0; |
|
121 |
|
|
122 |
// swap rotation direction for eyebrow |
|
123 |
if (id == iCubJointInterface::ICUB_ID_EYES_LEFT_BROW) { |
|
124 |
angle = -angle; |
|
125 |
} |
|
126 |
|
|
127 |
// convert to icub representation |
|
128 |
if (angle < -20) { |
|
129 |
icub_val = 1; |
|
130 |
} else if (angle < 10) { |
|
131 |
icub_val = 2; |
|
132 |
} else if (angle < 20) { |
|
133 |
icub_val = 4; |
|
134 |
} else { |
|
135 |
icub_val = 8; |
|
136 |
} |
|
137 |
|
|
138 |
// make sure to update only on new values |
|
139 |
if (icub_val == target_angle_previous[id]) { |
|
140 |
// no updata necessary |
|
141 |
return; |
|
142 |
} |
|
143 |
|
|
144 |
// store actual value |
|
145 |
target_angle_previous[id] = icub_val; |
|
146 |
|
|
147 |
|
|
148 |
std::string cmd_s; |
|
149 |
if (id == iCubJointInterface::ICUB_ID_EYES_LEFT_BROW) { |
|
150 |
cmd_s = "L0" + boost::lexical_cast<std::string>(icub_val); |
|
151 |
} else { |
|
152 |
cmd_s = "R0" + boost::lexical_cast<std::string>(icub_val); |
|
153 |
} |
|
154 |
|
|
155 |
cout << "SETTING EYEBROW " << id << " (" << angle << " -> " << cmd_s << ")\n"; |
|
156 |
|
|
157 |
Bottle &cmd = emotion_port[port_id].prepare(); |
|
158 |
cmd.clear(); |
|
159 |
cmd.addString(cmd_s); |
|
160 |
emotion_port[port_id].writeStrict(); |
|
161 |
} else { |
|
162 |
cerr << "ERROR: no icub emotion output\n"; |
|
163 |
exit(EXIT_FAILURE); |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
void iCubFaceInterface::set_mouth(float *target_angle) { |
|
168 |
// convert from 6DOF mouth displacement to icub leds: |
|
169 |
int led_value = 0; |
|
170 |
|
|
171 |
// fetch center opening |
|
172 |
double center_opening = target_angle[iCubJointInterface::ICUB_ID_LIP_CENTER_LOWER] - |
|
173 |
target_angle[iCubJointInterface::ICUB_ID_LIP_CENTER_UPPER]; |
|
174 |
bool mouth_open = (center_opening > 15.0) ? true : false; |
|
175 |
|
|
176 |
// side of mouth high or low? |
|
177 |
double center_avg = (target_angle[iCubJointInterface::ICUB_ID_LIP_CENTER_LOWER] + |
|
178 |
target_angle[iCubJointInterface::ICUB_ID_LIP_CENTER_UPPER])/2.0; |
|
179 |
double left_avg = (target_angle[iCubJointInterface::ICUB_ID_LIP_LEFT_LOWER] + |
|
180 |
target_angle[iCubJointInterface::ICUB_ID_LIP_LEFT_UPPER])/2.0; |
|
181 |
double right_avg = (target_angle[iCubJointInterface::ICUB_ID_LIP_RIGHT_LOWER] + |
|
182 |
target_angle[iCubJointInterface::ICUB_ID_LIP_RIGHT_UPPER])/2.0; |
|
183 |
|
|
184 |
// happy, neutral or sad? |
|
185 |
double diff_l = center_avg - left_avg; |
|
186 |
double diff_r = center_avg - right_avg; |
|
187 |
double diff = (diff_l+diff_r)/2.0; |
|
188 |
|
|
189 |
if (diff > 2.0) { |
|
190 |
if (mouth_open) { |
|
191 |
led_value = 0x14; |
|
192 |
} else { |
|
193 |
if (diff > 2.6) { |
|
194 |
led_value = 0x0A; |
|
195 |
} else { |
|
196 |
led_value = 0x0B; |
|
197 |
} |
|
198 |
} |
|
199 |
} else if (diff < -3.0) { |
|
200 |
if (mouth_open) { |
|
201 |
led_value = 0x06; |
|
202 |
} else { |
|
203 |
led_value = 0x18; |
Also available in: Unified diff