9 vx_(0), vy_(0), vth_(0), x_(0), y_(0), th_(0)
13 nh_.
getParam(
"noid_mover_controller/wheel_radius", wheel_radius);
15 nh_.
getParam(
"noid_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;
60 ROS_DEBUG(
"cmd_vel: %f %f %f", _cmd_vel->linear.x, _cmd_vel->linear.y, _cmd_vel->angular.z);
63 if (_cmd_vel->linear.x == 0.0 && _cmd_vel->linear.y == 0.0 && _cmd_vel->angular.z == 0.0) {
75 double acc_x = (_cmd_vel->linear.x -
vx_) / dt;
76 double acc_y = (_cmd_vel->linear.y -
vy_) / dt;
77 double acc_z = (_cmd_vel->angular.z -
vth_) / dt;
79 ROS_DEBUG(
"vel_acc: %f %f %f", acc_x, acc_y, acc_z);
113 ROS_WARN(
"cmd_vel comes before sending pervious message");
128 wheel_velocity[i] = 0;
143 double dt, delta_x, delta_y, delta_th;
147 delta_th =
vth_ * dt;
154 geometry_msgs::Quaternion odom_quat
158 geometry_msgs::TransformStamped odom_trans;
160 odom_trans.header.frame_id =
"odom";
161 odom_trans.child_frame_id =
"base_link";
163 odom_trans.transform.translation.x =
x_;
164 odom_trans.transform.translation.y =
y_;
165 odom_trans.transform.translation.z = 0.0;
166 odom_trans.transform.rotation = odom_quat;
172 nav_msgs::Odometry odom;
174 odom.header.frame_id =
"odom";
177 odom.pose.pose.position.x =
x_;
178 odom.pose.pose.position.y =
y_;
179 odom.pose.pose.position.z = 0.0;
180 odom.pose.pose.orientation = odom_quat;
183 odom.child_frame_id =
"base_link";
184 odom.twist.twist.linear.x =
vx_;
185 odom.twist.twist.linear.y =
vy_;
186 odom.twist.twist.angular.z =
vth_;
196 float dx, dy, dtheta, theta;
197 float v1, v2, v3, v4;
198 int16_t front_right_wheel, rear_right_wheel, front_left_wheel, rear_left_wheel;
201 float cos_theta =
cos(theta);
202 float sin_theta =
sin(theta);
205 dy = (_linear_x * cos_theta - _linear_y * sin_theta);
206 dx = (_linear_x * sin_theta + _linear_y * cos_theta);
210 v1 =
k1_ * dtheta +
k2_ * ((-cos_theta + sin_theta) * dx + (-cos_theta - sin_theta) * dy);
211 v2 =
k1_ * dtheta +
k2_ * ((-cos_theta - sin_theta) * dx + ( cos_theta - sin_theta) * dy);
212 v3 =
k1_ * dtheta +
k2_ * (( cos_theta - sin_theta) * dx + ( cos_theta + sin_theta) * dy);
213 v4 =
k1_ * dtheta +
k2_ * (( cos_theta + sin_theta) * dx + (-cos_theta + sin_theta) * dy);
216 front_right_wheel =
static_cast<int16_t
>(v1 * (180 / M_PI));
217 rear_right_wheel =
static_cast<int16_t
>(v4 * (180 / M_PI));
218 front_left_wheel =
static_cast<int16_t
>(v2 * (180 / M_PI));
219 rear_left_wheel =
static_cast<int16_t
>(v3 * (180 / M_PI));
221 _wheel_vel[0] = front_left_wheel;
222 _wheel_vel[1] = front_right_wheel;
223 _wheel_vel[2] = rear_left_wheel;
224 _wheel_vel[3] = rear_right_wheel;
void velocityToWheel(double _linear_x, double _linear_y, double _angular_z, std::vector< int16_t > &_wheel_vel)
void publish(const boost::shared_ptr< M > &message) const
void calculateOdometry(const ros::TimerEvent &_event)
odometry publisher
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void cmdVelCallback(const geometry_msgs::TwistConstPtr &_cmd_vel)
control with cmd_vel
tf::TransformBroadcaster odom_broadcaster_
NoidMoverController(const ros::NodeHandle &_nh, noid_robot_hardware::NoidRobotHW *_in_hw)
void safetyCheckCallback(const ros::TimerEvent &_event)
safety stopper when msg is not reached for more than safety_duration_ [s]
void writeWheel(const std::vector< std::string > &_names, const std::vector< int16_t > &_vel, double _tm_sec)
~NoidMoverController()
destructor
void onWheelServo(bool _value)
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
static geometry_msgs::Quaternion createQuaternionMsgFromYaw(double yaw)
bool getParam(const std::string &key, std::string &s) const
INLINE Rall1d< T, V, S > atan2(const Rall1d< T, V, S > &y, const Rall1d< T, V, S > &x)
std::vector< int > aero_index_
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
noid_robot_hardware::NoidRobotHW * hw_
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
ros::Subscriber cmd_vel_sub_