Example p1 error

i am keep getting this error what does it means ?

Hi @80601 ,

From the error output, I think you have not initialized your node with a name.

It says you are missing the rospy.init_node(<your_node_name>) line in your program.

Check if you have included that line and let me know if your problem is fixed.

Regards,
Girish

the node is already included

python file contain the service

#! /usr/bin/env python

import rospy
from std_srvs.srv import Empty,EmptyResponse 
from bb8_move_circle_class import MoveBB8

def my_callback(request):
    rospy.loginfo("The Service move_bb8_in_circle has been called")
    movebb8_object = MoveBB8()
    movebb8_object.move_bb8()
    rospy.loginfo("Finished service move_bb8_in_circle")
    return EmptyResponse() 

rospy.init_node('service_move_bb8_in_circle_server') 
my_service = rospy.Service('/move_bb8_in_circle', Empty , my_callback)
rospy.loginfo("Service /move_bb8_in_circle Ready")
rospy.spin() # keep the service open.

python class file

#! /usr/bin/env python

import rospy
from geometry_msgs.msg import Twist

class MoveBB8():
    
    def __init__(self):
        self.bb8_vel_publisher = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
        self.cmd = Twist()
        self.ctrl_c = False
        self.rate = rospy.Rate(10) # 10hz
        rospy.on_shutdown(self.shutdownhook)
        
    def publish_once_in_cmd_vel(self):

        while not self.ctrl_c:
            connections = self.bb8_vel_publisher.get_num_connections()
            if connections > 0:
                self.bb8_vel_publisher.publish(self.cmd)
                rospy.loginfo("Cmd Published")
                break
            else:
                self.rate.sleep()
        
    def shutdownhook(self):
        # works better than the rospy.is_shutdown()
        self.ctrl_c = True

    def move_bb8(self, linear_speed=0.2, angular_speed=0.2):
        
        self.cmd.linear.x = linear_speed
        self.cmd.angular.z = angular_speed
        
        rospy.loginfo("Moving BB8!")
        self.publish_once_in_cmd_vel()
            
if __name__ == '__main__':
    rospy.init_node('move_bb8_test', anonymous=True)
    movebb8_object = MoveBB8()
    try:
        movebb8_object.move_bb8()
    except rospy.ROSInterruptException:
        pass



rospy.spin()

launch file

<launch>
    <!-- Start Service Server for move_bb8_in_circle service -->
    <node pkg="my_python_class" type="bb8_move_circle_service_server.py" name="service_move_bb8_in_circle_server"  output="screen">
    </node>
</launch>

Hi @80601 ,

I think I found your problem, it is in your python class file containing class MoveBB8().

if __name__ == '__main__':
    rospy.init_node('move_bb8_test', anonymous=True)
    movebb8_object = MoveBB8()
    try:
        movebb8_object.move_bb8()
    except rospy.ROSInterruptException:
        pass
    rospy.spin() # this line must be written here



# rospy.spin() # delete this line

I believe that should fix your problem.

Also I saw another mistake in your picture:
rosservice call /move_bb8_in_circle [TAB]+[TAB]

You should not type the above line as is.
You should type upto rosservice call /move_bb8_in_circle and then press TAB key on yor keyboard twice. You should not type “[TAB]+[TAB]”.

Regards,
Girish