8 this->
name = node_name;
35 this->
publisher[
"joint_states"] = nh.
advertise<sensor_msgs::JointState>(
"joint_states",100);
38 this->
publisher[
"version_info"] = nh.
advertise<kobuki_msgs::VersionInfo>(
"version_info",100,
true);
41 this->publisher[
"odom"] = nh.
advertise<nav_msgs::Odometry>(
"odom",100);
65 std::string
cmd =
"commands/";
78 this->
kobuki.wheel_speed_cmd[
LEFT] = msg->linear.x - msg->angular.z * this->
kobuki.wheel_separation / 2;
79 this->
kobuki.wheel_speed_cmd[
RIGHT] = msg->linear.x + msg->angular.z * this->
kobuki.wheel_separation / 2;
84 if((msg->state == kobuki_msgs::MotorPower::ON) && (!this->kobuki.motor_enabled))
86 this->
kobuki.motor_enabled =
true;
89 else if((msg->state == kobuki_msgs::MotorPower::OFF) && (this->kobuki.motor_enabled))
91 this->
kobuki.motor_enabled =
false;
99 v = this->
kobuki.wheel_speed_cmd[index];
100 w = v / (this->
kobuki.wheel_diameter / 2);
101 this->
kobuki.joint_states.velocity[index] = w;
102 this->
kobuki.joint_states.position[index]= this->
kobuki.joint_states.position[index] + w * step_time.
toSec();
112 d1 = step_time.
toSec() * (this->
kobuki.wheel_diameter / 2) * w_left;
113 d2 = step_time.
toSec() * (this->
kobuki.wheel_diameter / 2) * w_right;
125 da = (d2 - d1) / this->
kobuki.wheel_separation;
128 this->kobuki.odom_pose[0] += dr *
cos(this->
kobuki.odom_pose[2]);
130 this->
kobuki.odom_pose[2] += da;
134 this->
kobuki.odom_vel[1] = 0.0;
137 this->
kobuki.odom.pose.pose.position.x = this->
kobuki.odom_pose[0];
138 this->
kobuki.odom.pose.pose.position.y = this->
kobuki.odom_pose[1];
139 this->
kobuki.odom.pose.pose.position.z = 0;
143 this->
kobuki.odom.twist.twist.linear.x = this->
kobuki.odom_vel[0];
144 this->
kobuki.odom.twist.twist.angular.z = this->
kobuki.odom_vel[2];
149 odom_tf.header = this->
kobuki.odom.header;
150 odom_tf.child_frame_id = this->
kobuki.odom.child_frame_id;
151 odom_tf.transform.translation.x = this->
kobuki.odom.pose.pose.position.x;
152 odom_tf.transform.translation.y = this->
kobuki.odom.pose.pose.position.y;
153 odom_tf.transform.translation.z = this->
kobuki.odom.pose.pose.position.z;
154 odom_tf.transform.rotation = this->
kobuki.odom.pose.pose.orientation;
162 this->prev_update_time = time_now;
165 if(((time_now - this->
last_cmd_vel_time).toSec() > this->
kobuki.cmd_vel_timeout) || !this->kobuki.motor_enabled)
172 double w_left,w_right;
175 this->
kobuki.joint_states.header.stamp = time_now;
180 this->
kobuki.odom.header.stamp = time_now;
184 geometry_msgs::TransformStamped odom_tf;
std::map< std::string, ros::Subscriber > subscriber
void advertiseTopics(ros::NodeHandle &nh)
void updateTF(geometry_msgs::TransformStamped &odom_tf)
std::map< std::string, ros::Publisher > publisher
void updateJoint(unsigned int index, double &w, ros::Duration step_time)
void publishVersionInfoOnce()
tf::TransformBroadcaster tf_broadcaster
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void subscribeTopics(ros::NodeHandle &nh)
void subscribeMotorPowerCommand(const kobuki_msgs::MotorPowerConstPtr msg)
ros::Time prev_update_time
void updateOdometry(double w_left, double w_right, ros::Duration step_time)
bool init(ros::NodeHandle &nh)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
FakeKobukiRos(std::string &node_name)
static geometry_msgs::Quaternion createQuaternionMsgFromYaw(double yaw)
#define ROS_INFO_STREAM(args)
void subscribeVelocityCommand(const geometry_msgs::TwistConstPtr msg)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)
ros::Time last_cmd_vel_time