瞬驰(Dash)D1开发手册--超声波使用说明

超声波测距

瞬驰(Dash)D1底盘有四个超声波(前面三个后面一个),通过如下两种方式获取超声波的值。

方式一: 下位机中获取超声波数据

通过USB串口方式连接下位机。通过如下命令读取下位机的值。

输入:p\r
输出:179 340 10 240\r
输出距离单位: 厘米(cm)

前面3个超声波,后面1个超声波。输出的值顺序是:前面左边、前面中间、前面右边、后面中间。

注意:该型号的超声波的测量距离为 0.02m ~ 4 m , 如果返回值不再该范围,请忽略。

方式二:在RoS下新增 超声波topic

在ros_arduino_bridge/ros_arduino_python/src/ros_arduino_python目录下,修改两个文件。

  • 把arduino_driver.py中把
    def ping(self, pin):
        ''' The srf05/Ping command queries an SRF05/Ping sonar sensor
            connected to the General Purpose I/O line pinId for a distance,
            and returns the range in cm.  Sonar distance resolution is integer based.
        '''
        return self.execute('p %d' %pin);

修改为如下内容:

    def ping(self):
        values = self.execute_array('p')
        if len(values) != 4:
            print "ping count was not 4"
            raise SerialException
            return None
        else:
            return values
  • 在base_controller.py文件中修改三处:
    1. 在文件开头
from tf.broadcaster import TransformBroadcaster

后面增加如下一行

from std_msgs.msg import String
  1. 在def init(self, arduino, base_frame)函数中
        # Set up the odometry broadcaster
        self.odomPub = rospy.Publisher('odom', Odometry)
        self.odomBroadcaster = TransformBroadcaster()

后面增加

        self.ultrasonicPub = rospy.Publisher('ultrasonic', String)

3.在def poll(self)函数中

        now = rospy.Time.now()
        if now > self.t_next:
            try:

后面增加

            try:
                u1, u2,u3,u4 = self.arduino.ping()
                self.ultrasonicPub.publish(str(u1)+" "+str(u2)+" "+str(u3)+" "+str(u4))
            except:
                rospy.logerr("ping exception")

使用方法:

重新运行

roslaunch ros_arduino_python  arduino.launch

在另一个终端,就可以获取到超声波的值。

rostopic echo /ultrasonic    

返回数据格式:一个字符串,四个超声波的值以空格分割, 单位厘米。 四个超声波的值依次是前面左一,前面中间,前面右一, 后面中间。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值