When I execute this file in Ros basics in 5 days course from 8.12a exercise, I’m facing a problem in execution because of the order is staying at 0. So, no feedback has happened and result has been obtained.
Hi, if you want help with a problem you’re having, please share more information. A screenshot of the error message and relevant code in the exercise is a good place to start.
#! /usr/bin/env python
import rospy
import time
import actionlib
from actionlib.msg import TestFeedback, TestResult, TestAction
from geometry_msgs.msg import Twist
from std_msgs.msg import Empty
class MoveSquareClass(object):
_feedback = TestFeedback()
_result = TestResult()
def init(self):
self._as = actionlib.SimpleActionServer(“move_drone_square_as”, TestAction, self.goal_callback, False)
self._as.start()
self.ctrl_c = False
self.rate = rospy.Rate(10)
def publish_once_in_cmd_vel(self,cmd):
while not self.ctrl_c:
connections = self._pub_cmd_vel.get_num_connections()
if connections > 0:
self._pub_cmd_vel.publish(cmd)
rospy.loginfo("Publish in cmd_vel...")
break
else:
self.rate.sleep()
def stop_drone(self):
rospy.loginfo("Stopping...")
self._move_msg.linear.x = 0.0
self._move_msg.angular.z = 0.0
self.publish_once_in_cmd_vel(self._move_msg)
def turn_drone(self):
self._move_msg.linear.x = 0
self._move_msg.angular.z = 1
rospy.loginfo("Turning...")
self.publish_once_in_cmd_vel(self._move_msg)
def move_froward_drone(self):
rospy.loginfo("Moving Forward")
self._move_msg.linear.x = 1
self._move_msg.angular.z = 0
self.publish_once_in_cmd_vel(self._move_msg)
def goal_callback(self, goal):
r = rospy.Rate(1)
success = True
self._pub_cmd_vel = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
self._move_msg = Twist()
self._pub_takeoff = rospy.Publisher('/drone/takeoff', Empty, queue_size=1)
self._takeoff_msg = Empty()
self._pub_land = rospy.Publisher('/drone/land', Empty, queue_size=1)
self._land_msg = Empty()
i=0
while not i == 3:
self._pub_takeoff.publish(self._takeoff_msg)
rospy.loginfo('Taking off...')
time.sleep(1)
i += 1
sideSeconds = goal.goal
turnSeconds = 1.8
i = 0
for i in range(0, 4):
if self._as.is_preempt_requested():
rospy.loginfo('The goal has been cancelled/preempted')
self._as.set_preempted()
success = False
break
self.move_forward_drone()
time.sleep(sideSeconds)
self.turn_drone()
time.sleep(turnSeconds)
self._feedback.feedback = i
self._as.publish_feedback(self._feedback)
r.sleep()
if success:
self._result.result = (sideSeconds*4) + (turnSeconds*4)
rospy.loginfo('The total seconds it took the drone to perform the square was %i' % self._result.result )
self._as.set_succeeded(self._result)
self.stop_drone()
i=0
while not i == 3:
self._pub_land.publish(self._land_msg)
rospy.loginfo('Landing...')
time.sleep(1)
i += 1
if name == ‘main’:
rospy.init_node(‘move_drone_square’)
MoveSquareClass()
rospy.spin()
My launch file is shown below.
<node pkg="exercise_513" type="move_drone_square.py" name="move_drone_square" output="screen" />
This is not fibonacci example but it is the example below fibonacci and even fibonacci code from this chapter is an example already given by the construct isn’t working when executed. I don’t understand why it is not getting executed.
Please share a screenshot of the output error from your terminal. The fact that the example is not working makes me believe there’s a problem with your setup. Try removing your build/ and devel/ folders and compiling again:
cd ~/catkin_ws/
rm -rf build/ devel/
catkin_make