I don’t get any error in my Program and BB8 also move like in a square path ( not a perfect square but something similar). I can successfully launch my server.launch and client.launch and eveyrthing work fine. But I don’t know why Gradebot shows unable to launch services_quiz client. Can anyone help me any suggestions would be highly Appreciated.
I want to tell this to you in a very clear way possible.
If you post incomplete codes and photographs instead of screenshots, it really frustrates us.
It frustrates people like me who are willing to help you. Imagine how it would frustrate the admins who are constantly dealing with the same issues from every new person like you!
Next time onwards, PLEASE, post the complete code and actual screenshot taken by pressing the “Print Screen” button on your keyboard.
Now to your problem:
Did you actually do what the error said?
Have you named your program and launch files as per instructions?
I have updated the post as you mentioned in your previous comment. And I also did check my file names too for your reference I have mentioned the exact file names That I use in my package. Thank you for fast response.
Your service server launch file has a lot of spaces. Improperly formatted launch files throw a lot of errors. I have faced similar issues before.
Try to fix the launch file formatting and run your package again. That should solve the problem.
Let me know if this did not solve the problem.
Regards,
Girish
EDIT: Just realized something, your server and client node names are same. So one of your programs will not work properly. Change the node name of the server to “move_square_server” and for the client, “move_square_client”. You will have to do the corresponding changes in the launch files too, in the name parameter.
Did you try running the service server and service client on your terminal before submitting to the gradebot?
Did your service server and service client work without any issues?
Also, if they work fine on the terminal, could you share the terminal output screenshots of the server and the client working?
This way we can be certain that the gradebot has some issue and not your program.
I see that your service server and client has worked well.
Although, your service server seems to print "Stop message sent" for every step of movement. (This is because of your program, you have copy-pasted print statements for stop(), move_straight() and rotate()).
So, at this point, with the assumption that your file names are correct and you do not have any other mistakes, I would say that the gradebot has some problem.
The problem is that your code is not doing what the quiz asked it to do, so it is exiting earlier than it should:
Create a new service client that calls the service /move_bb8_in_square_custom, and makes BB-8 move in a small square twice and in a bigger square once. It will be called bb8_move_custom_service_client.py. The launch that starts it will be called call_bb8_move_in_square_custom_service_server.launch.
Your code must make the BB8 move three times: twice for the small square and once for the big square. I checked that your code is making the robot move one small square only.
Please fix that and your code should pass. You are already more than halfway done!
That can still happen if it’s not moving the correct distance. Each side of the small square must be the length of one side of the square in the simulation, while that of the big square must be twice that.
You need to make the robot move these distances (or more) within the 3-minute deadline, neither too fast nor too slow.
I tried to correct my program as per your feedback. Can you please have a look at my modified code and give your feedback because I only have one last try to submit my assignment. My robot is moving in square path for twice in Small square and once in Big square. I would like to know whether my timing is correct or not
custom_service_client.py
#! /usr/bin/env python
import rospy
from rospy import Duration
from services_quiz.srv import BB8CustomServiceMessage, BB8CustomServiceMessageRequest
#from geometry_msgs.msg import Twist
rospy.init_node('move_square_client')
rospy.wait_for_service('/move_bb8_in_square_custom')
custom_client = rospy.ServiceProxy(
'/move_bb8_in_square_custom', BB8CustomServiceMessage)
start_time = rospy.Time.now()
for i in range(2):
custom_client_object = BB8CustomServiceMessageRequest()
custom_client_object.side = 1.0
custom_client_object.repetitions = 1
result = custom_client(custom_client_object)
rospy.loginfo('small square Completed')
# Update time
end_time = rospy.Time.now()
duration = end_time - start_time
duration_sec = duration.to_sec()
#duration_sec = duration.to_sec()
print("Completed 2 small squares in ", duration_sec)
# check time
if duration_sec <= 120:
print(" Completed small square in ", duration)
custom_client_object = BB8CustomServiceMessageRequest()
custom_client_object.side = 2.0
custom_client_object.repetitions = 1
result = custom_client(custom_client_object)
rospy.loginfo('Big square Completed')
print("Service_server is called")
# Update time
end_time = rospy.Time.now()
duration = (end_time - start_time).to_sec()
print("Completed Big squares in ", duration)
custom_service_server.py
#!/usr/bin/env python
from math import pi
import rospy
from services_quiz.srv import BB8CustomServiceMessage, BB8CustomServiceMessageResponse
from geometry_msgs.msg import Twist
pi = 3.14159
def stop():
# define the above mentioned function and send the twist messages here
move.linear.x = 0.0
move.angular.z = 0.0
pub.publish(move)
if not rospy.is_shutdown():
rospy.loginfo("Stop")
else:
rospy.logerr("Failed to stop")
# print('-X-')
def move_straight(side):
move.linear.x = 0.30 * side
move.angular.z = 0.0
pub.publish(move)
if not rospy.is_shutdown():
rospy.loginfo("Moving straight")
else:
rospy.logerr("Failed to move straight")
# print('->')
def rotate(angle):
move.linear.x = 0.0
move.angular.z = 1.0
time = abs(angle / 1.0)
pub.publish(move)
if not rospy.is_shutdown():
rospy.loginfo(" Rotating")
else:
rospy.logerr("Failed to rotate")
rospy.sleep(time)
# print('->')
def callback(req):
side = req.side
response = BB8CustomServiceMessageResponse()
for i in range(req.repetitions):
for j in range(4):
move_straight(side)
rospy.sleep(2)
stop()
rospy.sleep(2)
rotate(pi/2)
stop()
rospy.sleep(2)
pub.publish(move)
response.success = True
return response
if __name__ == "__main__":
rospy.init_node('move_square_server')
rospy.loginfo('service service started')
shan_service = rospy.Service(
'/move_bb8_in_square_custom', BB8CustomServiceMessage, callback)
pub = rospy.Publisher('/cmd_vel', Twist, queue_size=10)
move = Twist()
rospy.spin()