7 vx_(0), vy_(0), vth_(0), x_(0), y_(0), th_(0)
12 float wheel_radius,tread,wheelbase;
13 nh_.getParam(
"/seed_r7_mover_controller/wheel_radius", wheel_radius);
14 nh_.getParam(
"/seed_r7_mover_controller/tread", tread);
15 nh_.getParam(
"/seed_r7_mover_controller/wheelbase", wheelbase);
17 k1_ = - sqrt(2) * ( sqrt( pow(tread,2)+pow(wheelbase,2) )/2 ) * sin( M_PI/4 + atan2(tread/2,wheelbase/2) ) / wheel_radius;
18 k2_ = 1 / wheel_radius;
21 nh_.getParam(
"/seed_r7_mover_controller/ros_rate", ros_rate_);
22 nh_.getParam(
"/seed_r7_mover_controller/odom_rate", odom_rate_);
23 nh_.getParam(
"/seed_r7_mover_controller/safety_rate", safety_rate_);
24 nh_.getParam(
"/seed_r7_mover_controller/safety_duration", safety_duration_);
25 nh_.getParam(
"/joint_settings/wheel/aero_index", aero_index_);
27 num_of_wheels_ = aero_index_.size();
31 last_time_ = current_time_;
41 cmd_vel_sub_ = nh_.subscribe(
"cmd_vel",1, &MoverController::cmdVelCallback,
this);
42 safe_timer_ = nh_.createTimer(
ros::Duration(safety_rate_), &MoverController::safetyCheckCallback,
this);
45 odom_pub_ = nh_.advertise<nav_msgs::Odometry>(
"odom", 1);
46 odom_timer_ = nh_.createTimer(
ros::Duration(odom_rate_), &MoverController::calculateOdometry,
this);
48 initialpose_pub_ = nh_.advertise<geometry_msgs::PoseWithCovarianceStamped>(
"/initialpose", 1);
50 = nh_.advertiseService(
"led_control", &MoverController::ledControlCallback,
this);
52 set_initialpose_server_
53 = nh_.advertiseService(
"set_initialpose", &MoverController::setInitialPoseCallback,
this);
68 ROS_DEBUG(
"cmd_vel: %f %f %f", _cmd_vel->linear.x, _cmd_vel->linear.y, _cmd_vel->angular.z);
76 else if (_cmd_vel->linear.x == 0.0 && _cmd_vel->linear.y == 0.0 && _cmd_vel->angular.z == 0.0) {
80 vx_ = _cmd_vel->linear.x;
81 vy_ = _cmd_vel->linear.y;
82 vth_ = _cmd_vel->angular.z;
126 ROS_WARN(
"cmd_vel comes before sending pervious message");
141 wheel_velocity[i] = 0;
156 double dt, delta_x, delta_y, delta_th;
160 delta_th =
vth_ * dt;
167 geometry_msgs::Quaternion odom_quat
171 geometry_msgs::TransformStamped odom_trans;
173 odom_trans.header.frame_id =
"odom";
174 odom_trans.child_frame_id =
"base_link";
176 odom_trans.transform.translation.x =
x_;
177 odom_trans.transform.translation.y =
y_;
178 odom_trans.transform.translation.z = 0.0;
179 odom_trans.transform.rotation = odom_quat;
185 nav_msgs::Odometry odom;
187 odom.header.frame_id =
"odom";
190 odom.pose.pose.position.x =
x_;
191 odom.pose.pose.position.y =
y_;
192 odom.pose.pose.position.z = 0.0;
193 odom.pose.pose.orientation = odom_quat;
196 odom.child_frame_id =
"base_link";
197 odom.twist.twist.linear.x =
vx_;
198 odom.twist.twist.linear.y =
vy_;
199 odom.twist.twist.angular.z =
vth_;
208 (
double _linear_x,
double _linear_y,
double _angular_z, std::vector<int16_t>& _wheel_vel)
210 float dx, dy, dtheta, theta;
211 float v1, v2, v3, v4;
212 int16_t front_right_wheel, rear_right_wheel, front_left_wheel, rear_left_wheel;
215 float cos_theta = cos(theta);
216 float sin_theta = sin(theta);
219 dy = (_linear_x * cos_theta - _linear_y * sin_theta);
220 dx = (_linear_x * sin_theta + _linear_y * cos_theta);
224 v1 =
k1_ * dtheta +
k2_ * ((-cos_theta + sin_theta) * dx + (-cos_theta - sin_theta) * dy);
225 v2 =
k1_ * dtheta +
k2_ * ((-cos_theta - sin_theta) * dx + ( cos_theta - sin_theta) * dy);
226 v3 =
k1_ * dtheta +
k2_ * (( cos_theta - sin_theta) * dx + ( cos_theta + sin_theta) * dy);
227 v4 =
k1_ * dtheta +
k2_ * (( cos_theta + sin_theta) * dx + (-cos_theta + sin_theta) * dy);
230 front_right_wheel =
static_cast<int16_t
>(v1 * (180 / M_PI));
231 rear_right_wheel =
static_cast<int16_t
>(v4 * (180 / M_PI));
232 front_left_wheel =
static_cast<int16_t
>(v2 * (180 / M_PI));
233 rear_left_wheel =
static_cast<int16_t
>(v3 * (180 / M_PI));
235 _wheel_vel[0] = front_left_wheel;
236 _wheel_vel[1] = front_right_wheel;
237 _wheel_vel[2] = rear_left_wheel;
238 _wheel_vel[3] = rear_right_wheel;
243 (seed_r7_ros_controller::SetInitialPose::Request& _req,
244 seed_r7_ros_controller::SetInitialPose::Response& _res)
246 geometry_msgs::PoseWithCovarianceStamped initial_pose;
250 initial_pose.header.frame_id =
"map";
251 initial_pose.pose.pose.position.x = _req.x;
252 initial_pose.pose.pose.position.y = _req.y;
253 initial_pose.pose.pose.position.z = 0.0;
254 initial_pose.pose.pose.orientation = pose_quat;
257 return "SetInitialPose succeeded";
261 (seed_r7_ros_controller::LedControl::Request& _req,
262 seed_r7_ros_controller::LedControl::Response& _res)
266 _res.result =
"LED succeeded";
void turnWheel(std::vector< int16_t > &_vel)
void publish(const boost::shared_ptr< M > &message) const
void runLedScript(uint8_t _number, uint16_t _script)
tf::TransformBroadcaster odom_broadcaster_
void onWheelServo(bool _value)
void cmdVelCallback(const geometry_msgs::TwistConstPtr &_cmd_vel)
control with cmd_vel
struct robot_hardware::RobotHW::RobotStatus robot_status_
void calculateOdometry(const ros::TimerEvent &_event)
odometry publisher
bool setInitialPoseCallback(seed_r7_ros_controller::SetInitialPose::Request &_req, seed_r7_ros_controller::SetInitialPose::Response &_res)
void velocityToWheel(double _linear_x, double _linear_y, double _angular_z, std::vector< int16_t > &_wheel_vel)
robot_hardware::RobotHW * hw_
bool ledControlCallback(seed_r7_ros_controller::LedControl::Request &_req, seed_r7_ros_controller::LedControl::Response &_res)
void safetyCheckCallback(const ros::TimerEvent &_event)
safety stopper when msg is not reached for more than safety_duration_ [s]
MoverController(const ros::NodeHandle &_nh, robot_hardware::RobotHW *_in_hw)
static geometry_msgs::Quaternion createQuaternionMsgFromYaw(double yaw)
~MoverController()
destructor
ros::Publisher initialpose_pub_