64 for (i = 0; i < 23; i++)
88 boost::mutex::scoped_lock lock(
mMutex);
92 static unsigned char last_str[2] = { 0x00, 0x00 };
93 static unsigned char new_packed_ctr =
DISABLE;
94 static int new_packed_ok_len = 0;
95 static int new_packed_len = 0;
96 static unsigned char cmd_string_buf[512];
97 unsigned char current_str = 0x00;
98 const int cmd_string_max_size = 512;
109 for (i = 0; i < len; i++)
111 current_str = data[i];
115 if (last_str[0] == 205 && last_str[1] == 235 && current_str == 215)
119 new_packed_ok_len = 0;
120 new_packed_len = new_packed_ok_len;
121 last_str[0] = last_str[1];
122 last_str[1] = current_str;
125 last_str[0] = last_str[1];
126 last_str[1] = current_str;
127 if (new_packed_ctr ==
ENABLE)
130 new_packed_ok_len = current_str;
131 if (new_packed_ok_len > cmd_string_max_size)
132 new_packed_ok_len = cmd_string_max_size;
139 if (new_packed_ok_len <= new_packed_len)
149 cmd_string_buf[new_packed_len - 1] = current_str;
150 if (new_packed_ok_len == new_packed_len && new_packed_ok_len > 0)
154 if (new_packed_ok_len == 115)
156 for (j = 0; j < 23; j++)
158 memcpy(&receive_byte[j], &cmd_string_buf[5 * j], 4);
162 else if (new_packed_ok_len == 95)
164 for (j = 0; j < 19; j++)
166 memcpy(&receive_byte[j], &cmd_string_buf[5 * j], 4);
172 for (j = 0; j < 7; j++)
174 if (cmd_string_buf[5 * j + 4] != 32)
214 new_packed_ok_len = 0;
232 boost::mutex::scoped_lock lock(
mMutex);
233 static double theta_last = 0.0;
234 static unsigned int ii = 0;
235 static bool theta_updateflag =
false;
245 theta_updateflag =
false;
249 theta_updateflag =
true;
252 double delta_car, delta_x, delta_y, delta_theta, var_len, var_angle;
256 var_angle = (0.01f / 180.0f *
PI) * (0.01
f / 180.0
f *
PI);
259 2.0f * PI * wheel_radius;
260 if (delta_car > 0.05 || delta_car < -0.05)
273 delta_x = delta_car * cos(
CarPos2D.theta * PI / 180.0f);
274 delta_y = delta_car * sin(
CarPos2D.theta * PI / 180.0f);
278 if (delta_theta > 270)
280 if (delta_theta < -270)
283 if ((!theta_updateflag) || delta_theta > 20 || delta_theta < -20)
299 std_msgs::Int32 flag;
310 int barArea_nums = 0;
311 int clearArea_nums = 0;
337 if (barArea_nums > 0)
340 PointCloud::Ptr barcloud_msg(
new PointCloud);
341 barcloud_msg->header.stamp = current_time;
342 barcloud_msg->height = 1;
343 barcloud_msg->width = barArea_nums;
344 barcloud_msg->is_dense =
true;
345 barcloud_msg->is_bigendian =
false;
346 barcloud_msg->header.frame_id =
"kinect_link_new";
354 for (
int k = 0; k < 3; k++, ++bariter_x, ++bariter_y, ++bariter_z)
357 *bariter_y = -0.10 - k * 0.05;
363 for (
int k = 0; k < 3; k++, ++bariter_x, ++bariter_y, ++bariter_z)
366 *bariter_y = -0.1 + k * 0.05;
372 for (
int k = 0; k < 3; k++, ++bariter_x, ++bariter_y, ++bariter_z)
375 *bariter_y = 0.05 + k * 0.05;
384 if (clearArea_nums > 0)
387 PointCloud::Ptr clearcloud_msg(
new PointCloud);
388 clearcloud_msg->header.stamp = current_time;
389 clearcloud_msg->height = 1;
390 clearcloud_msg->width = clearArea_nums;
391 clearcloud_msg->is_dense =
true;
392 clearcloud_msg->is_bigendian =
false;
393 clearcloud_msg->header.frame_id =
"kinect_link_new";
401 for (
int k = 0; k < 3; k++, ++cleariter_x, ++cleariter_y, ++cleariter_z)
404 *cleariter_y = -0.1 - k * 0.05;
407 for (
int k = 0; k < 3; k++, ++cleariter_x, ++cleariter_y, ++cleariter_z)
410 *cleariter_y = -0.1 - k * 0.05;
416 for (
int k = 0; k < 3; k++, ++cleariter_x, ++cleariter_y, ++cleariter_z)
419 *cleariter_y = -0.1 + k * 0.05;
422 for (
int k = 0; k < 3; k++, ++cleariter_x, ++cleariter_y, ++cleariter_z)
425 *cleariter_y = -0.1 + k * 0.05;
431 for (
int k = 0; k < 3; k++, ++cleariter_x, ++cleariter_y, ++cleariter_z)
434 *cleariter_y = 0.05 + k * 0.05;
437 for (
int k = 0; k < 3; k++, ++cleariter_x, ++cleariter_y, ++cleariter_z)
440 *cleariter_y = 0.05 + k * 0.05;
452 CarTwist.linear.x = delta_car * 50.0f;
454 CarTwist.angular.z = angle_speed * PI / 180.0f;
460 CarOdom.header.stamp = current_time;
461 CarOdom.header.frame_id =
"odom";
464 CarOdom.pose.pose.position.z = 0.0f;
466 CarOdom.pose.pose.orientation = odom_quat;
467 CarOdom.pose.covariance = boost::assign::list_of(var_len)(0)(0)(0)(0)(0)(0)(var_len)(0)(0)(0)(0)(0)(0)(999)(0)(0)(
468 0)(0)(0)(0)(999)(0)(0)(0)(0)(0)(0)(999)(0)(0)(0)(0)(0)(0)(var_angle);
469 CarOdom.child_frame_id =
"base_footprint";
473 CarOdom.twist.covariance = boost::assign::list_of(var_len)(0)(0)(0)(0)(0)(0)(var_len)(0)(0)(0)(0)(0)(0)(999)(0)(0)(
474 0)(0)(0)(0)(999)(0)(0)(0)(0)(0)(0)(999)(0)(0)(0)(0)(0)(0)(var_angle);
ros::Publisher pub_clearpoint_cloud_
double get_wheel_radius()
nav_msgs::Odometry CarOdom
void publish(const boost::shared_ptr< M > &message) const
sensor_msgs::PointCloud2 PointCloud
ros::Publisher mStatusFlagPub
ros::Publisher mPose2DPub
std_msgs::Float64 get_power()
nav_msgs::Odometry get_odom()
void setRPY(const tfScalar &roll, const tfScalar &pitch, const tfScalar &yaw)
geometry_msgs::Pose2D get_CarPos2D()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
static geometry_msgs::Quaternion createQuaternionMsgFromYaw(double yaw)
double get_wheel_separation()
ros::Publisher pub_barpoint_cloud_
geometry_msgs::Pose2D CarPos2D
geometry_msgs::Twist get_CarTwist()
void get_wheel_speed(double speed[2])
ROSCPP_DECL void spinOnce()
void setPointCloud2FieldsByString(int n_fields,...)
geometry_msgs::Twist CarTwist
void Update(const char *data, unsigned int len)
std_msgs::Float64 CarPower