def my_callback(request):
global move_circle
global my_pub
rospy.loginfo("The Service move_bb8_in_circle has been called")
move_circle.linear.x = 0.2
move_circle.angular.z = 0.2
my_pub.publish(move_circle)
rospy.loginfo("Finished service move_bb8_in_circle")
return EmptyResponse()
It actually works, as the global keyword is not needed for those variables:
There’s no need to use the global keyword to access a global variable (it’s required when you are modifying it). Regarding my_pub, we are merely accessing one of it’s methods.
We also don’t need to use the global keyword to modify properties of a global object. In this case, move_circle. This is a special case for objects, vs “plain” variables, I understand that this is quite surprising and interesting!
Hi,
could u check why my code doesn’t work.
I think it’s basically the same, but the robot doesn’t move at all, and only the loginfo outseide the fcun is printed
thank u!
You are showing in your screenshot that you have launched the service server, now you have to call that service from a different terminal in order for the robot to move.