Revision 8c6c1163
CMakeLists.txt | ||
---|---|---|
1 |
cmake_minimum_required(VERSION 2.8.3) |
|
2 |
project(humotion) |
|
3 |
|
|
4 |
set(ENV{ROS_LANG_DISABLE} "genjava") |
|
5 |
|
|
6 |
|
|
7 |
set(ROS_BUILD_TYPE Debug) |
|
8 |
|
|
9 |
|
|
10 |
####################################### |
|
11 |
# check if we have RSB support: |
|
12 |
FIND_PACKAGE(RSB 0.11) |
|
13 |
IF (RSB_FOUND) |
|
14 |
#RSB |
|
15 |
SET(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib:\$ORIGIN/") |
|
16 |
FIND_PACKAGE(RSC 0.11 REQUIRED) |
|
17 |
FIND_PACKAGE(RSB 0.11 REQUIRED) |
|
18 |
#RST |
|
19 |
FIND_PACKAGE(RST REQUIRED COMPONENTS sandbox) |
|
20 |
INCLUDE_DIRECTORIES(BEFORE SYSTEM ${RST_INCLUDE_DIRS}) |
|
21 |
ADD_DEFINITIONS(${RST_CFLAGS} ${RSTSANDBOX_CFLAGS}) |
|
22 |
|
|
23 |
INCLUDE_DIRECTORIES(BEFORE SYSTEM ${RSB_INCLUDE_DIRS}) |
|
24 |
LIST(INSERT CMAKE_MODULE_PATH 0 ${RSC_CMAKE_MODULE_PATH}) |
|
25 |
#RSB |
|
26 |
SET(CMAKE_INSTALL_RPATH "\$ORIGIN/../lib:\$ORIGIN/") |
|
27 |
FIND_PACKAGE(RSC 0.11 REQUIRED) |
|
28 |
FIND_PACKAGE(RSB 0.11 REQUIRED) |
|
29 |
#RST |
|
30 |
FIND_PACKAGE(RST REQUIRED COMPONENTS sandbox) |
|
31 |
INCLUDE_DIRECTORIES(BEFORE SYSTEM ${RST_INCLUDE_DIRS}) |
|
32 |
ADD_DEFINITIONS(${RST_CFLAGS} ${RSTSANDBOX_CFLAGS}) |
|
33 |
|
|
34 |
INCLUDE_DIRECTORIES(BEFORE SYSTEM ${RSB_INCLUDE_DIRS}) |
|
35 |
LIST(INSERT CMAKE_MODULE_PATH 0 ${RSC_CMAKE_MODULE_PATH}) |
|
36 |
|
|
37 |
message(STATUS "RSB Support is ON") |
|
38 |
add_definitions(-DRSB_SUPPORT=1) |
|
39 |
ENDIF (RSB_FOUND) |
|
40 |
|
|
41 |
################################################################ |
|
42 |
# check for ROS support: |
|
43 |
find_package(catkin) |
|
44 |
IF (catkin_FOUND) |
|
45 |
SET(ROS_FOUND 1) |
|
46 |
|
|
47 |
find_package(catkin REQUIRED COMPONENTS roscpp std_msgs sensor_msgs message_generation genmsg) |
|
48 |
|
|
49 |
message(STATUS "ROS Support is ON") |
|
50 |
add_definitions(-DROS_SUPPORT=1) |
|
51 |
ENDIF (catkin_FOUND) |
|
52 |
|
|
53 |
|
|
54 |
INCLUDE(FindPkgConfig) |
|
55 |
|
|
56 |
##libreflexxes |
|
57 |
IF (libreflexxes_DIR) |
|
58 |
MESSAGE("using libreflexxes_DIR as override ('${libreflexxes_DIR}')") |
|
59 |
SET(REFLEXXES_PREFIX ${libreflexxes_DIR}) |
|
60 |
ELSE () |
|
61 |
PKG_CHECK_MODULES(REFLEXXES REQUIRED libReflexxesTypeII>=1.2.3) |
|
62 |
IF (NOT REFLEXXES_FOUND) |
|
63 |
message(FATAL_ERROR "Error: could not find lib libReflexxesTypeII") |
|
64 |
ENDIF () |
|
65 |
ENDIF() |
|
66 |
|
|
67 |
IF (NOT catkin_FOUND) |
|
68 |
IF (NOT RSB_FOUND) |
|
69 |
message(FATAL_ERROR "Error: could neither find RSB or ROS middleware!") |
|
70 |
ENDIF (NOT RSB_FOUND) |
|
71 |
ENDIF (NOT catkin_FOUND) |
|
72 |
|
|
73 |
|
|
74 |
SET(REFLEXXES_LIBRARY_DIRS "${REFLEXXES_PREFIX}/lib") |
|
75 |
SET(REFLEXXES_INCLUDE_DIRS "${REFLEXXES_PREFIX}/include") |
|
76 |
MESSAGE("using libReflexxesTypeII version ${REFLEXXES_VERSION} from ${REFLEXXES_INCLUDE_DIRS} and ${REFLEXXES_LIBRARY_DIRS}") |
|
77 |
|
|
78 |
set(CMAKE_CXX_FLAGS "-g -Wall") |
|
79 |
add_definitions ("-Wall") |
|
80 |
|
|
81 |
|
|
82 |
IF (catkin_FOUND) |
|
83 |
####################################### |
|
84 |
## Declare ROS messages and services ## |
|
85 |
####################################### |
|
86 |
|
|
87 |
add_message_files( |
|
88 |
FILES |
|
89 |
gaze.msg |
|
90 |
position_lcr.msg |
|
91 |
mouth.msg |
|
92 |
) |
|
93 |
|
|
94 |
## Generate added messages and services with any dependencies listed here |
|
95 |
generate_messages( |
|
96 |
DEPENDENCIES |
|
97 |
std_msgs |
|
98 |
humotion |
|
99 |
) |
|
100 |
|
|
101 |
|
|
102 |
# |
|
103 |
################################### |
|
104 |
## catkin specific configuration ## |
|
105 |
################################### |
|
106 |
## The catkin_package macro generates cmake config files for your package |
|
107 |
## Declare things to be passed to dependent projects |
|
108 |
## INCLUDE_DIRS: uncomment this if you package contains header files |
|
109 |
## LIBRARIES: libraries you create in this project that dependent projects also need |
|
110 |
## CATKIN_DEPENDS: catkin_packages dependent projects also need |
|
111 |
## DEPENDS: system dependencies of this project that dependent projects also need |
|
112 |
catkin_package( |
|
113 |
INCLUDE_DIRS include |
|
114 |
LIBRARIES humotion |
|
115 |
#CATKIN_DEPENDS message_runtime |
|
116 |
#DEPENDS system_lib |
|
117 |
) |
|
118 |
ENDIF (catkin_FOUND) |
|
119 |
|
|
120 |
########### |
|
121 |
## Build ## |
|
122 |
########### |
|
123 |
|
|
124 |
## Specify additional locations of header files |
|
125 |
## Your package locations should be listed before other locations |
|
126 |
include_directories (BEFORE ${Boost_INCLUDE_DIRS} ${REFLEXXES_INCLUDE_DIRS}) |
|
127 |
include_directories(include) |
|
128 |
include_directories( ${catkin_INCLUDE_DIRS}) |
|
129 |
link_directories (${Boost_LIBRARY_DIRS} ${REFLEXXES_LIBRARY_DIRS} ${catkin_LIBRARY_DIRS}) |
|
130 |
|
|
131 |
file(GLOB DUMMY_HEADER_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} include/*.h include/client/*.h include/server/*.h srv/*.srv msg/*.msg etc/*) |
|
132 |
|
|
133 |
## Declare a cpp library |
|
134 |
add_library(humotion |
|
135 |
src/mouth_state.cpp |
|
136 |
src/gaze_state.cpp |
|
137 |
|
|
138 |
src/client/client.cpp |
|
139 |
src/client/middleware.cpp |
|
140 |
src/client/middleware_ros.cpp |
|
141 |
src/client/middleware_rsb.cpp |
|
142 |
|
|
143 |
src/server/server.cpp |
|
144 |
src/server/middleware.cpp |
|
145 |
src/server/middleware_ros.cpp |
|
146 |
src/server/middleware_rsb.cpp |
|
147 |
|
|
148 |
src/server/controller.cpp |
|
149 |
src/server/joint_interface.cpp |
|
150 |
src/server/motion_generator.cpp |
|
151 |
src/server/gaze_motion_generator.cpp |
|
152 |
src/server/reflexxes_motion_generator.cpp |
|
153 |
src/server/mouth_motion_generator.cpp |
|
154 |
src/server/eye_motion_generator.cpp |
|
155 |
src/server/eyelid_motion_generator.cpp |
|
156 |
src/server/eyebrow_motion_generator.cpp |
|
157 |
src/server/neck_motion_generator.cpp |
|
158 |
|
|
159 |
src/timestamped_list.cpp |
|
160 |
|
|
161 |
${DUMMY_HEADER_LIST} |
|
162 |
) |
|
163 |
|
|
164 |
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") |
|
165 |
|
|
166 |
|
|
167 |
## Add cmake target dependencies of the executable/library |
|
168 |
## as an example, message headers may need to be generated before nodes |
|
169 |
add_dependencies(humotion ${catkin_EXPORTED_TARGETS} humotion_gencpp) |
|
170 |
|
|
171 |
## Specify libraries to link a library or executable target against |
|
172 |
target_link_libraries(humotion |
|
173 |
${Boost_LIBRARIES} |
|
174 |
${catkin_LIBRARIES} |
|
175 |
${REFLEXXES_LIBRARIES} |
|
176 |
${RST_LIBRARIES} |
|
177 |
${RSB_LIBRARIES} |
|
178 |
) |
|
179 |
|
|
180 |
set_property(TARGET humotion PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE) |
|
181 |
|
|
182 |
############# |
|
183 |
## Install ## |
|
184 |
############# |
|
185 |
|
|
186 |
# all install targets should use catkin DESTINATION variables |
|
187 |
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html |
|
188 |
|
|
189 |
## Mark executable scripts (Python etc.) for installation |
|
190 |
## in contrast to setup.py, you can choose the destination |
|
191 |
# install(PROGRAMS |
|
192 |
# scripts/my_python_script |
|
193 |
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} |
|
194 |
# ) |
|
195 |
|
|
196 |
## Mark executables and/or libraries for installation |
|
197 |
IF (catkin_FOUND) |
|
198 |
install(TARGETS humotion |
|
199 |
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} |
|
200 |
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} |
|
201 |
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} |
|
202 |
) |
|
203 |
## Mark cpp header files for installation |
|
204 |
install(DIRECTORY include/ |
|
205 |
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} |
|
206 |
PATTERN ".svn" EXCLUDE |
|
207 |
) |
|
208 |
ENDIF (catkin_FOUND) |
|
209 |
|
|
210 |
|
|
211 |
############# |
|
212 |
## Testing ## |
|
213 |
############# |
|
214 |
IF (catkin_FOUND) |
|
215 |
## Add gtest based cpp test target and link libraries |
|
216 |
catkin_add_gtest(${PROJECT_NAME}-test-server test/server.cpp) |
|
217 |
if(TARGET ${PROJECT_NAME}-test-server) |
|
218 |
target_link_libraries(${PROJECT_NAME}-test-server ${PROJECT_NAME}) |
|
219 |
endif() |
|
220 |
catkin_add_gtest(${PROJECT_NAME}-test-client test/client.cpp) |
|
221 |
if(TARGET ${PROJECT_NAME}-test-client) |
|
222 |
target_link_libraries(${PROJECT_NAME}-test-client ${PROJECT_NAME}) |
|
223 |
endif() |
|
224 |
ENDIF (catkin_FOUND) |
|
225 |
|
|
226 |
|
|
227 |
### Add folders to be run by python nosetests |
|
228 |
# catkin_add_nosetests(test) |
COPYING | ||
---|---|---|
1 |
GNU LESSER GENERAL PUBLIC LICENSE |
|
2 |
Version 3, 29 June 2007 |
|
3 |
|
|
4 |
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> |
|
5 |
Everyone is permitted to copy and distribute verbatim copies |
|
6 |
of this license document, but changing it is not allowed. |
|
7 |
|
|
8 |
|
|
9 |
This version of the GNU Lesser General Public License incorporates |
|
10 |
the terms and conditions of version 3 of the GNU General Public |
|
11 |
License, supplemented by the additional permissions listed below. |
|
12 |
|
|
13 |
0. Additional Definitions. |
|
14 |
|
|
15 |
As used herein, "this License" refers to version 3 of the GNU Lesser |
|
16 |
General Public License, and the "GNU GPL" refers to version 3 of the GNU |
|
17 |
General Public License. |
|
18 |
|
|
19 |
"The Library" refers to a covered work governed by this License, |
|
20 |
other than an Application or a Combined Work as defined below. |
|
21 |
|
|
22 |
An "Application" is any work that makes use of an interface provided |
|
23 |
by the Library, but which is not otherwise based on the Library. |
|
24 |
Defining a subclass of a class defined by the Library is deemed a mode |
|
25 |
of using an interface provided by the Library. |
|
26 |
|
|
27 |
A "Combined Work" is a work produced by combining or linking an |
|
28 |
Application with the Library. The particular version of the Library |
|
29 |
with which the Combined Work was made is also called the "Linked |
|
30 |
Version". |
|
31 |
|
|
32 |
The "Minimal Corresponding Source" for a Combined Work means the |
|
33 |
Corresponding Source for the Combined Work, excluding any source code |
|
34 |
for portions of the Combined Work that, considered in isolation, are |
|
35 |
based on the Application, and not on the Linked Version. |
|
36 |
|
|
37 |
The "Corresponding Application Code" for a Combined Work means the |
|
38 |
object code and/or source code for the Application, including any data |
|
39 |
and utility programs needed for reproducing the Combined Work from the |
|
40 |
Application, but excluding the System Libraries of the Combined Work. |
|
41 |
|
|
42 |
1. Exception to Section 3 of the GNU GPL. |
|
43 |
|
|
44 |
You may convey a covered work under sections 3 and 4 of this License |
|
45 |
without being bound by section 3 of the GNU GPL. |
|
46 |
|
|
47 |
2. Conveying Modified Versions. |
|
48 |
|
|
49 |
If you modify a copy of the Library, and, in your modifications, a |
|
50 |
facility refers to a function or data to be supplied by an Application |
|
51 |
that uses the facility (other than as an argument passed when the |
|
52 |
facility is invoked), then you may convey a copy of the modified |
|
53 |
version: |
|
54 |
|
|
55 |
a) under this License, provided that you make a good faith effort to |
|
56 |
ensure that, in the event an Application does not supply the |
|
57 |
function or data, the facility still operates, and performs |
|
58 |
whatever part of its purpose remains meaningful, or |
|
59 |
|
|
60 |
b) under the GNU GPL, with none of the additional permissions of |
|
61 |
this License applicable to that copy. |
|
62 |
|
|
63 |
3. Object Code Incorporating Material from Library Header Files. |
|
64 |
|
|
65 |
The object code form of an Application may incorporate material from |
|
66 |
a header file that is part of the Library. You may convey such object |
|
67 |
code under terms of your choice, provided that, if the incorporated |
|
68 |
material is not limited to numerical parameters, data structure |
|
69 |
layouts and accessors, or small macros, inline functions and templates |
|
70 |
(ten or fewer lines in length), you do both of the following: |
|
71 |
|
|
72 |
a) Give prominent notice with each copy of the object code that the |
|
73 |
Library is used in it and that the Library and its use are |
|
74 |
covered by this License. |
|
75 |
|
|
76 |
b) Accompany the object code with a copy of the GNU GPL and this license |
|
77 |
document. |
|
78 |
|
|
79 |
4. Combined Works. |
|
80 |
|
|
81 |
You may convey a Combined Work under terms of your choice that, |
|
82 |
taken together, effectively do not restrict modification of the |
|
83 |
portions of the Library contained in the Combined Work and reverse |
|
84 |
engineering for debugging such modifications, if you also do each of |
|
85 |
the following: |
|
86 |
|
|
87 |
a) Give prominent notice with each copy of the Combined Work that |
|
88 |
the Library is used in it and that the Library and its use are |
|
89 |
covered by this License. |
|
90 |
|
|
91 |
b) Accompany the Combined Work with a copy of the GNU GPL and this license |
|
92 |
document. |
|
93 |
|
|
94 |
c) For a Combined Work that displays copyright notices during |
|
95 |
execution, include the copyright notice for the Library among |
|
96 |
these notices, as well as a reference directing the user to the |
|
97 |
copies of the GNU GPL and this license document. |
|
98 |
|
|
99 |
d) Do one of the following: |
|
100 |
|
|
101 |
0) Convey the Minimal Corresponding Source under the terms of this |
|
102 |
License, and the Corresponding Application Code in a form |
|
103 |
suitable for, and under terms that permit, the user to |
|
104 |
recombine or relink the Application with a modified version of |
|
105 |
the Linked Version to produce a modified Combined Work, in the |
|
106 |
manner specified by section 6 of the GNU GPL for conveying |
|
107 |
Corresponding Source. |
|
108 |
|
|
109 |
1) Use a suitable shared library mechanism for linking with the |
|
110 |
Library. A suitable mechanism is one that (a) uses at run time |
|
111 |
a copy of the Library already present on the user's computer |
|
112 |
system, and (b) will operate properly with a modified version |
|
113 |
of the Library that is interface-compatible with the Linked |
|
114 |
Version. |
|
115 |
|
|
116 |
e) Provide Installation Information, but only if you would otherwise |
|
117 |
be required to provide such information under section 6 of the |
|
118 |
GNU GPL, and only to the extent that such information is |
|
119 |
necessary to install and execute a modified version of the |
|
120 |
Combined Work produced by recombining or relinking the |
|
121 |
Application with a modified version of the Linked Version. (If |
|
122 |
you use option 4d0, the Installation Information must accompany |
|
123 |
the Minimal Corresponding Source and Corresponding Application |
|
124 |
Code. If you use option 4d1, you must provide the Installation |
|
125 |
Information in the manner specified by section 6 of the GNU GPL |
|
126 |
for conveying Corresponding Source.) |
|
127 |
|
|
128 |
5. Combined Libraries. |
|
129 |
|
|
130 |
You may place library facilities that are a work based on the |
|
131 |
Library side by side in a single library together with other library |
|
132 |
facilities that are not Applications and are not covered by this |
|
133 |
License, and convey such a combined library under terms of your |
|
134 |
choice, if you do both of the following: |
|
135 |
|
|
136 |
a) Accompany the combined library with a copy of the same work based |
|
137 |
on the Library, uncombined with any other library facilities, |
|
138 |
conveyed under the terms of this License. |
|
139 |
|
|
140 |
b) Give prominent notice with the combined library that part of it |
|
141 |
is a work based on the Library, and explaining where to find the |
|
142 |
accompanying uncombined form of the same work. |
|
143 |
|
|
144 |
6. Revised Versions of the GNU Lesser General Public License. |
|
145 |
|
|
146 |
The Free Software Foundation may publish revised and/or new versions |
|
147 |
of the GNU Lesser General Public License from time to time. Such new |
|
148 |
versions will be similar in spirit to the present version, but may |
|
149 |
differ in detail to address new problems or concerns. |
|
150 |
|
|
151 |
Each version is given a distinguishing version number. If the |
|
152 |
Library as you received it specifies that a certain numbered version |
|
153 |
of the GNU Lesser General Public License "or any later version" |
|
154 |
applies to it, you have the option of following the terms and |
|
155 |
conditions either of that published version or of any later version |
|
156 |
published by the Free Software Foundation. If the Library as you |
|
157 |
received it does not specify a version number of the GNU Lesser |
|
158 |
General Public License, you may choose any version of the GNU Lesser |
|
159 |
General Public License ever published by the Free Software Foundation. |
|
160 |
|
|
161 |
If the Library as you received it specifies that a proxy can decide |
|
162 |
whether future versions of the GNU Lesser General Public License shall |
|
163 |
apply, that proxy's public statement of acceptance of any version is |
|
164 |
permanent authorization for you to choose that version for the |
|
165 |
Library. |
README.md | ||
---|---|---|
1 |
# [hu]man [motion] low-level robot ontrol library |
|
2 |
|
|
3 |
this is the low level robot control software to allow |
|
4 |
human like motion generation on a humanoid robotic head |
|
5 |
|
examples/yarp_icub/CMakeLists.txt | ||
---|---|---|
1 |
PROJECT(icub_humotion) |
|
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_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 |
|
|
28 |
INSTALL(TARGETS ${MAIN} DESTINATION bin) |
|
29 |
|
examples/yarp_icub/CMakeLists.txt.user | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<!DOCTYPE QtCreatorProject> |
|
3 |
<!-- Written by QtCreator 3.0.1, 2015-03-12T13:07: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">{3152ed58-41d1-426c-b17f-dbe12171436a}</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="ProjectExplorer.BuildConfiguration.BuildDirectory">/homes/sschulz/src/flobidev.core/humotion/examples/yarp_icub/qbuild</value> |
|
63 |
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> |
|
64 |
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> |
|
65 |
<value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments"></value> |
|
66 |
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets"/> |
|
67 |
<value type="bool" key="CMakeProjectManager.MakeStep.Clean">false</value> |
|
68 |
<value type="bool" key="CMakeProjectManager.MakeStep.UseNinja">false</value> |
|
69 |
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> |
|
70 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value> |
|
71 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
|
72 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value> |
|
73 |
</valuemap> |
|
74 |
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value> |
|
75 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value> |
|
76 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
|
77 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value> |
|
78 |
</valuemap> |
|
79 |
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1"> |
|
80 |
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> |
|
81 |
<value type="QString" key="CMakeProjectManager.MakeStep.AdditionalArguments">clean</value> |
|
82 |
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets"/> |
|
83 |
<value type="bool" key="CMakeProjectManager.MakeStep.Clean">true</value> |
|
84 |
<value type="bool" key="CMakeProjectManager.MakeStep.UseNinja">false</value> |
|
85 |
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> |
|
86 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value> |
|
87 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
|
88 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value> |
|
89 |
</valuemap> |
|
90 |
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value> |
|
91 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value> |
|
92 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
|
93 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value> |
|
94 |
</valuemap> |
|
95 |
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value> |
|
96 |
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value> |
|
97 |
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/> |
|
98 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Default</value> |
|
99 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Default</value> |
|
100 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value> |
|
101 |
</valuemap> |
|
102 |
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">1</value> |
|
103 |
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0"> |
|
104 |
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> |
|
105 |
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value> |
|
106 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value> |
|
107 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
|
108 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value> |
|
109 |
</valuemap> |
|
110 |
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value> |
|
111 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy locally</value> |
|
112 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
|
113 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value> |
|
114 |
</valuemap> |
|
115 |
<value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value> |
|
116 |
<valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/> |
|
117 |
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0"> |
|
118 |
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/> |
|
119 |
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value> |
|
120 |
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value> |
|
121 |
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value> |
|
122 |
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value> |
|
123 |
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value> |
|
124 |
<value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value> |
|
125 |
<value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value> |
|
126 |
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value> |
|
127 |
<value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">1</value> |
|
128 |
<value type="int" key="Analyzer.Valgrind.NumCallers">25</value> |
|
129 |
<valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/> |
|
130 |
<value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">1</value> |
|
131 |
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value> |
|
132 |
<value type="bool" key="Analyzer.Valgrind.ShowReachable">false</value> |
|
133 |
<value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value> |
|
134 |
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">valgrind</value> |
|
135 |
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds"> |
|
136 |
<value type="int">0</value> |
|
137 |
<value type="int">1</value> |
|
138 |
<value type="int">2</value> |
|
139 |
<value type="int">3</value> |
|
140 |
<value type="int">4</value> |
|
141 |
<value type="int">5</value> |
|
142 |
<value type="int">6</value> |
|
143 |
<value type="int">7</value> |
|
144 |
<value type="int">8</value> |
|
145 |
<value type="int">9</value> |
|
146 |
<value type="int">10</value> |
|
147 |
<value type="int">11</value> |
|
148 |
<value type="int">12</value> |
|
149 |
<value type="int">13</value> |
|
150 |
<value type="int">14</value> |
|
151 |
</valuelist> |
|
152 |
<value type="QString" key="CMakeProjectManager.CMakeRunConfiguation.Title">icub_humotion_server</value> |
|
153 |
<value type="QString" key="CMakeProjectManager.CMakeRunConfiguration.Arguments"></value> |
|
154 |
<value type="bool" key="CMakeProjectManager.CMakeRunConfiguration.UseTerminal">false</value> |
|
155 |
<value type="QString" key="CMakeProjectManager.CMakeRunConfiguration.UserWorkingDirectory"></value> |
|
156 |
<value type="int" key="PE.EnvironmentAspect.Base">-1</value> |
|
157 |
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> |
|
158 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">icub_humotion_server</value> |
|
159 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> |
|
160 |
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeRunConfiguration.icub_humotion_server</value> |
|
161 |
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value> |
|
162 |
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value> |
|
163 |
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value> |
|
164 |
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value> |
|
165 |
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value> |
|
166 |
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value> |
|
167 |
</valuemap> |
|
168 |
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value> |
|
169 |
</valuemap> |
|
170 |
</data> |
|
171 |
<data> |
|
172 |
<variable>ProjectExplorer.Project.TargetCount</variable> |
|
173 |
<value type="int">1</value> |
|
174 |
</data> |
|
175 |
<data> |
|
176 |
<variable>ProjectExplorer.Project.Updater.EnvironmentId</variable> |
|
177 |
<value type="QByteArray">{ccede451-c1b6-4b92-a13d-14bd6a65dd35}</value> |
|
178 |
</data> |
|
179 |
<data> |
|
180 |
<variable>ProjectExplorer.Project.Updater.FileVersion</variable> |
|
181 |
<value type="int">15</value> |
|
182 |
</data> |
|
183 |
</qtcreator> |
examples/yarp_icub/include/icub_data_receiver.h | ||
---|---|---|
1 |
#pragma once |
|
2 |
#include <humotion/server/joint_interface.h> |
|
3 |
#include <boost/bimap.hpp> |
|
4 |
#include <yarp/dev/PolyDriver.h> |
|
5 |
#include <yarp/dev/IControlLimits2.h> |
|
6 |
#include <yarp/dev/ControlBoardInterfaces.h> |
|
7 |
#include <yarp/os/Time.h> |
|
8 |
#include <yarp/sig/Vector.h> |
|
9 |
#include "icub_jointinterface.h" |
|
10 |
#include <humotion/server/server.h> |
|
11 |
#include <yarp/os/Network.h> |
|
12 |
#include <yarp/os/RateThread.h> |
|
13 |
#include <yarp/os/Time.h> |
|
14 |
#include <yarp/os/Property.h> |
|
15 |
#include <yarp/dev/ControlBoardInterfaces.h> |
|
16 |
#include "icub_jointinterface.h" |
|
17 |
|
|
18 |
//forward declaration to solve loop |
|
19 |
class iCubJointInterface; |
|
20 |
|
|
21 |
class iCubDataReceiver : public yarp::os::RateThread{ |
|
22 |
public: |
|
23 |
iCubDataReceiver(int period, yarp::dev::IEncoders *_iencs, iCubJointInterface *_icub_jointinterface); |
|
24 |
bool threadInit(); |
|
25 |
void threadRelease(); |
|
26 |
void run(); |
|
27 |
private: |
|
28 |
double get_timestamp_ms(); |
|
29 |
|
|
30 |
yarp::sig::Vector positions; |
|
31 |
yarp::sig::Vector velocities; |
|
32 |
yarp::sig::Vector commands; |
|
33 |
|
|
34 |
yarp::dev::IEncoders *iencs; |
|
35 |
iCubJointInterface *icub_jointinterface; |
|
36 |
}; |
|
37 |
|
examples/yarp_icub/include/icub_jointinterface.h | ||
---|---|---|
1 |
#pragma once |
|
2 |
#include <humotion/server/joint_interface.h> |
|
3 |
#include <boost/bimap.hpp> |
|
4 |
#include <yarp/dev/PolyDriver.h> |
|
5 |
#include <yarp/dev/IControlLimits2.h> |
|
6 |
#include <yarp/dev/ControlBoardInterfaces.h> |
|
7 |
#include <yarp/os/Time.h> |
|
8 |
#include <yarp/sig/Vector.h> |
|
9 |
#include "icub_jointinterface.h" |
|
10 |
#include <humotion/server/server.h> |
|
11 |
#include <yarp/os/Network.h> |
|
12 |
#include <yarp/os/RateThread.h> |
|
13 |
#include <yarp/os/Time.h> |
|
14 |
#include <yarp/os/Property.h> |
|
15 |
#include <yarp/os/Port.h> |
|
16 |
#include <yarp/dev/ControlBoardInterfaces.h> |
|
17 |
#include "icub_data_receiver.h" |
|
18 |
|
|
19 |
class iCubDataReceiver; |
|
20 |
|
|
21 |
class iCubJointInterface : public humotion::server::JointInterface{ |
|
22 |
public: |
|
23 |
iCubJointInterface(std::string scope); |
|
24 |
~iCubJointInterface(); |
|
25 |
|
|
26 |
//void fetch_position(Device *dev, double timestamp); |
|
27 |
//void fetch_speed(Device *dev, double timestamp); |
|
28 |
void fetch_position(int id, double value, double timestamp); |
|
29 |
void fetch_speed(int id, double value, double timestamp); |
|
30 |
void run(); |
|
31 |
|
|
32 |
enum JOINT_ID_ENUM{ |
|
33 |
ICUB_ID_NECK_TILT = 0, |
|
34 |
ICUB_ID_NECK_ROLL = 1, |
|
35 |
ICUB_ID_NECK_PAN = 2, |
|
36 |
ICUB_ID_EYES_BOTH_UD = 3, |
|
37 |
ICUB_ID_EYES_PAN = 4, |
|
38 |
ICUB_ID_EYES_VERGENCE = 5, |
|
39 |
//the following ids are used for remapping: |
|
40 |
ICUB_ID_EYES_LEFT_LR, |
|
41 |
ICUB_ID_EYES_RIGHT_LR, |
|
42 |
ICUB_ID_EYES_LEFT_LID_LOWER, |
|
43 |
ICUB_ID_EYES_LEFT_LID_UPPER, |
|
44 |
ICUB_ID_EYES_RIGHT_LID_LOWER, |
|
45 |
ICUB_ID_EYES_RIGHT_LID_UPPER, |
|
46 |
ICUB_ID_EYES_LEFT_BROW, |
|
47 |
ICUB_ID_EYES_RIGHT_BROW, |
|
48 |
ICUB_ID_LIP_LEFT_UPPER, |
|
49 |
ICUB_ID_LIP_LEFT_LOWER, |
|
50 |
ICUB_ID_LIP_CENTER_UPPER, |
|
51 |
ICUB_ID_LIP_CENTER_LOWER, |
|
52 |
ICUB_ID_LIP_RIGHT_UPPER, |
|
53 |
ICUB_ID_LIP_RIGHT_LOWER, |
|
54 |
ICUB_JOINT_ID_ENUM_SIZE |
|
55 |
}; |
|
56 |
|
|
57 |
static const int MAIN_LOOP_FREQUENCY = 50; |
|
58 |
|
|
59 |
protected: |
|
60 |
void disable_joint(int e); |
|
61 |
void publish_target_position(int e); |
|
62 |
void enable_joint(int e); |
|
63 |
void execute_motion(); |
|
64 |
|
|
65 |
private: |
|
66 |
double get_timestamp_ms(); |
|
67 |
double target_angle[ICUB_JOINT_ID_ENUM_SIZE]; |
|
68 |
double target_angle_previous[ICUB_JOINT_ID_ENUM_SIZE]; |
|
69 |
|
|
70 |
void set_eyelid_angle(double angle); |
|
71 |
void set_eyebrow_angle(int id); |
|
72 |
void set_mouth(); |
|
73 |
|
|
74 |
iCubDataReceiver *icub_data_receiver; |
|
75 |
void init_joints(); |
|
76 |
double lid_angle; |
|
77 |
int lid_opening_previous; |
|
78 |
int previous_mouth_state; |
|
79 |
|
|
80 |
std::string scope; |
|
81 |
yarp::dev::PolyDriver dd; |
|
82 |
yarp::sig::Vector positions; |
|
83 |
yarp::sig::Vector velocities; |
|
84 |
yarp::sig::Vector commands; |
|
85 |
|
|
86 |
yarp::os::BufferedPort<yarp::os::Bottle> emotion_port[4]; |
|
87 |
|
|
88 |
yarp::dev::IVelocityControl *ivel; |
|
89 |
yarp::dev::IPositionControl *ipos; |
|
90 |
yarp::dev::IEncoders *iencs; |
|
91 |
yarp::dev::IControlLimits *ilimits; |
|
92 |
|
|
93 |
void store_min_max(yarp::dev::IControlLimits *ilimits, int id, int e); |
|
94 |
|
|
95 |
float last_pos_eye_vergence; |
|
96 |
float last_pos_eye_pan; |
|
97 |
float last_vel_eye_vergence; |
|
98 |
float last_vel_eye_pan; |
|
99 |
|
|
100 |
void store_joint(int id, float value); |
|
101 |
void set_target_in_positionmode(int id, double value); |
|
102 |
void set_target_in_velocitymode(int id, double value); |
|
103 |
|
|
104 |
|
|
105 |
int convert_enum_to_motorid(int e); |
|
106 |
int convert_motorid_to_enum(int id); |
|
107 |
|
|
108 |
|
|
109 |
typedef boost::bimap<int, int > enum_id_bimap_t; |
|
110 |
typedef enum_id_bimap_t::value_type enum_id_bimap_entry_t; |
|
111 |
enum_id_bimap_t enum_id_bimap; |
|
112 |
}; |
examples/yarp_icub/src/icub_data_receiver.cpp | ||
---|---|---|
1 |
#include "icub_data_receiver.h" |
|
2 |
#include <yarp/os/Property.h> |
|
3 |
using namespace yarp::dev; |
|
4 |
using namespace yarp::sig; |
|
5 |
using namespace yarp::os; |
|
6 |
using namespace std; |
|
7 |
|
|
8 |
iCubDataReceiver::iCubDataReceiver(int period, IEncoders *_iencs, iCubJointInterface *_icub_jointinterface):RateThread(period){ |
|
9 |
iencs = _iencs; |
|
10 |
icub_jointinterface = _icub_jointinterface; |
|
11 |
int joints; |
|
12 |
iencs->getAxes(&joints); |
|
13 |
positions.resize(joints); |
|
14 |
velocities.resize(joints); |
|
15 |
} |
|
16 |
|
|
17 |
bool iCubDataReceiver::threadInit(){ return true; } |
|
18 |
void iCubDataReceiver::threadRelease(){ } |
|
19 |
|
|
20 |
double iCubDataReceiver::get_timestamp_ms(){ |
|
21 |
struct timespec spec; |
|
22 |
clock_gettime(CLOCK_REALTIME, &spec); |
|
23 |
return spec.tv_sec+spec.tv_nsec/1000000000.0; |
|
24 |
} |
|
25 |
|
|
26 |
void iCubDataReceiver::run(){ |
|
27 |
//grab pos+vel data: |
|
28 |
iencs->getEncoders(positions.data()); |
|
29 |
iencs->getEncoderSpeeds(velocities.data()); |
|
30 |
double timestamp = get_timestamp_ms(); |
|
31 |
|
|
32 |
//publish data to humotion |
|
33 |
for(int i=0; i<positions.size(); i++){ |
|
34 |
icub_jointinterface->fetch_position(i, positions[i], timestamp); |
|
35 |
icub_jointinterface->fetch_speed(i, velocities[i], timestamp); |
|
36 |
} |
|
37 |
|
|
38 |
//tell humotion to update lid angle (hack) |
|
39 |
icub_jointinterface->fetch_position(100, 0.0, timestamp); |
|
40 |
//fixme: use real id |
|
41 |
} |
examples/yarp_icub/src/icub_jointinterface.cpp | ||
---|---|---|
1 |
#include "icub_jointinterface.h" |
|
2 |
#include <yarp/os/Property.h> |
|
3 |
using namespace yarp::dev; |
|
4 |
using namespace yarp::sig; |
|
5 |
using namespace yarp::os; |
|
6 |
using namespace std; |
|
7 |
/*running: |
|
8 |
/media/local_data/sschulz/iros15/icub-nightly/share/iCub/contexts/simConfig:> iCub_SIM |
|
9 |
/media/local_data/sschulz/iros15/icub-nightly/share/iCub/contexts/simFaceExpressions:> ../../../../bin/simFaceExpressions |
|
10 |
yarp connect /face/eyelids /icubSim/face/eyelids |
|
11 |
yarp connect /face/image/out /icubSim/texture/face |
|
12 |
|
|
13 |
TEST: yarp write /writer /icubSim/face/raw/in |
|
14 |
|
|
15 |
http://wiki.icub.org/wiki/Motor_control |
|
16 |
*/ |
|
17 |
|
|
18 |
//WARNING: DO NOT CHANGE THIS; VELOCITYMODE IS NOT YET IMPLEMENTED |
|
19 |
#define POSITION_CONTROL 1 |
|
20 |
|
|
21 |
|
|
22 |
//! constructor |
|
23 |
iCubJointInterface::iCubJointInterface(string _scope) : humotion::server::JointInterface(){ |
|
24 |
scope = _scope; |
|
25 |
|
|
26 |
|
|
27 |
//add mapping from ids to enums: |
|
28 |
//this might look strange at the first sight but we need to have a generic |
|
29 |
//way to acces joints from libhumotion. therefore the lib uses its enum with ID_* enum ids |
|
30 |
//to access the joints. now we need to define a mapping to map those to our motor ids. |
|
31 |
//this is what we use the enum bimap for (convertion fro/to motorid is handled |
|
32 |
//by \sa convert_enum_to_motorid() and \sa convert_motorid_to_enum() lateron |
|
33 |
|
|
34 |
//MOUTH |
|
35 |
enum_id_bimap.insert(enum_id_bimap_entry_t(ICUB_ID_LIP_LEFT_UPPER, ID_LIP_LEFT_UPPER)); |
|
36 |
enum_id_bimap.insert(enum_id_bimap_entry_t(ICUB_ID_LIP_LEFT_LOWER, ID_LIP_LEFT_LOWER)); |
|
37 |
enum_id_bimap.insert(enum_id_bimap_entry_t(ICUB_ID_LIP_CENTER_UPPER, ID_LIP_CENTER_UPPER)); |
|
38 |
enum_id_bimap.insert(enum_id_bimap_entry_t(ICUB_ID_LIP_CENTER_LOWER, ID_LIP_CENTER_LOWER)); |
|
39 |
enum_id_bimap.insert(enum_id_bimap_entry_t(ICUB_ID_LIP_RIGHT_UPPER, ID_LIP_RIGHT_UPPER)); |
|
40 |
enum_id_bimap.insert(enum_id_bimap_entry_t(ICUB_ID_LIP_RIGHT_LOWER, ID_LIP_RIGHT_LOWER)); |
|
41 |
|
|
42 |
//NECK |
|
43 |
enum_id_bimap.insert(enum_id_bimap_entry_t(ICUB_ID_NECK_PAN, ID_NECK_PAN)); |
|
44 |
enum_id_bimap.insert(enum_id_bimap_entry_t(ICUB_ID_NECK_TILT, ID_NECK_TILT)); |
|
45 |
enum_id_bimap.insert(enum_id_bimap_entry_t(ICUB_ID_NECK_ROLL, ID_NECK_ROLL)); |
|
46 |
|
|
47 |
//EYES |
|
48 |
enum_id_bimap.insert(enum_id_bimap_entry_t(ICUB_ID_EYES_LEFT_LR, ID_EYES_LEFT_LR)); |
|
49 |
enum_id_bimap.insert(enum_id_bimap_entry_t(ICUB_ID_EYES_RIGHT_LR, ID_EYES_RIGHT_LR)); |
|
50 |
enum_id_bimap.insert(enum_id_bimap_entry_t(ICUB_ID_EYES_BOTH_UD, ID_EYES_BOTH_UD)); |
|
51 |
|
|
52 |
//EYELIDS |
|
53 |
enum_id_bimap.insert(enum_id_bimap_entry_t(ICUB_ID_EYES_LEFT_LID_LOWER, ID_EYES_LEFT_LID_LOWER)); |
|
54 |
enum_id_bimap.insert(enum_id_bimap_entry_t(ICUB_ID_EYES_LEFT_LID_UPPER, ID_EYES_LEFT_LID_UPPER)); |
|
55 |
enum_id_bimap.insert(enum_id_bimap_entry_t(ICUB_ID_EYES_LEFT_BROW, ID_EYES_LEFT_BROW)); |
|
56 |
|
|
57 |
enum_id_bimap.insert(enum_id_bimap_entry_t(ICUB_ID_EYES_RIGHT_LID_LOWER, ID_EYES_RIGHT_LID_LOWER)); |
|
58 |
enum_id_bimap.insert(enum_id_bimap_entry_t(ICUB_ID_EYES_RIGHT_LID_UPPER,ID_EYES_RIGHT_LID_UPPER)); |
|
59 |
enum_id_bimap.insert(enum_id_bimap_entry_t(ICUB_ID_EYES_RIGHT_BROW, ID_EYES_RIGHT_BROW)); |
|
60 |
|
|
61 |
Property options; |
|
62 |
options.put("device", "remote_controlboard"); |
|
63 |
options.put("local", "/local/head"); |
|
64 |
options.put("remote", scope+"/head"); |
|
65 |
dd.open(options); |
|
66 |
|
|
67 |
//fetch views: |
|
68 |
dd.view(iencs); |
|
69 |
dd.view(ipos); |
|
70 |
dd.view(ivel); |
|
71 |
dd.view(ilimits); |
|
72 |
|
|
73 |
if ( (!iencs) || (!ipos) || (!ilimits) || (!ivel)){ |
|
74 |
printf("> ERROR: failed to open icub views\n"); |
|
75 |
exit(EXIT_FAILURE); |
|
76 |
} |
|
77 |
|
|
78 |
int joints; |
|
79 |
|
|
80 |
//tell humotion about min/max joint values: |
|
81 |
init_joints(); |
|
82 |
|
|
83 |
iencs->getAxes(&joints); |
|
84 |
positions.resize(joints); |
|
85 |
velocities.resize(joints); |
|
86 |
commands.resize(joints); |
|
87 |
|
|
88 |
//set position mode: |
|
89 |
if (POSITION_CONTROL){ |
|
90 |
commands=200000.0; |
|
91 |
ipos->setRefAccelerations(commands.data()); |
|
92 |
ipos->setPositionMode(); |
|
93 |
}else{ |
|
94 |
ivel->setVelocityMode(); |
|
95 |
commands=1000000; |
|
96 |
ivel->setRefAccelerations(commands.data()); |
|
97 |
} |
|
98 |
|
|
99 |
//attach to facial expressions: |
|
100 |
string emotion_scope = scope + "/face/raw/in"; |
|
101 |
printf("> opening connection to %s\n", emotion_scope.c_str()); |
|
102 |
|
|
103 |
for(int i=0; i<4; i++){ |
|
104 |
//strange, if we use one output port only the first command is executed?! flushing issues? |
|
105 |
string emotion_port_out = "/emotionwriter" + to_string(i); |
|
106 |
if (!emotion_port[i].open(emotion_port_out.c_str())){ |
|
107 |
printf("> ERROR: failed to open to %s\n",emotion_port_out.c_str()); |
|
108 |
exit(EXIT_FAILURE); |
|
109 |
} |
|
110 |
if (!Network::connect(emotion_port_out.c_str(), emotion_scope.c_str())){ |
|
111 |
printf("> ERROR: failed to connect emotion ports\n"); |
|
112 |
exit(EXIT_FAILURE); |
|
113 |
} |
|
114 |
} |
|
115 |
} |
|
116 |
|
|
117 |
//! destructor |
|
118 |
iCubJointInterface::~iCubJointInterface(){ |
|
119 |
} |
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
//! conversion table for humotion motor ids to our ids: |
|
124 |
//! \param enum from JointInterface::JOINT_ID_ENUM |
|
125 |
//! \return int value of motor id |
|
126 |
int iCubJointInterface::convert_enum_to_motorid(int e){ |
|
127 |
enum_id_bimap_t::right_const_iterator it = enum_id_bimap.right.find(e); |
|
128 |
if(it == enum_id_bimap.right.end()) { |
|
129 |
//key does not exists, we are not interested in that dataset, return -1 |
|
130 |
return -1; |
|
131 |
} |
|
132 |
return it->second; |
|
133 |
} |
|
134 |
|
|
135 |
|
|
136 |
//! conversion table for our ids to humotion motor ids: |
|
137 |
//! \param int value of motor id |
|
138 |
//! \return enum from JointInterface::JOINT_ID_ENUM |
|
139 |
int iCubJointInterface::convert_motorid_to_enum(int id){ |
|
140 |
enum_id_bimap_t::left_const_iterator it = enum_id_bimap.left.find(id); |
|
141 |
if(it == enum_id_bimap.left.end()) { |
|
142 |
//key does not exists, we are not interested in that dataset, return -1 |
|
143 |
return -1; |
|
144 |
} |
|
145 |
return it->second; |
|
146 |
} |
|
147 |
|
|
148 |
//! special command to set eyelid angle |
|
149 |
//! \param angle in degrees |
|
150 |
void iCubJointInterface::set_eyelid_angle(double angle){ |
|
151 |
if (emotion_port[0].getOutputCount()>0){ |
|
152 |
//try to set the value based on the upper one |
|
153 |
//some guesses from the sim: S30 = 0° / S40 = 10° |
|
154 |
int opening = (25.0 + 0.8*angle); |
|
155 |
opening = min(48, max(24, opening)); |
|
156 |
|
|
157 |
if (opening == lid_opening_previous){ |
|
158 |
//no update necessary |
|
159 |
return; |
|
160 |
} |
|
161 |
|
|
162 |
lid_angle = angle; |
|
163 |
lid_opening_previous = opening; |
|
164 |
|
|
165 |
char buf[20]; |
|
166 |
sprintf(buf, "S%2d", opening); |
|
167 |
|
|
168 |
//printf("> SETTING EYELID '%s' (%f -> %d)\n",buf,angle,opening); |
|
169 |
Bottle &cmd = emotion_port[0].prepare(); |
|
170 |
cmd.clear(); |
|
171 |
cmd.addString(buf); |
|
172 |
emotion_port[0].write(); |
|
173 |
}else{ |
|
174 |
printf("> ERROR: no icub emotion output\n"); |
|
175 |
exit(EXIT_FAILURE); |
|
176 |
} |
|
177 |
} |
|
178 |
|
|
179 |
//! special command to set the eyebrow angle |
|
180 |
//! \param id {0=left, 1=right) |
|
181 |
//! \param angle in degrees |
|
182 |
void iCubJointInterface::set_eyebrow_angle(int id){ |
|
183 |
int port_id; |
|
184 |
if (id == ICUB_ID_EYES_LEFT_BROW){ |
|
185 |
port_id = 1; |
|
186 |
}else{ |
|
187 |
port_id = 2; |
|
188 |
} |
|
189 |
|
|
190 |
if (emotion_port[port_id].getOutputCount()>0){ |
|
191 |
double angle = target_angle[id]; |
|
192 |
int icub_val = 0; |
|
193 |
|
|
194 |
//swap rotation direction: |
|
195 |
if (id==ICUB_ID_EYES_LEFT_BROW) angle = -angle; |
|
196 |
|
|
197 |
//convert to icub representation |
|
198 |
if (angle < -20){ |
|
199 |
icub_val = 1; |
|
200 |
}else if (angle<10){ |
|
201 |
icub_val = 2; |
|
202 |
}else if (angle<20){ |
|
203 |
icub_val = 4; |
|
204 |
}else{ |
|
205 |
icub_val = 8; |
|
206 |
} |
|
207 |
|
|
208 |
//make sure to update only on new values: |
|
209 |
if (icub_val == target_angle_previous[id]){ |
|
210 |
//no updata necessary |
|
211 |
return; |
|
212 |
} |
|
213 |
|
|
214 |
//store actual value: |
|
215 |
target_angle_previous[id] = icub_val; |
|
216 |
|
|
217 |
|
|
218 |
string cmd_s; |
|
219 |
if (id==ICUB_ID_EYES_LEFT_BROW){ |
|
220 |
cmd_s = "L0" + to_string(icub_val); |
|
221 |
}else{ |
|
222 |
cmd_s = "R0" + to_string(icub_val); |
|
223 |
} |
|
224 |
|
|
225 |
printf("> SETTING EYEBROW %d (%f -> %s)\n",id,angle,cmd_s.c_str()); |
|
226 |
|
|
227 |
Bottle &cmd = emotion_port[port_id].prepare(); |
|
228 |
cmd.clear(); |
|
229 |
cmd.addString(cmd_s); |
|
230 |
emotion_port[port_id].write(); |
|
231 |
}else{ |
|
232 |
printf("> ERROR: no icub emotion output\n"); |
|
233 |
exit(EXIT_FAILURE); |
|
234 |
} |
|
235 |
} |
|
236 |
|
|
237 |
void iCubJointInterface::run(){ |
|
238 |
iCubDataReceiver *data_receiver = new iCubDataReceiver(10/*1000.0 / MAIN_LOOP_FREQUENCY*/, iencs, this); |
|
239 |
data_receiver->start(); |
|
240 |
} |
|
241 |
|
|
242 |
//! set the target position of a joint |
|
243 |
//! \param enum id of joint |
|
244 |
//! \param float value |
|
245 |
void iCubJointInterface::publish_target_position(int e){ |
|
246 |
//first: convert humotion enum to our enum: |
|
247 |
int id = convert_enum_to_motorid(e); |
|
248 |
if (id == -1){ |
|
249 |
return; //we are not interested in that data, so we just return here |
|
250 |
} |
|
251 |
|
|
252 |
if (id == ICUB_ID_NECK_PAN){ |
|
253 |
//PAN seems to be swapped |
|
254 |
store_joint(ICUB_ID_NECK_PAN, -joint_target[e]); |
|
255 |
}else if ((id == ICUB_ID_EYES_LEFT_LR) || ( id == ICUB_ID_EYES_RIGHT_LR)){ |
|
256 |
//icub handles eyes differently, we have to set pan angle + vergence |
|
257 |
float pan = (joint_target[ID_EYES_LEFT_LR] + joint_target[ID_EYES_RIGHT_LR]) / 2; |
|
258 |
float vergence = (joint_target[ID_EYES_LEFT_LR] - joint_target[ID_EYES_RIGHT_LR]); |
|
259 |
//printf("EYEDBG %3.2f %3.2f --_> pan %3.2f verg=%3.2f\n",joint_target[ID_EYES_LEFT_LR], joint_target[ID_EYES_RIGHT_LR],pan,vergence); |
|
260 |
|
|
261 |
store_joint(ICUB_ID_EYES_PAN, pan); |
|
262 |
store_joint(ICUB_ID_EYES_VERGENCE, vergence); |
|
263 |
}else{ |
|
264 |
store_joint(id, joint_target[e]); |
|
265 |
} |
|
266 |
} |
|
267 |
|
|
268 |
|
|
269 |
//! set the target position of a joint |
|
270 |
//! \param id of joint |
|
271 |
//! \param float value of position |
|
272 |
void iCubJointInterface::store_joint(int id, float value){ |
|
273 |
//printf("> set joint %d = %f\n",id,value); |
|
274 |
target_angle[id] = value; |
|
275 |
//ipos->positionMove(id, value); |
|
276 |
} |
|
277 |
|
|
278 |
//! execute a move in position mode |
|
279 |
//! \param id of joint |
|
280 |
//! \param angle |
|
281 |
void iCubJointInterface::set_target_in_positionmode(int id, double value){ |
|
282 |
if (id>ICUB_ID_EYES_VERGENCE){ |
|
283 |
printf("> ERROR: set_target_positionmode(id=%d, %3.2f) not supported for this id\n",id,value); |
|
284 |
return; |
|
285 |
} |
|
286 |
#if 0 |
|
287 |
//set speed cacluated as in velocity + set position -> replicates smoothmotion from flobi?! |
|
288 |
|
|
289 |
//first: calculate necessary speed to reach the given target within the next clock tick: |
|
290 |
double distance = value - target_angle_previous[id]; |
|
291 |
//make the motion smooth: we want to reach 85% of the target in the next iteration: |
|
292 |
//calculate speed for that: |
|
293 |
double speed = 0.85 * distance * ((double)MAIN_LOOP_FREQUENCY); |
|
294 |
|
|
295 |
//set up speed for controller: |
|
296 |
ipos->setRefSpeed(id, speed); |
|
297 |
#endif |
|
298 |
//execute motion |
|
299 |
ipos->positionMove(id, value); |
|
300 |
} |
|
301 |
|
|
302 |
//! execute a move in velocity mode |
|
303 |
//! \param id of joint |
|
304 |
//! \param angle |
|
305 |
void iCubJointInterface::set_target_in_velocitymode(int id, double value){ |
|
306 |
//first: calculate necessary speed to reach the given target within the next clock tick: |
|
307 |
double distance = value - target_angle_previous[id]; |
|
308 |
//make the motion smooth: we want to reach 85% of the target in the next iteration: |
|
309 |
distance = 0.85 * distance; |
|
310 |
//calculate speed |
|
311 |
double speed = distance * ((double)MAIN_LOOP_FREQUENCY); |
|
312 |
//execute: |
|
313 |
ivel->velocityMove(id, speed); |
|
314 |
//if (id == ICUB_ID_NECK_PAN) printf("> VEL now=%3.2f target=%3.2f --> dist=%3.2f speed=%3.2f\n",target_angle_previous[id],value,distance,speed); |
|
315 |
|
|
316 |
target_angle_previous[id] = get_ts_position(convert_motorid_to_enum(id)).get_newest_value(); |
|
317 |
} |
|
318 |
|
|
319 |
//! actually execute the scheduled motion commands |
|
320 |
void iCubJointInterface::execute_motion(){ |
|
321 |
|
|
322 |
// set up neck and eye motion commands: |
|
323 |
if (POSITION_CONTROL){ |
|
324 |
//position control |
|
325 |
for(int i=ICUB_ID_NECK_TILT; i<=ICUB_ID_EYES_VERGENCE; i++){ |
|
326 |
set_target_in_positionmode(i, target_angle[i]); |
|
327 |
} |
|
328 |
}else{ |
|
329 |
//velocity control |
|
330 |
for(int i=ICUB_ID_NECK_TILT; i<=ICUB_ID_EYES_VERGENCE; i++){ |
|
331 |
set_target_in_velocitymode(i, target_angle[i]); |
|
332 |
} |
|
333 |
} |
|
334 |
//printf("> TARGET PAN = %3.2f\n",target_angle[ICUB_ID_NECK_PAN]); |
|
335 |
|
|
336 |
|
|
337 |
//eyelids: unfortuantely the icub has only 1dof for eyelids, so we use only one dof here: |
|
338 |
set_eyelid_angle(target_angle[ICUB_ID_EYES_RIGHT_LID_UPPER]); |
|
339 |
|
|
340 |
//eyebrows are set using a special command as well: |
|
341 |
set_eyebrow_angle(ICUB_ID_EYES_LEFT_BROW); |
|
342 |
set_eyebrow_angle(ICUB_ID_EYES_RIGHT_BROW); |
|
343 |
|
|
344 |
//mouth |
|
345 |
set_mouth(); |
|
346 |
|
|
347 |
|
|
348 |
} |
|
349 |
|
|
350 |
void iCubJointInterface::set_mouth(){ |
|
351 |
//convert from 6DOF mouth displacement to icub leds: |
|
352 |
int led_value = 0; |
|
353 |
|
|
354 |
//fetch center opening: |
|
355 |
double center_opening = target_angle[ICUB_ID_LIP_CENTER_LOWER] - target_angle[ICUB_ID_LIP_CENTER_UPPER]; |
|
356 |
bool mouth_open = (center_opening>15.0)?true:false; |
|
357 |
|
|
358 |
//side of mouth high or low? |
|
359 |
double center_avg = (target_angle[ICUB_ID_LIP_CENTER_LOWER] + target_angle[ICUB_ID_LIP_CENTER_UPPER])/2.0; |
|
360 |
double left_avg = (target_angle[ICUB_ID_LIP_LEFT_LOWER] + target_angle[ICUB_ID_LIP_LEFT_UPPER])/2.0; |
|
361 |
double right_avg = (target_angle[ICUB_ID_LIP_RIGHT_LOWER] + target_angle[ICUB_ID_LIP_RIGHT_UPPER])/2.0; |
|
362 |
|
|
363 |
//happy, neutral or sad? |
|
364 |
double diff_l = center_avg - left_avg; |
|
365 |
double diff_r = center_avg - right_avg; |
|
366 |
double diff = (diff_l+diff_r)/2.0; |
|
367 |
|
|
368 |
if (diff > 2.0){ |
|
369 |
if (mouth_open){ |
|
370 |
led_value = 0x14; |
|
371 |
}else{ |
|
372 |
if (diff > 2.6){ |
|
373 |
led_value = 0x0A; |
|
374 |
}else{ |
|
375 |
led_value = 0x0B; |
|
376 |
} |
|
377 |
} |
|
378 |
}else if (diff < -3.0){ |
|
379 |
if (mouth_open){ |
|
380 |
led_value = 0x06; |
|
381 |
}else{ |
|
382 |
led_value = 0x18; |
|
383 |
} |
|
384 |
}else if (diff < -2.0){ |
|
385 |
if (mouth_open){ |
|
386 |
led_value = 0x04; //0x25; |
|
387 |
}else{ |
|
388 |
led_value = 0x08; |
|
389 |
} |
|
390 |
}else{ |
|
391 |
if (mouth_open){ |
|
392 |
led_value = 0x16; |
|
393 |
}else{ |
|
394 |
led_value = 0x08; |
|
395 |
} |
|
396 |
} |
|
397 |
|
|
398 |
|
|
399 |
if (led_value == previous_mouth_state){ |
|
400 |
//no update necessary |
|
401 |
return; |
|
402 |
} |
|
403 |
|
|
404 |
previous_mouth_state = led_value; |
|
405 |
|
|
406 |
//convert to string: |
|
407 |
char buf[10]; |
|
408 |
sprintf(buf, "M%02X",led_value); |
|
409 |
|
|
410 |
/*printf("> sending mouth '%s'\n",buf); |
|
411 |
printf("> mouth angles: %3.2f %3.2f %3.2f\n",target_angle[ICUB_ID_LIP_LEFT_UPPER],target_angle[ICUB_ID_LIP_CENTER_UPPER],target_angle[ICUB_ID_LIP_RIGHT_UPPER]); |
|
412 |
printf(" mouth %3.2f %3.2f %3.2f\n",target_angle[ICUB_ID_LIP_LEFT_LOWER],target_angle[ICUB_ID_LIP_CENTER_LOWER],target_angle[ICUB_ID_LIP_RIGHT_LOWER]); |
|
413 |
printf(" mouth open=%3.2f diff=%3.2f\n", center_opening, diff);*/ |
|
414 |
|
|
415 |
//add mouth: |
|
416 |
Bottle &cmd = emotion_port[3].prepare(); |
|
417 |
cmd.clear(); |
|
418 |
cmd.addString(buf); |
|
419 |
emotion_port[3].write(); |
|
420 |
|
|
421 |
|
|
422 |
//store joint values which we do not handle on icub here: |
|
423 |
double timestamp = get_timestamp_ms(); |
|
424 |
JointInterface::store_incoming_position(ID_LIP_LEFT_UPPER, target_angle[ICUB_ID_LIP_LEFT_UPPER], timestamp); |
|
425 |
JointInterface::store_incoming_position(ID_LIP_LEFT_LOWER, target_angle[ICUB_ID_LIP_LEFT_LOWER], timestamp); |
|
426 |
JointInterface::store_incoming_position(ID_LIP_CENTER_UPPER, target_angle[ICUB_ID_LIP_CENTER_UPPER], timestamp); |
|
427 |
JointInterface::store_incoming_position(ID_LIP_CENTER_LOWER, target_angle[ICUB_ID_LIP_CENTER_LOWER], timestamp); |
|
428 |
JointInterface::store_incoming_position(ID_LIP_RIGHT_UPPER, target_angle[ICUB_ID_LIP_RIGHT_UPPER], timestamp); |
|
429 |
JointInterface::store_incoming_position(ID_LIP_RIGHT_LOWER, target_angle[ICUB_ID_LIP_RIGHT_LOWER], timestamp); |
|
430 |
|
|
431 |
} |
|
432 |
|
|
433 |
double iCubJointInterface::get_timestamp_ms(){ |
|
434 |
struct timespec spec; |
|
435 |
clock_gettime(CLOCK_REALTIME, &spec); |
|
436 |
return spec.tv_sec*1000 + spec.tv_nsec / 1.0e6; |
|
437 |
} |
|
438 |
|
|
439 |
//! set the current position of a joint |
|
440 |
//! \param id of joint |
|
441 |
//! \param float value of position |
|
442 |
//! \param double timestamp |
|
443 |
void iCubJointInterface::fetch_position(int id, double value, double timestamp){ |
|
444 |
//store joint based on id: |
|
445 |
switch(id){ |
|
446 |
default: |
|
447 |
printf("> ERROR: unhandled joint id %d\n",id); |
|
448 |
return; |
|
449 |
|
|
450 |
case(100): |
|
451 |
JointInterface::store_incoming_position(ID_EYES_RIGHT_LID_UPPER, lid_angle, timestamp); |
|
452 |
break; |
|
453 |
|
|
454 |
case(2): |
|
455 |
//PAN is inverted! |
|
456 |
JointInterface::store_incoming_position(ID_NECK_PAN, -value, timestamp); |
|
457 |
break; |
|
458 |
|
|
459 |
case(0): |
|
460 |
JointInterface::store_incoming_position(ID_NECK_TILT, value, timestamp); |
|
461 |
break; |
|
462 |
|
|
463 |
case(1): |
|
464 |
JointInterface::store_incoming_position(ID_NECK_ROLL, value, timestamp); |
|
465 |
break; |
|
466 |
|
|
467 |
case(3): |
|
468 |
JointInterface::store_incoming_position(ID_EYES_BOTH_UD, value, timestamp); |
|
469 |
break; |
|
470 |
|
|
471 |
//icub handles eyes differently, we have to set pan angle + vergence |
|
472 |
case(4): {//pan |
|
473 |
last_pos_eye_pan = value; |
|
474 |
float left = last_pos_eye_pan + last_pos_eye_vergence/2.0; |
|
475 |
float right = last_pos_eye_pan - last_pos_eye_vergence/2.0; |
|
476 |
|
|
477 |
//printf("> eye: pan=%3.2f vergence=%3.2f --> L=%3.2f R=%3.2f\n", last_pos_eye_pan, last_pos_eye_vergence, left, right); |
|
478 |
JointInterface::store_incoming_position(ID_EYES_LEFT_LR, left, timestamp); |
|
479 |
JointInterface::store_incoming_position(ID_EYES_RIGHT_LR, right, timestamp); |
|
480 |
break; |
|
481 |
} |
|
482 |
|
|
483 |
case(5): { //vergence |
|
484 |
last_pos_eye_vergence = value; |
|
485 |
float left = last_pos_eye_pan + last_pos_eye_vergence/2.0; |
|
486 |
float right = last_pos_eye_pan - last_pos_eye_vergence/2.0; |
|
487 |
|
|
488 |
//printf("> eye: pan=%3.2f vergence=%3.2f --> L=%3.2f R=%3.2f\n", last_pos_eye_pan, last_pos_eye_vergence, left, right); |
|
489 |
JointInterface::store_incoming_position(ID_EYES_LEFT_LR, left, timestamp); |
|
490 |
JointInterface::store_incoming_position(ID_EYES_RIGHT_LR, right, timestamp); |
|
491 |
break; |
|
492 |
} |
|
493 |
} |
|
494 |
|
|
495 |
|
|
496 |
} |
|
497 |
|
|
498 |
//! set the current speed of a joint |
|
499 |
//! \param enum id of joint |
|
500 |
//! \param float value of speed |
|
501 |
//! \param double timestamp |
|
502 |
void iCubJointInterface::fetch_speed(int id, double value, double timestamp){ |
|
503 |
|
|
504 |
switch(id){ |
|
505 |
default: |
|
506 |
printf("> ERROR: unhandled joint id %d\n",id); |
|
507 |
return; |
|
508 |
|
|
509 |
case(2): |
|
510 |
JointInterface::store_incoming_speed(ID_NECK_PAN, value, timestamp); |
|
511 |
break; |
|
512 |
|
|
513 |
case(0): |
|
514 |
JointInterface::store_incoming_speed(ID_NECK_TILT, value, timestamp); |
|
515 |
break; |
|
516 |
|
|
517 |
case(1): |
|
518 |
JointInterface::store_incoming_speed(ID_NECK_ROLL, value, timestamp); |
|
519 |
break; |
|
520 |
|
|
521 |
case(3): |
|
522 |
JointInterface::store_incoming_speed(ID_EYES_BOTH_UD, value, timestamp); |
|
523 |
break; |
|
524 |
|
|
525 |
//icub handles eyes differently, we have to set pan angle + vergence |
|
526 |
case(4): {//pan |
|
527 |
last_vel_eye_pan = value; |
|
528 |
float left = last_vel_eye_pan + last_vel_eye_vergence/2.0; |
|
529 |
float right = last_vel_eye_pan - last_vel_eye_vergence/2.0; |
|
530 |
|
|
531 |
//printf("> eye: velocity pan=%3.2f vergence=%3.2f --> L=%3.2f R=%3.2f\n", last_vel_eye_pan, last_vel_eye_vergence, left, right); |
|
532 |
JointInterface::store_incoming_speed(ID_EYES_LEFT_LR, left, timestamp); |
|
533 |
JointInterface::store_incoming_speed(ID_EYES_RIGHT_LR, right, timestamp); |
|
534 |
break; |
|
535 |
} |
|
536 |
|
|
537 |
case(5): { //vergence |
|
538 |
last_vel_eye_pan = value; |
|
539 |
float left = last_vel_eye_pan + last_vel_eye_vergence/2.0; |
|
540 |
float right = last_vel_eye_pan - last_vel_eye_vergence/2.0; |
|
541 |
|
|
542 |
//printf("> eye: velocity pan=%3.2f vergence=%3.2f --> L=%3.2f R=%3.2f\n", last_vel_eye_pan, last_vel_eye_vergence, left, right); |
|
543 |
JointInterface::store_incoming_speed(ID_EYES_LEFT_LR, left, timestamp); |
|
544 |
JointInterface::store_incoming_speed(ID_EYES_RIGHT_LR, right, timestamp); |
|
545 |
break; |
|
546 |
} |
|
547 |
} |
|
548 |
/* |
|
549 |
JointInterface::store_incoming_speed(ID_LIP_LEFT_UPPER, 0.0, timestamp); |
|
550 |
JointInterface::store_incoming_speed(ID_LIP_LEFT_LOWER, 0.0, timestamp); |
|
551 |
JointInterface::store_incoming_speed(ID_LIP_CENTER_UPPER, 0.0, timestamp); |
|
552 |
JointInterface::store_incoming_speed(ID_LIP_CENTER_LOWER, 0.0, timestamp); |
|
553 |
JointInterface::store_incoming_speed(ID_LIP_RIGHT_UPPER, 0.0, timestamp); |
|
554 |
JointInterface::store_incoming_speed(ID_LIP_RIGHT_LOWER, 0.0, timestamp); |
|
555 |
|
|
556 |
JointInterface::store_incoming_speed(ID_EYES_LEFT_LID_LOWER, 0.0, timestamp); |
|
557 |
JointInterface::store_incoming_speed(ID_EYES_LEFT_LID_UPPER, 0.0, timestamp); |
|
558 |
JointInterface::store_incoming_speed(ID_EYES_LEFT_BROW, 0.0, timestamp); |
|
559 |
|
|
560 |
JointInterface::store_incoming_speed(ID_EYES_RIGHT_LID_LOWER, 0.0, timestamp); |
|
561 |
JointInterface::store_incoming_speed(ID_EYES_RIGHT_LID_UPPER,0.0, timestamp); |
|
562 |
JointInterface::store_incoming_speed(ID_EYES_RIGHT_BROW, 0.0, timestamp);*/ |
|
563 |
/* |
|
564 |
//fetch enum id: |
|
565 |
int e = convert_motorid_to_enum(device->get_device_id()); |
|
566 |
if (e == -1){ |
|
567 |
return; //we are not interested in that data, so we just return here |
|
568 |
} |
|
569 |
|
|
570 |
JointInterface::store_incoming_speed(e, device->get_register(XSC3_REGISTER_MOTORSPEED), timestamp);*/ |
|
571 |
|
|
572 |
} |
|
573 |
/* |
|
574 |
//! conversion table for humotion motor ids to our ids: |
|
575 |
//! \param enum from JointInterface::JOINT_ID_ENUM |
|
576 |
//! \return int value of motor id |
|
577 |
int HumotionJointInterface::convert_enum_to_motorid(int e){ |
|
578 |
enum_id_bimap_t::right_const_iterator it = enum_id_bimap.right.find(e); |
|
579 |
if(it == enum_id_bimap.right.end()) { |
|
580 |
//key does not exists, we are not interested in that dataset, return -1 |
|
581 |
return -1; |
|
582 |
} |
|
583 |
|
|
584 |
return it->second; |
|
585 |
} |
|
586 |
|
|
587 |
|
|
588 |
//! conversion table for our ids to humotion motor ids: |
|
589 |
//! \param int value of motor id |
|
590 |
//! \return enum from JointInterface::JOINT_ID_ENUM |
|
591 |
int HumotionJointInterface::convert_motorid_to_enum(int id){ |
|
592 |
enum_id_bimap_t::left_const_iterator it = enum_id_bimap.left.find(id); |
|
593 |
if(it == enum_id_bimap.left.end()) { |
|
594 |
//key does not exists, we are not interested in that dataset, return -1 |
|
595 |
return -1; |
|
596 |
} |
|
597 |
|
|
598 |
return it->second; |
|
599 |
} |
|
600 |
*/ |
|
601 |
|
|
602 |
//! prepare and enable a joint |
|
603 |
//! NOTE: this should also prefill the min/max positions for this joint |
|
604 |
//! \param the enum id of a joint |
|
605 |
void iCubJointInterface::enable_joint(int e){ |
|
606 |
//FIXME ADD THIS: |
|
607 |
// enable the amplifier and the pid controller on each joint |
|
608 |
/*for (i = 0; i < nj; i++) { |
|
609 |
amp->enableAmp(i); |
|
610 |
pid->enablePid(i); |
|
611 |
}*/ |
|
612 |
|
|
613 |
|
|
614 |
//set up smooth motion controller |
|
615 |
//step1: set up framerate |
|
616 |
//dev->set_register_blocking(XSC3_REGISTER_PID_RAMP, framerate, true); |
|
617 |
|
|
618 |
//step2: set controllertype: |
|
619 |
//printf("> activating smooth motion control for joint id 0x%02X (%s)\n", motor_id, joint_name.c_str()); |
|
620 |
//dev->set_register_blocking(XSC3_REGISTER_PID_CONTROLLER, XSC3_PROTOCOL_PID_CONTROLLERTYPE_SMOOTH_PLAYBACK, true); |
|
621 |
|
|
622 |
//step3: set pid controller: |
|
623 |
/*if ((e == ID_LIP_LEFT_UPPER) || (e == ID_LIP_LEFT_LOWER) || (e == ID_LIP_CENTER_UPPER) || (e == ID_LIP_CENTER_LOWER) || (e == ID_LIP_RIGHT_UPPER) || (e == ID_LIP_RIGHT_LOWER)){ |
|
624 |
printf("> fixing PID i controller value for smooth motion (FIXME: restore old value!!)\n"); |
|
625 |
dev->set_register_blocking(XSC3_REGISTER_CONST_I, 10, true); |
|
626 |
}*/ |
|
627 |
|
|
628 |
//uint16_t result = dev->get_register_blocking_raw(XSC3_REGISTER_PID_CONTROLLER); |
|
629 |
|
|
630 |
//check if setting pid controllertype was successfull: |
|
631 |
/*if (result != XSC3_PROTOCOL_PID_CONTROLLERTYPE_SMOOTH_PLAYBACK){ |
|
632 |
printf("> failed to set smooth motion controller for joint %s (res=0x%04X)\n",joint_name.c_str(),result); |
|
633 |
exit(1); |
|
634 |
}*/ |
|
635 |
|
|
636 |
//fetch min/max: |
|
637 |
// init_joint(e); |
|
638 |
|
|
639 |
//ok fine, now enable motor: |
|
640 |
//printf("> enabling motor %s\n", joint_name.c_str()); |
|
641 |
//dev->set_register_blocking(XSC3_REGISTER_STATUS, XSC3_PROTOCOL_STATUS_BITMASK_MOTOR_ENABLE, true); |
Also available in: Unified diff