将turtlebot2绕其轴旋转10度

问题描述

你好吗?如何将turtlebot2绕其轴旋转10度,然后暂停。 注意:机器人不会移动,只会说20秒一次,旋转10度。 我尝试在Z方向上设置Twist()对象的角速度,但只有一个轮子移动,最终机器人移位了。

下面是我的代码

                angular_veLocity = radians(10) #10 degs / s

                r = rospy.Rate(5) #5Hz
                #rospy.loginfo("starting loop")
                while not rospy.is_shutdown():
                        rospy.loginfo("in loop")
                        new_angle = (angle + new_angle) % 360
                        real_angle = real_angle + angle
                        #real_angle = rea1_angle + 5
                        rospy.loginfo("after addition")
                        new_angle =  real_angle % 360
                  
                        turn_cmd.angular.z = angular_veLocity #turns 10 degrees a second
                        #turn at 10 degrees a second for 1 second  
                        for i in range(5):
                                self.cmd_vel.publish(turn_cmd)
                                r.sleep()
                        r.sleep()
    # wait 40s
                        for x in range(200):
                                self.cmd_vel.publish(Twist()) #publish ) to stop the bot at that point
                                # stop the turtle and gather data as u  wait
                                r.sleep()
                                try:
                                        data = "get some data from external source"
                                        if(data):
                                                try:
                                                        #rospy.loginfo("w(rads/$
                                                        comb_d.write( str(data)
                                                except:
                                                        rospy.loginfo("Failed or bad data)
                                                        pass
                          r.sleep()
                          comb_d.close()


        def shutdown(self):
                # stop turtlebot
                rospy.loginfo("Stop turning")
                self.cmd_vel.publish(Twist())
                       

以上是我的逻辑。但是机器人不仅会移动,而且不会像我期望的那样旋转10度。 我究竟做错了什么? 非常感谢你。 我正在使用ROS靛蓝kobuki和turtlebot2

话虽这么说-稍微不同一点-rospy.Rate()函数和内部for循环以达到10甚至30的有利值是多少相对较高的角速度(例如25 degrees per second)旋转1度。因为似乎机器人在10 degs/s等低速下不能很好地工作。有时,当给出低速时,它根本不会移动。无论如何,谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)