|
@@ -1,7 +1,7 @@
|
|
|
/*
|
|
|
* @Author: adam_zhuo
|
|
|
* @Date: 2020-12-30 10:32:32
|
|
|
- * @LastEditTime: 2021-01-06 18:12:39
|
|
|
+ * @LastEditTime: 2021-01-07 18:06:03
|
|
|
* @LastEditors: Please set LastEditors
|
|
|
* @Description: grip cube
|
|
|
* @FilePath: /blackTornadoRobot/src/robot_cube/src/robot_cube_node.cpp
|
|
@@ -131,12 +131,24 @@ void yaw_update(const float dynamic_turn_angle)
|
|
|
void robot_turn(const float dynamic_turn_angle){
|
|
|
tf::TransformListener tf_listener;
|
|
|
tf::StampedTransform tf_transform;
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ tf_listener.waitForTransform(odom_frame, base_frame, ros::Time(0), ros::Duration(5.0));
|
|
|
+ }
|
|
|
+ catch(tf::TransformException &ex)
|
|
|
+ {
|
|
|
+ ROS_ERROR("tf_Listener.waitForTransform timeout error !");
|
|
|
+ ROS_ERROR("%s", ex.what());
|
|
|
+ ros::shutdown();
|
|
|
+ }
|
|
|
+
|
|
|
tf_listener.lookupTransform(odom_frame, base_frame, ros::Time(0), tf_transform);
|
|
|
float last_angle = fabs(tf::getYaw(tf_transform.getRotation()));
|
|
|
float turn_angle = 0.0;
|
|
|
while((fabs(turn_angle) < dynamic_turn_angle)&&(ros::ok()))
|
|
|
{
|
|
|
- pub_twist_cmd(0, 0, -angular_speed); //原地转弯,不需要linear_x,y的控制
|
|
|
+ pub_twist_cmd(0, 0, angular_speed); //原地转弯,不需要linear_x,y的控制
|
|
|
ros::Duration(0.10).sleep(); //100 ms
|
|
|
|
|
|
try
|
|
@@ -208,7 +220,7 @@ void robot_move(int move_flag,const float check_dist)
|
|
|
}
|
|
|
|
|
|
void find_cube(){
|
|
|
- ros::Rate rate(10);
|
|
|
+ ros::Rate rate(100);
|
|
|
bool status = ros::ok();
|
|
|
while(status){
|
|
|
pub_twist_cmd(0,0,angular_speed);
|
|
@@ -222,7 +234,7 @@ void find_cube(){
|
|
|
|
|
|
void find_cube_2_control_angular(){
|
|
|
//yaw_update(yaw);
|
|
|
- robot_turn(fabs(yaw));
|
|
|
+ robot_turn(yaw);
|
|
|
}
|
|
|
|
|
|
void control_angular_2_control_distance(){
|
|
@@ -230,7 +242,7 @@ void control_angular_2_control_distance(){
|
|
|
position_y = position_d * cos(yaw);
|
|
|
ROS_INFO("position_x is %f",position_x);
|
|
|
ROS_INFO("position_y is %f",position_y);
|
|
|
- //robot_move(HORIZON_MOVE,position_x);
|
|
|
+ //robot_move(HORIZON_MOVE,-position_x);
|
|
|
//robot_move(VERTICAL_MOVE,position_y);
|
|
|
}
|
|
|
|
|
@@ -246,11 +258,13 @@ void rcv_marker_callback(const visualization_msgs::Marker & marker){
|
|
|
return;
|
|
|
}
|
|
|
position_x = marker.pose.position.x;
|
|
|
- if(abs(position_x) < position_x_threshold){
|
|
|
+ ROS_INFO("position_x is %f",position_x);
|
|
|
+ if(fabs(fabs(position_x)-0.0695) < position_x_threshold){
|
|
|
+ ROS_INFO("cha is %f",fabs(position_x)-0.0695);
|
|
|
position_d = abs(marker.pose.position.y);
|
|
|
tf::quaternionMsgToTF(marker.pose.orientation, quat);
|
|
|
tf::Matrix3x3(quat).getRPY(roll, pitch, yaw);
|
|
|
- yaw = abs(yaw) - 0.262;
|
|
|
+ yaw = abs(yaw);
|
|
|
ROS_INFO("yaw is %f",yaw);
|
|
|
find_cube_flag = true;
|
|
|
}
|
|
@@ -286,15 +300,15 @@ int main(int argc, char** argv){
|
|
|
|
|
|
cmd_pub = nh.advertise<geometry_msgs::Twist>(cmd_topic, 1);
|
|
|
marker_sub = nh.subscribe(marker_topic, 1, rcv_marker_callback);
|
|
|
- yaw_srv_client = nh.serviceClient<rasp_imu_hat_6dof::GetYawData>(yaw_service);
|
|
|
- gripper_srv_client = nh.serviceClient<ros_arduino_msgs::GripperAngle>(gripper_service);
|
|
|
+ //yaw_srv_client = nh.serviceClient<rasp_imu_hat_6dof::GetYawData>(yaw_service);
|
|
|
+ //gripper_srv_client = nh.serviceClient<ros_arduino_msgs::GripperAngle>(gripper_service);
|
|
|
|
|
|
thread spin_thread(run_spin_thread);
|
|
|
spin_thread.detach();
|
|
|
|
|
|
find_cube();
|
|
|
find_cube_2_control_angular();
|
|
|
- //control_angular_2_control_distance();
|
|
|
+ control_angular_2_control_distance();
|
|
|
//grip_cube();
|
|
|
|
|
|
return 0;
|