Revision 473a6a6c
| examples/meka/CMakeLists.txt | ||
|---|---|---|
| 1 |
PROJECT(icub_humotion)
|
|
| 1 |
PROJECT(meka_humotion_server)
|
|
| 2 | 2 |
cmake_minimum_required(VERSION 2.8) |
| 3 |
SET(MAIN maka_humotion_server) |
|
| 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 () |
|
| 3 | 20 |
|
| 4 | 21 |
FIND_PACKAGE(Boost REQUIRED COMPONENTS system thread) |
| 5 | 22 |
FIND_PACKAGE(humotion) |
| 6 | 23 |
|
| 7 | 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 |
catkin_package( |
|
| 35 |
INCLUDE_DIRS include |
|
| 36 |
LIBRARIES humotion |
|
| 37 |
#CATKIN_DEPENDS message_runtime |
|
| 38 |
#DEPENDS system_lib |
|
| 39 |
) |
|
| 40 |
|
|
| 41 |
include_directories( ${catkin_INCLUDE_DIRS})
|
|
| 8 | 42 |
|
| 9 | 43 |
# add include directories |
| 10 | 44 |
INCLUDE_DIRECTORIES(${YARP_INCLUDE_DIRS} ${ICUB_INCLUDE_DIRS} ${humotion_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} include/)
|
| 11 | 45 |
link_directories(${Boost_LIBRARY_DIRS} ${humotion_LIBRARY_DIRS})
|
| 12 | 46 |
|
| 13 | 47 |
# add required linker flags |
| 14 |
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ICUB_LINK_FLAGS}")
|
|
| 15 |
SET(MAIN icub_humotion_server) |
|
| 16 | 48 |
|
| 49 |
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ICUB_LINK_FLAGS}")
|
|
| 17 | 50 |
file(GLOB DUMMY_HEADER_LIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} include/*.h)
|
| 18 | 51 |
|
| 19 |
ADD_EXECUTABLE(${MAIN} src/main.cpp src/mekajointinterface.cpp src/meka_data_receiver.cpp ${DUMMY_HEADER_LIST})
|
|
| 52 |
#add_dependencies(${MAIN} ${catkin_EXPORTED_TARGETS})
|
|
| 53 |
ADD_EXECUTABLE(${MAIN} src/main.cpp src/mekajointinterface.cpp ${DUMMY_HEADER_LIST})
|
|
| 20 | 54 |
|
| 21 |
TARGET_LINK_LIBRARIES(${MAIN} ${Boost_LIBRARIES} ${humotion_LIBRARIES})
|
|
| 55 |
TARGET_LINK_LIBRARIES(${MAIN} ${Boost_LIBRARIES} ${catkin_LIBRARIES} ${humotion_LIBRARIES})
|
|
| 22 | 56 |
set_property(TARGET ${MAIN} PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
|
| 23 | 57 |
|
| 24 | 58 |
|
| 25 |
INSTALL(TARGETS ${MAIN} DESTINATION bin)
|
|
| 59 |
#INSTALL(TARGETS ${MAIN} DESTINATION bin)
|
|
| 60 |
install(TARGETS ${MAIN}
|
|
| 61 |
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
|
| 62 |
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
|
|
| 63 |
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
|
|
| 64 |
) |
|
| 26 | 65 |
|
| examples/meka/include/mekajointinterface.h | ||
|---|---|---|
| 4 | 4 |
#include <boost/bimap.hpp> |
| 5 | 5 |
//#include "meka_data_receiver.h" |
| 6 | 6 |
//class MekaDataReceiver; |
| 7 |
#include "ros/ros.h" |
|
| 8 |
#include "sensor_msgs/JointState.h" |
|
| 7 | 9 |
|
| 8 | 10 |
class MekaJointInterface : public humotion::server::JointInterface{
|
| 9 | 11 |
public: |
| ... | ... | |
| 12 | 14 |
|
| 13 | 15 |
//void fetch_position(Device *dev, double timestamp); |
| 14 | 16 |
//void fetch_speed(Device *dev, double timestamp); |
| 15 |
void fetch_position(int id, double value, double timestamp); |
|
| 16 |
void fetch_speed(int id, double value, double timestamp); |
|
| 17 |
//void fetch_position(int id, double value, double timestamp);
|
|
| 18 |
//void fetch_speed(int id, double value, double timestamp);
|
|
| 17 | 19 |
void run(); |
| 18 | 20 |
|
| 19 | 21 |
enum JOINT_ID_ENUM{
|
| ... | ... | |
| 50 | 52 |
void execute_motion(); |
| 51 | 53 |
|
| 52 | 54 |
private: |
| 55 |
void incoming_jointstates(const sensor_msgs::JointState & msg); |
|
| 56 |
ros::Subscriber joint_state_subscriber; |
|
| 57 |
|
|
| 58 |
|
|
| 53 | 59 |
double get_timestamp_ms(); |
| 54 | 60 |
double target_angle[ICUB_JOINT_ID_ENUM_SIZE]; |
| 55 | 61 |
double target_angle_previous[ICUB_JOINT_ID_ENUM_SIZE]; |
| examples/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/meka/src/main.cpp | ||
|---|---|---|
| 23 | 23 |
*/ |
| 24 | 24 |
|
| 25 | 25 |
//create humotion interface |
| 26 |
string scope = "/bla";
|
|
| 26 |
string scope = "/"; |
|
| 27 | 27 |
MekaJointInterface *jointinterface = new MekaJointInterface(scope); |
| 28 | 28 |
humotion::server::Server *humotion_server = new humotion::server::Server("/meka", "ROS", jointinterface);
|
| 29 | 29 |
|
| examples/meka/src/mekajointinterface.cpp | ||
|---|---|---|
| 4 | 4 |
//WARNING: DO NOT CHANGE THIS; VELOCITYMODE IS NOT YET IMPLEMENTED |
| 5 | 5 |
#define POSITION_CONTROL 1 |
| 6 | 6 |
|
| 7 |
void MekaJointInterface::incoming_jointstates(const sensor_msgs::JointState & msg){
|
|
| 8 |
//joint_pos_global = msg.position[3]; |
|
| 9 |
cout << msg; |
|
| 10 |
} |
|
| 11 |
|
|
| 7 | 12 |
//! constructor |
| 8 | 13 |
MekaJointInterface::MekaJointInterface(string _scope) : humotion::server::JointInterface(){
|
| 9 | 14 |
scope = _scope; |
| 10 | 15 |
|
| 16 |
//subscribe to meka joint states |
|
| 17 |
ros::NodeHandle n; |
|
| 18 |
joint_state_subscriber = n.subscribe(scope + "joint_states", 150, &MekaJointInterface::incoming_jointstates , this); |
|
| 19 |
|
|
| 20 |
|
|
| 11 | 21 |
//add mapping from ids to enums: |
| 12 | 22 |
//this might look strange at the first sight but we need to have a generic |
| 13 | 23 |
//way to acces joints from libhumotion. therefore the lib uses its enum with ID_* enum ids |
| ... | ... | |
| 103 | 113 |
MekaJointInterface::~MekaJointInterface(){
|
| 104 | 114 |
} |
| 105 | 115 |
|
| 106 |
/* |
|
| 116 |
|
|
| 117 |
|
|
| 118 |
void MekaJointInterface::run(){
|
|
| 119 |
//iCubDataReceiver *data_receiver = new iCubDataReceiver(10/*1000.0 / MAIN_LOOP_FREQUENCY*/, iencs, this); |
|
| 120 |
//data_receiver->start(); |
|
| 121 |
} |
|
| 122 |
|
|
| 123 |
|
|
| 124 |
//! set the target position of a joint |
|
| 125 |
//! \param enum id of joint |
|
| 126 |
//! \param float value |
|
| 127 |
void MekaJointInterface::publish_target_position(int e){
|
|
| 128 |
#if 0 |
|
| 129 |
//first: convert humotion enum to our enum: |
|
| 130 |
int id = convert_enum_to_motorid(e); |
|
| 131 |
if (id == -1){
|
|
| 132 |
return; //we are not interested in that data, so we just return here |
|
| 133 |
} |
|
| 134 |
|
|
| 135 |
if (id == ICUB_ID_NECK_PAN){
|
|
| 136 |
//PAN seems to be swapped |
|
| 137 |
store_joint(ICUB_ID_NECK_PAN, -joint_target[e]); |
|
| 138 |
}else if ((id == ICUB_ID_EYES_LEFT_LR) || ( id == ICUB_ID_EYES_RIGHT_LR)){
|
|
| 139 |
//icub handles eyes differently, we have to set pan angle + vergence |
|
| 140 |
float pan = (joint_target[ID_EYES_LEFT_LR] + joint_target[ID_EYES_RIGHT_LR]) / 2; |
|
| 141 |
float vergence = (joint_target[ID_EYES_LEFT_LR] - joint_target[ID_EYES_RIGHT_LR]); |
|
| 142 |
//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);
|
|
| 143 |
|
|
| 144 |
store_joint(ICUB_ID_EYES_PAN, pan); |
|
| 145 |
store_joint(ICUB_ID_EYES_VERGENCE, vergence); |
|
| 146 |
}else{
|
|
| 147 |
store_joint(id, joint_target[e]); |
|
| 148 |
} |
|
| 149 |
#endif |
|
| 150 |
} |
|
| 151 |
|
|
| 152 |
|
|
| 153 |
//! actually execute the scheduled motion commands |
|
| 154 |
void MekaJointInterface::execute_motion(){
|
|
| 155 |
#if 0 |
|
| 156 |
// set up neck and eye motion commands: |
|
| 157 |
if (POSITION_CONTROL){
|
|
| 158 |
//position control |
|
| 159 |
for(int i=ICUB_ID_NECK_TILT; i<=ICUB_ID_EYES_VERGENCE; i++){
|
|
| 160 |
set_target_in_positionmode(i, target_angle[i]); |
|
| 161 |
} |
|
| 162 |
}else{
|
|
| 163 |
//velocity control |
|
| 164 |
for(int i=ICUB_ID_NECK_TILT; i<=ICUB_ID_EYES_VERGENCE; i++){
|
|
| 165 |
set_target_in_velocitymode(i, target_angle[i]); |
|
| 166 |
} |
|
| 167 |
} |
|
| 168 |
//printf("> TARGET PAN = %3.2f\n",target_angle[ICUB_ID_NECK_PAN]);
|
|
| 169 |
|
|
| 170 |
|
|
| 171 |
//eyelids: unfortuantely the icub has only 1dof for eyelids, so we use only one dof here: |
|
| 172 |
set_eyelid_angle(target_angle[ICUB_ID_EYES_RIGHT_LID_UPPER]); |
|
| 173 |
|
|
| 174 |
//eyebrows are set using a special command as well: |
|
| 175 |
set_eyebrow_angle(ICUB_ID_EYES_LEFT_BROW); |
|
| 176 |
set_eyebrow_angle(ICUB_ID_EYES_RIGHT_BROW); |
|
| 177 |
|
|
| 178 |
//mouth |
|
| 179 |
set_mouth(); |
|
| 180 |
|
|
| 181 |
#endif |
|
| 182 |
} |
|
| 183 |
|
|
| 184 |
|
|
| 185 |
//! prepare and enable a joint |
|
| 186 |
//! NOTE: this should also prefill the min/max positions for this joint |
|
| 187 |
//! \param the enum id of a joint |
|
| 188 |
void MekaJointInterface::enable_joint(int e){
|
|
| 189 |
#if 0 |
|
| 190 |
//FIXME ADD THIS: |
|
| 191 |
// enable the amplifier and the pid controller on each joint |
|
| 192 |
/*for (i = 0; i < nj; i++) {
|
|
| 193 |
amp->enableAmp(i); |
|
| 194 |
pid->enablePid(i); |
|
| 195 |
}*/ |
|
| 196 |
|
|
| 197 |
|
|
| 198 |
//set up smooth motion controller |
|
| 199 |
//step1: set up framerate |
|
| 200 |
//dev->set_register_blocking(XSC3_REGISTER_PID_RAMP, framerate, true); |
|
| 201 |
|
|
| 202 |
//step2: set controllertype: |
|
| 203 |
//printf("> activating smooth motion control for joint id 0x%02X (%s)\n", motor_id, joint_name.c_str());
|
|
| 204 |
//dev->set_register_blocking(XSC3_REGISTER_PID_CONTROLLER, XSC3_PROTOCOL_PID_CONTROLLERTYPE_SMOOTH_PLAYBACK, true); |
|
| 205 |
|
|
| 206 |
//step3: set pid controller: |
|
| 207 |
/*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)){
|
|
| 208 |
printf("> fixing PID i controller value for smooth motion (FIXME: restore old value!!)\n");
|
|
| 209 |
dev->set_register_blocking(XSC3_REGISTER_CONST_I, 10, true); |
|
| 210 |
}*/ |
|
| 211 |
|
|
| 212 |
//uint16_t result = dev->get_register_blocking_raw(XSC3_REGISTER_PID_CONTROLLER); |
|
| 213 |
|
|
| 214 |
//check if setting pid controllertype was successfull: |
|
| 215 |
/*if (result != XSC3_PROTOCOL_PID_CONTROLLERTYPE_SMOOTH_PLAYBACK){
|
|
| 216 |
printf("> failed to set smooth motion controller for joint %s (res=0x%04X)\n",joint_name.c_str(),result);
|
|
| 217 |
exit(1); |
|
| 218 |
}*/ |
|
| 219 |
|
|
| 220 |
//fetch min/max: |
|
| 221 |
// init_joint(e); |
|
| 222 |
|
|
| 223 |
//ok fine, now enable motor: |
|
| 224 |
//printf("> enabling motor %s\n", joint_name.c_str());
|
|
| 225 |
//dev->set_register_blocking(XSC3_REGISTER_STATUS, XSC3_PROTOCOL_STATUS_BITMASK_MOTOR_ENABLE, true); |
|
| 226 |
#endif |
|
| 227 |
} |
|
| 228 |
|
|
| 229 |
//! shutdown and disable a joint |
|
| 230 |
//! \param the enum id of a joint |
|
| 231 |
void MekaJointInterface::disable_joint(int e){
|
|
| 232 |
/* |
|
| 233 |
//first: convert humotion enum to our enum: |
|
| 234 |
int motor_id = convert_enum_to_motorid(e); |
|
| 235 |
if (motor_id == -1){
|
|
| 236 |
return; //we are not interested in that data, so we just return here |
|
| 237 |
} |
|
| 238 |
|
|
| 239 |
//fetch device: |
|
| 240 |
Device *dev = get_device(motor_id); |
|
| 241 |
printf("> FIXME: ADD DISABLE CODE\n");
|
|
| 242 |
printf("> FIXME: ADD DISABLE CODE\n");
|
|
| 243 |
printf("> FIXME: ADD DISABLE CODE\n");
|
|
| 244 |
printf("> FIXME: ADD DISABLE CODE\n");
|
|
| 245 |
printf("> FIXME: ADD DISABLE CODE\n");
|
|
| 246 |
printf("> FIXME: ADD DISABLE CODE\n");
|
|
| 247 |
printf("> FIXME: ADD DISABLE CODE\n");
|
|
| 248 |
printf("> FIXME: ADD DISABLE CODE\n");
|
|
| 249 |
printf("> FIXME: ADD DISABLE CODE\n");
|
|
| 250 |
*/ |
|
| 251 |
} |
|
| 252 |
|
|
| 253 |
#if 0 |
|
| 107 | 254 |
|
| 108 | 255 |
//! conversion table for humotion motor ids to our ids: |
| 109 | 256 |
//! \param enum from JointInterface::JOINT_ID_ENUM |
| ... | ... | |
| 704 | 851 |
printf("> FIXME: ADD DISABLE CODE\n");
|
| 705 | 852 |
*/ |
| 706 | 853 |
} |
| 854 |
#endif |
|
| src/server/neck_motion_generator.cpp | ||
|---|---|---|
| 199 | 199 |
max_accel = pow(max_speed, 2) / distance_abs; |
| 200 | 200 |
} |
| 201 | 201 |
|
| 202 |
//smoother motion |
|
| 203 |
max_accel = max_accel * 0.7; //1.0; //0.7; |
|
| 204 |
|
|
| 202 | 205 |
//limit maximum acceleration to reduce noise FIXME! |
| 203 | 206 |
if (max_accel>1000){
|
| 204 | 207 |
max_accel = 1000; |
Also available in: Unified diff