Last active
December 19, 2016 16:20
-
-
Save RyodoTanaka/4e6f08a2d4bb27dc99293149bd3fb5d6 to your computer and use it in GitHub Desktop.
Gazebo + ROS で自分だけのロボットをつくる 6. ros_controlについて ref: http://qiita.com/RyodoTanaka/items/e7feb74d0e29a8598f48
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fourth_robot: | |
joint_state_controller: | |
type: joint_state_controller/JointStateController | |
publish_rate: 50 | |
diff_drive_controller: | |
type : "diff_drive_controller/DiffDriveController" | |
left_wheel : 'left_wheel_joint' | |
right_wheel : 'right_wheel_joint' | |
publish_rate: 50.0 # default: 50 | |
pose_covariance_diagonal : [0.001, 0.001, 1000000.0, 1000000.0, 1000000.0, 1000.0] | |
twist_covariance_diagonal: [0.001, 0.001, 1000000.0, 1000000.0, 1000000.0, 1000.0] | |
# Wheel separation and diameter. These are both optional. | |
# diff_drive_controller will attempt to read either one or both from the | |
# URDF if not specified as a parameter | |
wheel_separation : 0.43515 | |
wheel_radius : 0.193125 #0.38625 | |
# Wheel separation and radius multipliers | |
wheel_separation_multiplier: 1.0 # default: 1.0 | |
wheel_radius_multiplier : 1.0 # default: 1.0 | |
# Velocity commands timeout [s], default 0.5 | |
cmd_vel_timeout: 1.0 | |
# Base frame_id | |
base_frame_id: base_footprint #default: base_link | |
# Velocity and acceleration limits | |
# Whenever a min_* is unspecified, default to -max_* | |
linear: | |
x: | |
has_velocity_limits : true | |
max_velocity : 0.825 # m/s | |
min_velocity : -0.825 # m/s | |
has_acceleration_limits: true | |
max_acceleration : 1.0 # m/s^2 | |
min_acceleration : -1.0 # m/s^2 | |
angular: | |
z: | |
has_velocity_limits : true | |
max_velocity : 3.14 # rad/s | |
min_velocity : -3.14 | |
has_acceleration_limits: true | |
max_acceleration : 1.0 # rad/s^2 | |
min_acceleration : -1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// COMPUTE AND PUBLISH ODOMETRY | |
if (open_loop_) | |
{ | |
odometry_.updateOpenLoop(last0_cmd_.lin, last0_cmd_.ang, time); | |
} | |
else | |
{ | |
double left_pos = 0.0; | |
double right_pos = 0.0; | |
for (size_t i = 0; i < wheel_joints_size_; ++i) | |
{ | |
const double lp = left_wheel_joints_[i].getPosition(); | |
const double rp = right_wheel_joints_[i].getPosition(); | |
if (std::isnan(lp) || std::isnan(rp)) | |
return; | |
left_pos += lp; | |
right_pos += rp; | |
} | |
left_pos /= wheel_joints_size_; | |
right_pos /= wheel_joints_size_; | |
// Estimate linear and angular velocity using joint information | |
odometry_.update(left_pos, right_pos, time); | |
} | |
// Publish odometry message | |
if (last_state_publish_time_ + publish_period_ < time) | |
{ | |
last_state_publish_time_ += publish_period_; | |
// Compute and store orientation info | |
const geometry_msgs::Quaternion orientation( | |
tf::createQuaternionMsgFromYaw(odometry_.getHeading())); | |
// Populate odom message and publish | |
if (odom_pub_->trylock()) | |
{ | |
odom_pub_->msg_.header.stamp = time; | |
odom_pub_->msg_.pose.pose.position.x = odometry_.getX(); | |
odom_pub_->msg_.pose.pose.position.y = odometry_.getY(); | |
odom_pub_->msg_.pose.pose.orientation = orientation; | |
odom_pub_->msg_.twist.twist.linear.x = odometry_.getLinear(); | |
odom_pub_->msg_.twist.twist.angular.z = odometry_.getAngular(); | |
odom_pub_->unlockAndPublish(); | |
} | |
// Publish tf /odom frame | |
if (enable_odom_tf_ && tf_odom_pub_->trylock()) | |
{ | |
geometry_msgs::TransformStamped& odom_frame = tf_odom_pub_->msg_.transforms[0]; | |
odom_frame.header.stamp = time; | |
odom_frame.transform.translation.x = odometry_.getX(); | |
odom_frame.transform.translation.y = odometry_.getY(); | |
odom_frame.transform.rotation = orientation; | |
tf_odom_pub_->unlockAndPublish(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MOVE ROBOT | |
// Retreive current velocity command and time step: | |
Commands curr_cmd = *(command_.readFromRT()); | |
const double dt = (time - curr_cmd.stamp).toSec(); | |
// Brake if cmd_vel has timeout: | |
if (dt > cmd_vel_timeout_) | |
{ | |
curr_cmd.lin = 0.0; | |
curr_cmd.ang = 0.0; | |
} | |
// Limit velocities and accelerations: | |
const double cmd_dt(period.toSec()); | |
limiter_lin_.limit(curr_cmd.lin, last0_cmd_.lin, last1_cmd_.lin, cmd_dt); | |
limiter_ang_.limit(curr_cmd.ang, last0_cmd_.ang, last1_cmd_.ang, cmd_dt); | |
last1_cmd_ = last0_cmd_; | |
last0_cmd_ = curr_cmd; | |
// Apply multipliers: | |
const double ws = wheel_separation_multiplier_ * wheel_separation_; | |
const double wr = wheel_radius_multiplier_ * wheel_radius_; | |
// Compute wheels velocities: | |
const double vel_left = (curr_cmd.lin - curr_cmd.ang * ws / 2.0)/wr; | |
const double vel_right = (curr_cmd.lin + curr_cmd.ang * ws / 2.0)/wr; | |
// Set wheels velocities: | |
for (size_t i = 0; i < wheel_joints_size_; ++i) | |
{ | |
left_wheel_joints_[i].setCommand(vel_left); | |
right_wheel_joints_[i].setCommand(vel_right); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<robot xmlns:xacro="http://ros.org/wiki/xacro"> | |
<xacro:macro name="wheel_trans_v0" params="prefix"> | |
<transmission name="${prefix}_wheel_trans"> | |
<type>transmission_interface/SimpleTransmission</type> | |
<joint name="${prefix}_wheel_joint"> | |
<hardwareInterface>VelocityJointInterface</hardwareInterface> | |
</joint> | |
<actuator name="${prefix}_wheel_motor"> | |
<hardwareInterface>VelocityJointInterface</hardwareInterface> | |
<mechanicalReduction>30</mechanicalReduction> | |
</actuator> | |
</transmission> | |
</xacro:macro> | |
</robot> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment