PX4 avoidance ROS仿真之——使用自定义的飞机模型

运行自己的飞机模型主要需解决的问题

飞机模型的stereo相机话题

当你的飞机模型中包含了双目相机时,需要运行一个ROS的node,将下面内容添加到posix_sitl.launch文件中:

<!-- Launch stereo_image_proc node which runs OpenCV's block matching  -->
  <node ns="stereo" pkg="stereo_image_proc" type="stereo_image_proc" name="stereo_image_proc">
    <param name="stereo_algorithm" type="double" value="1.0" />
    <param name="correlation_window_size" type="double" value="19.0" />
    <param name="disparity_range" type="double" value="32.0" />
    <param name="uniqueness_ratio" type="double" value="40.0" />
    <param name="speckle_size" type="double" value="1000.0" />
    <param name="speckle_range" type="double" value="2.0" />
  </node>

要注意的是,你要将stereo的话题设置为:/stereo/left/image_raw和/stereo/right/image_raw
PS:我没有使用iris的sdf模型 我修改了models下iris的xacro文件,并在posix_sitl.launch中加载模型由sdf改成了xacro模型。

在posix_sitl.launch中添加

<!-- Launch local planner -->
  <node name="local_planner_node" pkg="local_planner" type="local_planner_node" output="screen" >
    <param name="goal_x_param" value="15" />
    <param name="goal_y_param" value="15"/>
    <param name="goal_z_param" value="4" />
    <param name="world_name" value="$(find avoidance)/sim/worlds/simple_obstacle.yaml" />
    <rosparam param="pointcloud_topics" subst_value="True">$(arg pointcloud_topics)</rosparam>
  </node>

  <node name="rviz" pkg="rviz" type="rviz" output="screen" args="-d $(find local_planner)/resource/local_planner.rviz" />

这是启动了局部路径规划节点和避障节点。
注意的是,在posix_sitl.launch最顶部,我已经修改了world参数为simple_obstacle.world
其实也就是要注意所有参数的定义是什么~

目前遇到的问题

在没有修改使用官方提供的程序时,局部路径规划的速度以及无人机执行的速度在xy方向很快,在z方向略慢。
但是换我的飞机后,xy方向还不错,但是z方向特别特别特别特别的慢,观察是因为在接近目标点上方无人机很难定住,而是在上方左右一直在不断调整,因此很难向下运动。目前这个问题还没解决

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的ROS导航机器人模型代码,可以作为参考: ```python #!/usr/bin/env python import rospy from geometry_msgs.msg import Twist from nav_msgs.msg import Odometry from sensor_msgs.msg import LaserScan import tf import math class Robot: def __init__(self): rospy.init_node('robot_navigation') self.odom_sub = rospy.Subscriber('/odom', Odometry, self.odom_callback) self.scan_sub = rospy.Subscriber('/scan', LaserScan, self.scan_callback) self.cmd_vel_pub = rospy.Publisher('/cmd_vel', Twist, queue_size=10) self.tf_listener = tf.TransformListener() self.rate = rospy.Rate(10) self.cmd_vel = Twist() self.goal_x = 2.0 self.goal_y = 2.0 self.goal_tolerance = 0.1 self.distance_tolerance = 0.5 self.angle_tolerance = 0.1 def odom_callback(self, msg): try: (trans, rot) = self.tf_listener.lookupTransform('/map', '/base_link', rospy.Time(0)) except (tf.LookupException, tf.ConnectivityException, tf.ExtrapolationException): return current_x = trans[0] current_y = trans[1] current_yaw = tf.transformations.euler_from_quaternion(rot)[2] distance_to_goal = math.sqrt((self.goal_x - current_x)**2 + (self.goal_y - current_y)**2) if distance_to_goal < self.goal_tolerance: self.cmd_vel.linear.x = 0.0 self.cmd_vel.angular.z = 0.0 self.cmd_vel_pub.publish(self.cmd_vel) rospy.loginfo('Goal reached!') rospy.signal_shutdown('Goal reached!') else: angle_to_goal = math.atan2(self.goal_y - current_y, self.goal_x - current_x) angle_difference = angle_to_goal - current_yaw if angle_difference > math.pi: angle_difference -= 2 * math.pi elif angle_difference < -math.pi: angle_difference += 2 * math.pi if abs(angle_difference) < self.angle_tolerance: self.cmd_vel.linear.x = 0.5 else: self.cmd_vel.linear.x = 0.0 if distance_to_goal > self.distance_tolerance: if angle_difference > self.angle_tolerance: self.cmd_vel.angular.z = 0.5 elif angle_difference < -self.angle_tolerance: self.cmd_vel.angular.z = -0.5 else: self.cmd_vel.angular.z = 0.0 self.cmd_vel_pub.publish(self.cmd_vel) def scan_callback(self, msg): # Add obstacle detection and avoidance here pass def run(self): while not rospy.is_shutdown(): self.rate.sleep() if __name__ == '__main__': robot = Robot() robot.run() ``` 这个机器人模型会订阅`/odom`和`/scan`话题,发布基于里程计和激光雷达数据的速度控制命令到`/cmd_vel`话题,以达到机器人导航到目标点的目的。你可以根据自己的需求进行修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值