ROS Services Quiz

Hello All, I am not sure how to implement the side request to my Move_BB8 function. I am thinking of that the side = move_square.linear.x * move time (displacement = velocity * time). But I am not positive toward my thought. Here is my code shown below without the implementation of side. Appreciate anyone who could help me out!

def Move_BB8(request) :

#repeat the robot movement for request.repetitions times

i = 0

while i < request.repetitions :

    #move the robot in square

    j = 0

    while j < 4: #(j=0,1,2,3)

        move_square.linear.x = 0.2 #go straight 

        rate.sleep()

        move_square.linear.x = 0.0 #stop to attenuate the inertia effect

        rate.sleep()

        move_square.angular.z = 0.1 #make a turn 

        rate.sleep()

        move_square.angular.z = 0.0 #stop to attenuate the inertia effect

        rate.sleep()

        my_pub.publish(move_square)

        rate.sleep()

        j+=1

    i+=1

rospy.loginfo("Finished service move_bb8_in_square_custom")

response = BB8CustomServiceMessageResponse()

response.success = True

return response
1 Like

Hi @tonyli19970130,
Dont forget to publish the move_square each time you change it. Also using rate.sleep seems kinda weird in this instant, as you are not really dealing with a continuous loop. Rather use fixed values.
rospy.sleep(1) for example. Then you can simply change the length of the square by waiting longer after publishing the forward move command.

1 Like

Hi Simon, Thanks for the correction and now the robot moves perfectly fine. But when I do the quiz evaluation, it said that I did not have my services_quiz pkg compiled as shown below. I wonder if you could give me some hints on this error further. Appreciate for your time.

It is hard to say. Double and triple check your spelling and naming of packages. @bayodesegun perhaps you can take a look.

I forgot to include the BB8CustomServiceMessage.srv in the services_quiz package and have it complied. Now I got 10 for the quiz. Appreciate all the help!

1 Like