I have been off the site for a little while but am trying to get started again!
I restarted my program and noticed that while my sensor is distance is decreasing, it is doing so very slowly and not keeping up with my gazebo robot. By the time my turtebot hits the wall, I am at a distance of 0.87 or so. Is it not updating fast enough? Codes below
Also - not as critical, but im never able to get to the 4th checkpoint ( print point 4 completed) on my action client. It isnt creating issues but is driving my crazy!
#! /usr/bin/env python import rospy import actionlib import turtle2.msg from turtle2.msg import turtlemvmtAction, turtlemvmtGoal, turtlemvmtResult, turtlemvmtFeedback import rospy import sensor_msgs.msg from geometry_msgs.msg import Twist from sensor_msgs.msg import LaserScan from std_msgs.msg import String class ActionClient(): #prereq instead of of object , or self??? def __init__(self, dist): #Constructors are used to initialize the object’s state. The task of constructors is to initialize(assign values) to the data members of the class when an object of class is created. Like methods, a constructor also contains collection of statements(i.e. instructions) that are executed at time of Object creation. It is run as soon as an object of a class is instantiated. The method is useful to do any initialization you want to do with your object. self.dist = dist self.sub = rospy.Subscriber('/scan', LaserScan, self.callback) rate = rospy.Rate(100) def callback(self, msg) : self.dist = (msg.ranges) print ("point 1", self.dist) self.call_server() def feedback_cb(self): print ("point 4: completed") def call_server(self): print ("point 2, server called") print ("point 3", self.dist) self.client = actionlib.SimpleActionClient('sharedspace', turtlemvmtAction) self.client.wait_for_server() self.goal = turtlemvmtGoal() self.goal.ranges = float(self.dist) print ("point3a", self.goal.ranges) self.client.send_goal(self.goal, feedback_cb = self.feedback_cb) self.client.wait_for_result(timeout=rospy.Duration(1)) result = self.client.get_result() return result if __name__ == '__main__': try: rospy.init_node('action_client') j = ActionClient(dist=) print ('The result is:', ) rospy.spin() except rospy.ROSInterruptException as e: print ('Something went wrong:', e)
#! /usr/bin/env python import turtle2.msg from turtle2.msg import turtlemvmtAction, turtlemvmtFeedback, turtlemvmtResult, turtlemvmtGoal import rospy from geometry_msgs.msg import Twist from sensor_msgs.msg import LaserScan from std_msgs.msg import String import actionlib import actionlib_tutorials.msg class ActionServer(object): # create messages that are used to publish feedback/result #feedback = turtle2.msg.turtlemvmtFeedback() #result = turtle2.msg.turtlemvmtResult() #goal = turtle2.msg.turtlemvmtGoal() def __init__(self): self._as = actionlib.SimpleActionServer('sharedspace', turtlemvmtAction, execute_cb=self.execute_cb, auto_start = False) self.pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1) self.Twistobj = Twist() self._as.start() print ("executing1 @ ",) def execute_cb(self, goal): print ("executing2") success = True feedback = turtlemvmtFeedback() result = turtlemvmtResult() rate = rospy.Rate(100) while True: if self._as.is_preempt_requested(): self._as.set_preempted() success = False break if float(goal.ranges) > 0.3: self.Twistobj.linear.x = .002 self.Twistobj.linear.y = 0 self.Twistobj.linear.z = 0 self.Twistobj.angular.x = 0 self.Twistobj.angular.y = 0 self.Twistobj.angular.z = 0 self.pub.publish(self.Twistobj) print("goal 1 @", goal.ranges) continue elif float(goal.ranges) <0.2: self.Twistobj.linear.x = .01 self.Twistobj.linear.y = 0 self.Twistobj.linear.z = 0 self.Twistobj.angular.x = 20 self.Twistobj.angular.y = 0 self.Twistobj.angular.z = 0 self.pub.publish(self.Twistobj) print("goal 2 @", goal.ranges) continue elif 0.2 < float(goal.ranges) < 0.5: self.Twistobj.linear.x = .02 self.Twistobj.linear.y = 0 self.Twistobj.linear.z = 0 self.Twistobj.angular.x = 20 self.Twistobj.angular.y = 0 self.Twistobj.angular.z = 0 self.pub.publish(self.Twistobj) print("goal 3 @", goal.ranges) continue feedback.last_dish_washed = last_dish_washed result.dishes_washed.append(last_dish_washed) self._as.publish_feedback(feedback) rate.sleep() if success: self._as.set_succeeded(self._result) if __name__ == '__main__': rospy.init_node('action_server') server = ActionServer() rospy.spin()