Skip to content

Commit

Permalink
add feet link and ik test
Browse files Browse the repository at this point in the history
  • Loading branch information
zlingkang committed Jul 4, 2018
1 parent 9f3a9b9 commit de84687
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 6 deletions.
18 changes: 14 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8.3)
project(quadruped_9g)

## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)
add_compile_options(-std=c++11)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
Expand All @@ -17,7 +17,14 @@ find_package(catkin REQUIRED COMPONENTS
rospy
rviz
xacro
kdl_parser
tf
sensor_msgs
std_msgs
trac_ik_lib
)
find_package(Boost REQUIRED COMPONENTS date_time)
find_package(orocos_kdl REQUIRED)

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
Expand Down Expand Up @@ -111,8 +118,8 @@ find_package(catkin REQUIRED COMPONENTS
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES quadruped_9g
# CATKIN_DEPENDS controller_manager gazebo_ros gazebo_ros_control joint_state_publisher robot_state_publisher roscpp rospy rviz xacro
# DEPENDS system_lib
CATKIN_DEPENDS controller_manager gazebo_ros gazebo_ros_control joint_state_publisher robot_state_publisher roscpp rospy rviz xacro trac_ik_lib
DEPENDS Boost orocos_kdl
)

###########
Expand All @@ -122,8 +129,9 @@ catkin_package(
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
# include
include
${catkin_INCLUDE_DIRS}
${orocos_kdl_INCLUDE_DIRS}
)

## Declare a C++ library
Expand All @@ -140,6 +148,8 @@ include_directories(
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
# add_executable(${PROJECT_NAME}_node src/quadruped_9g_node.cpp)
add_executable(ik_test_node src/ik_test_node.cpp)
target_link_libraries(ik_test_node ${catkin_LIBRARIES} ${orocos_kdl_LIBRARIES})

## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
Expand Down
15 changes: 15 additions & 0 deletions launch/ik_test.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<launch>

<arg name="model" default="$(find quadruped_9g)/urdf/qleg.urdf.xacro"/>
<arg name="gui" default="true" />
<arg name="rvizconfig" default="$(find quadruped_9g)/rviz/urdf.rviz" />

<param name="robot_description" command="$(find xacro)/xacro --inorder $(arg model)" />
<param name="use_gui" value="$(arg gui)"/>

<node name="ik_test_node" pkg="quadruped_9g" type="ik_test_node" output="screen"/>
<node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />

<node name="rviz" pkg="rviz" type="rviz" args="-d $(arg rvizconfig)" required="true" />

</launch>
10 changes: 9 additions & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
<build_depend>rospy</build_depend>
<build_depend>rviz</build_depend>
<build_depend>xacro</build_depend>
<build_depend>kdl_parser</build_depend>
<build_depend>urdf</build_depend>
<build_export_depend>controller_manager</build_export_depend>
<build_export_depend>gazebo_ros</build_export_depend>
<build_export_depend>gazebo_ros_control</build_export_depend>
Expand All @@ -76,7 +78,13 @@
<exec_depend>rospy</exec_depend>
<exec_depend>rviz</exec_depend>
<exec_depend>xacro</exec_depend>

<exec_depend>kdl_parser</exec_depend>
<exec_depend>urdf</exec_depend>
<depend>sensor_msgs</depend>
<depend>std_msgs</depend>
<depend>orocos_kdl</depend>
<depend>trac_ik_lib</depend>
<depend>boost</depend>

<!-- The export tag contains other, unspecified, tags -->
<export>
Expand Down
123 changes: 123 additions & 0 deletions src/ik_test_node.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#include <iostream>
#include <string>
#include <vector>

#include "ros/ros.h"
#include "sensor_msgs/JointState.h"
#include "tf/transform_broadcaster.h"
#include "kdl_parser/kdl_parser.hpp"
#include "kdl/chainiksolverpos_nr_jl.hpp"
#include "trac_ik/trac_ik.hpp"
#include "urdf/model.h"

int main(int argc, char** argv)
{
ros::init(argc, argv, "ik_test_node");
ros::NodeHandle n;
ros::Publisher joint_pub = n.advertise<sensor_msgs::JointState>("joint_states", 1);
tf::TransformBroadcaster broadcaster;
ros::Rate loop_rate(1);

std::string robot_desc_string;
n.param("robot_description", robot_desc_string, std::string());

KDL::Tree my_tree;
if(!kdl_parser::treeFromString(robot_desc_string, my_tree))
{
ROS_ERROR("Failed to construct kdl tree");
}

std::vector<std::string> joint_name = {"shoulder_joint_lf", "elbow_joint_lf", "wrist_joint_lf",
"shoulder_joint_rf", "elbow_joint_rf", "wrist_joint_rf",
"shoulder_joint_lb", "elbow_joint_lb", "wrist_joint_lb",
"shoulder_joint_rb", "elbow_joint_rb", "wrist_joint_rb" };
std::vector<double> joint_pos = {0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0, 0, 0, 0};
// for joints pos pub
sensor_msgs::JointState joint_state;
// for odom pub
geometry_msgs::TransformStamped odom_trans;
odom_trans.header.frame_id = "odom";
odom_trans.child_frame_id = "base_link";

// ik stuff initialization
std::string urdf_param = "/robot_description";
double timeout = 0.005;
double eps = 1e-5;
std::string chain_start = "shoulder_link_lf";
std::string chain_end = "feet_link_lf";
TRAC_IK::TRAC_IK tracik_solver(chain_start, chain_end, urdf_param, timeout, eps);
KDL::Chain chain;
KDL::JntArray ll, ul; //joint lower limits, joint upper limits
bool valid = tracik_solver.getKDLChain(chain);
if(!valid)
{
ROS_ERROR("There was no valid KDL chain found");
}
valid = tracik_solver.getKDLLimits(ll, ul);
if(!valid)
{
ROS_ERROR("There was no valid KDL joint limits found");
}
KDL::ChainFkSolverPos_recursive fk_solver(chain);
ROS_INFO("joints number: %d", chain.getNrOfJoints());
KDL::JntArray nominal(chain.getNrOfJoints()); // starting joints config
for(size_t j = 0; j < nominal.data.size(); j ++)
{
nominal(j) = (ll(j) + ul(j))/2.0;
}
KDL::JntArray q(chain.getNrOfJoints()); // target joints config
q(0) = 0.4;
q(1) = -0.8;
KDL::Frame end_effector_pose;
KDL::JntArray result;

bool flag = true;
double x_trans = 0;
while(ros::ok())
{
// ik computation
if(flag)
{
fk_solver.JntToCart(q, end_effector_pose);
int rc = tracik_solver.CartToJnt(nominal, end_effector_pose, result);
}
else
{
fk_solver.JntToCart(nominal, end_effector_pose);
int rc = tracik_solver.CartToJnt(q, end_effector_pose, result);
}
flag = !flag;

// update joint_state
ROS_INFO("update joint state");
joint_state.header.stamp = ros::Time::now();
joint_state.name.resize(12);
joint_state.position.resize(12);
for(size_t i = 0; i < 12; i ++)
{
joint_state.name[i] = joint_name[i];
joint_state.position[i] = joint_pos[i];
}
joint_state.position[1] = result(0);
joint_state.position[2] = result(1);

// update odom transform
ROS_INFO("update odom trans");
odom_trans.header.stamp = ros::Time::now();
odom_trans.transform.translation.x = x_trans;
odom_trans.transform.translation.y = 0;
odom_trans.transform.translation.z = 0.095;
odom_trans.transform.rotation = tf::createQuaternionMsgFromYaw(0.0);

ROS_INFO("pub joint state");
joint_pub.publish(joint_state);
ROS_INFO("pub odom trans");
broadcaster.sendTransform(odom_trans);

//x_trans += 0.001;

loop_rate.sleep();
}

return 0;
}
21 changes: 20 additions & 1 deletion urdf/qleg.urdf.xacro
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

<robot name="quadruped_9g" xmlns:xacro="http://ros.org/wiki/xacro">
<xacro:property name="shoul_len" value="0.035" />
<xacro:property name="thigh_len" value="0.045" />
<xacro:property name="thigh_len" value="0.05" />
<xacro:property name="shank_len" value="0.05" />
<xacro:property name="link_radius" value="0.0025"/>
<xacro:property name="feet_radius" value="0.0025"/>
<xacro:property name="pi" value="3.1415" />
<xacro:property name="body_len" value="0.1" />
<xacro:property name="body_width" value="0.05" />
Expand Down Expand Up @@ -90,6 +91,24 @@
<child link="shank_link_${suffix}"/>
<origin xyz="0 0 ${-thigh_len}"/>
</joint>

<link name="feet_link_${suffix}">
<visual>
<geometry>
<sphere radius="${feet_radius}"/>
</geometry>
<origin rpy="0 0 0" xyz="0 0 0"/>
<material name="white"/>
</visual>
<xacro:default_inertial mass="0.2"/>
</link>
<joint name="ankle_joint_${suffix}" type="fixed">
<axis xyz="0 1 0"/>
<parent link="shank_link_${suffix}"/>
<child link="feet_link_${suffix}"/>
<origin xyz="0 0 ${-shank_len}"/>
</joint>

</xacro:macro>
<xacro:leg suffix="lf" front="1" left="1" />
<xacro:leg suffix="rf" front="1" left="-1" />
Expand Down

0 comments on commit de84687

Please sign in to comment.