stage simulator

本文介绍了一种基于ROS系统的机器人避障控制方案,利用激光雷达数据实现机器人在检测到前方0.5米内有障碍物时停止前进的功能。通过自定义的Stopper类,结合ROS节点、发布者和订阅者,实现了机器人的运动控制和激光雷达数据的实时处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

---恢复内容开始---

 运行自带地图

rosrun stage_ros stageros /opt/ros/indigo/share/stage_ros/world/willow-erratic.world 

控制机器人运动
sudo apt-get install ros-indigo-teleop-twist-keyboard
rosrun teleop_twist_keyboard teleop_twist_keyboard.py
简单的gmapping&保存map
rosrun gmapping slam_gmapping scan:=base_scan
rosrun map_server map_saver

在home目录下查看地图

利用激光雷达数据,在前方有障碍物0.5米内停止前行

#include<ros/ros.h>
#include<sensor_msgs/LaserScan.h>
#include<geometry_msgs/Twist.h>

class Stopper{
public:
    const static double FORWARD_SPEED_MPS = 0.5;
    const static double MIN_SCAN_ANGLE_RAD = -30.0/180*M_PI;
    const static double MAX_SCAN_ANGLE_RAD = +30.0/180*M_PI;
    const static float MIN_PROXOMITY_RANGE_M = 0.5;

    Stopper();
    void startMoving();
private:
    ros::NodeHandle node;
    ros::Publisher commandPub;
    ros::Subscriber laserSub;
    bool keepMoving;
    void moveForward();
    void scanCallback( const sensor_msgs::LaserScan::ConstPtr& scan);
};
Stopper::Stopper(){
    keepMoving = true;
    commandPub = node.advertise<geometry_msgs::Twist>("cmd_vel",10);
    laserSub = node.subscribe("base_scan",1, &Stopper::scanCallback,this);

}

void Stopper::moveForward(){
    geometry_msgs::Twist msg;
    msg.linear.x = FORWARD_SPEED_MPS;
    commandPub.publish(msg);
}

void Stopper::scanCallback(const sensor_msgs::LaserScan::ConstPtr& scan){
    int minIndex = ceil((MIN_SCAN_ANGLE_RAD - scan->angle_min) / scan->angle_increment);
    int maxIndex = floor((MAX_SCAN_ANGLE_RAD - scan->angle_min) / scan->angle_increment);
    float closestRange = scan->ranges[minIndex];

    for(int currIndex = minIndex + 1; currIndex <= maxIndex; currIndex++){

        if(scan->ranges[currIndex] < closestRange){
            closestRange = scan->ranges[currIndex];
        }
       ROS_INFO_STREAM("closest range: " <<closestRange);
       if(closestRange < MIN_PROXOMITY_RANGE_M){
           ROS_INFO("stop");
           keepMoving = false;
       }
    }

}

void Stopper::startMoving(){
ros::Rate rate(10);
ROS_INFO("start_moving");
while(ros::ok()&&keepMoving){
    moveForward();
    ros::spinOnce();
    rate.sleep();
    }
}

int main(int argc,char **argv){
    ros::init(argc,argv,"stopper");
    Stopper stopper;
    stopper.startMoving();
    return 0;

}

 

转载于:https://www.cnblogs.com/CZM-/p/6030692.html

TebLocalPlannerROS: odom_topic: odom # Trajectory teb_autosize: True dt_ref: 0.42 #change dt_hysteresis: 0.1 global_plan_overwrite_orientation: True allow_init_with_backwards_motion: True max_global_plan_lookahead_dist: 6.8 #change 防止膨胀区卡死机 本次修改 feasibility_check_no_poses: 3 #change exact_arc_length: False #change force_reinit_new_goal_dist: 2.0 #change # Robot max_vel_x: 2 #0.7 max_vel_x_backwards: 0.7 max_vel_y: 0.0 max_vel_theta: 0.8 # 30.0 the angular velocity is also bounded by min_turning_radius in case of a carlike robot (r = v / omega) acc_lim_x: 0.2 #change 0.33 acc_lim_theta: 0.6 #change 0.6 # ********************** Carlike robot parameters ******************** min_turning_radius: 0.7 # 最小拐弯角Min turning radius of the carlike robot (compute value using a model or adjust with rqt_reconfigure manually) wheelbase: 0.3 # Wheelbase of our robot change cmd_angle_instead_rotvel: False # stage simulator takes the angle instead of the rotvel as input (twist message) # ******************************************************************** is_footprint_dynamic: False footprint_model: # types: "point", "circular", "two_circles", "line", "polygon" type: "line" line_start: [-0.1, 0.0] # for type "line" line_end: [0.1, 0.0] # for type "line" # GoalTolerance xy_goal_tolerance: 0.2 #change yaw_goal_tolerance: 0.2 #change free_goal_vel: False # Obstacles min_obstacle_dist: 0.55 # This value must also include our robot's expansion, since footprint_model is set to "line". inflation_dist : 0.4 #change 障碍物距离的缓冲区,如果冲角落调大 include_costmap_obstacles: True include_dynamic_obstacles: True costmap_obstacles_behind_robot_dist: 0.5 #change 加速小车 0.5 dynamic_obstacle_inflation_dist: 0.15 obstacle_poses_affected: 10 #change costmap_converter_plugin: "" costmap_converter_spin_thread: True costmap_converter_rate: 5 legacy_obstacle_association: False obstacle_association_cutoff_factor: 5.0 obstacle_association_force_inclusion_factor: 1.5 # Optimization no_inner_iterations: 5 #5 no_outer_iterations: 4 #4 optimization_activate: True optimization_verbose: False penalty_epsilon: 0.08 # 0.25 本次修改 已改回 weight_max_vel_x: 1.5 #2 weight_max_vel_theta: 0.7 #1 weight_acc_lim_x: 1 weight_acc_lim_theta: 1 weight_kinematics_nh: 1000 weight_kinematics_forward_drive: 1000 weight_kinematics_turning_radius: 8.0 #change 本次修改 40 15 weight_optimaltime: 30 #冒险13 weight_obstacle: 120 #change 本次修改 已改回 原来为100 weight_dynamic_obstacle: 100 # not in use yet obstacle_cost_exponent: 4.0 weight_adapt_factor: 1.0 weight_dynamic_obstacle_inflation: 0.8 weight_inflation: 0.8 #0.8膨胀区权重 weight_shortest_path: 5.0 weight_viapoint: 100.0 # Homotopy Class Planner enable_homotopy_class_planning: False enable_multithreading: True simple_exploration: False max_number_classes: 2 selection_cost_hysteresis: 1.0 selection_obst_cost_scale: 1.0 selection_viapoint_cost_scale: 1.0 selection_alternative_time_cost: False roadmap_graph_no_samples: 15 roadmap_graph_area_width: 5 roadmap_graph_area_length_scale: 1.0 h_signature_prescaler: 0.5 h_signature_threshold: 0.1 obstacle_keypoint_offset: 0.1 obstacle_heading_threshold: 0.45 visualize_hc_graph: False # viapoint global_plan_viapoint_sep: 0.8 #1 via_points_ordered: False # Recovery oscillation_recovery: True shrink_horizon_backup: True 修改哪些
05-14
TebLocalPlannerROS: odom_topic: odom # Trajectory teb_autosize: True dt_ref: 0.3 dt_hysteresis: 0.1 max_samples: 500 global_plan_overwrite_orientation: True allow_init_with_backwards_motion: True max_global_plan_lookahead_dist: 10 global_plan_viapoint_sep: -1 global_plan_prune_distance: 1 exact_arc_length: False feasibility_check_no_poses: 2 publish_feedback: False # Robot max_vel_x: 0.4 max_vel_x_backwards: 0.2 max_vel_y: 0.0 max_vel_theta: 0.3 # the angular velocity is also bounded by min_turning_radius in case of a carlike robot (r = v / omega) acc_lim_x: 0.5 acc_lim_theta: 0.5 # ********************** Carlike robot parameters ******************** min_turning_radius: 0.5 # Min turning radius of the carlike robot (compute value using a model or adjust with rqt_reconfigure manually) wheelbase: 0.4 # Wheelbase of our robot cmd_angle_instead_rotvel: True # stage simulator takes the angle instead of the rotvel as input (twist message) # ******************************************************************** footprint_model: # types: "point", "circular", "two_circles", "line", "polygon" type: "line" radius: 0.2 # for type "circular" line_start: [0.0, 0.0] # for type "line" line_end: [0.4, 0.0] # for type "line" front_offset: 0.2 # for type "two_circles" front_radius: 0.2 # for type "two_circles" rear_offset: 0.2 # for type "two_circles" rear_radius: 0.2 # for type "two_circles" vertices: [ [0.25, -0.05], [0.18, -0.05], [0.18, -0.18], [-0.19, -0.18], [-0.25, 0], [-0.19, 0.18], [0.18, 0.18], [0.18, 0.05], [0.25, 0.05] ] # for type "polygon" # GoalTolerance xy_goal_tolerance: 0.2 yaw_goal_tolerance: 0.1 free_goal_vel: False complete_global_plan: True # Obstacles min_obstacle_dist: 0.5 # This value must also include our robot's expansion, since footprint_model is set to "line". inflation_dist: 0.8 include_costmap_obstacles: True costmap_obstacles_behind_robot_dist: 1.0 obstacle_poses_affected: 20 dynamic_obstacle_inflation_dist: 0.6 include_dynamic_obstacles: True costmap_converter_plugin: "" costmap_converter_spin_thread: True costmap_converter_rate: 8 # Optimization no_inner_iterations: 5 no_outer_iterations: 4 optimization_activate: True optimization_verbose: False penalty_epsilon: 0.1 obstacle_cost_exponent: 4 weight_max_vel_x: 2 weight_max_vel_theta: 1 weight_acc_lim_x: 1 weight_acc_lim_theta: 1 weight_kinematics_nh: 1000 weight_kinematics_forward_drive: 1 weight_kinematics_turning_radius: 1 weight_optimaltime: 1 # must be > 0 weight_shortest_path: 0 weight_obstacle: 100 weight_inflation: 0.2 weight_dynamic_obstacle: 10 # not in use yet weight_dynamic_obstacle_inflation: 0.2 weight_viapoint: 1 weight_adapt_factor: 2 # Homotopy Class Planner enable_homotopy_class_planning: True enable_multithreading: True max_number_classes: 4 selection_cost_hysteresis: 1.0 selection_prefer_initial_plan: 0.95 selection_obst_cost_scale: 1.0 selection_alternative_time_cost: False roadmap_graph_no_samples: 15 roadmap_graph_area_width: 5 roadmap_graph_area_length_scale: 1.0 h_signature_prescaler: 0.5 h_signature_threshold: 0.1 obstacle_heading_threshold: 0.45 switching_blocking_period: 0.0 viapoints_all_candidates: True delete_detours_backwards: True max_ratio_detours_duration_best_duration: 3.0 visualize_hc_graph: False visualize_with_time_as_z_axis_scale: False # Recovery shrink_horizon_backup: True shrink_horizon_min_duration: 10 oscillation_recovery: True oscillation_v_eps: 0.1 oscillation_omega_eps: 0.1 oscillation_recovery_min_duration: 10 oscillation_filter_duration: 10 分析以上代码
最新发布
05-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值