Ask Your Question
0

UR robot arm speed control

asked 2022-05-24 09:04:41 -0500

yemre0642 gravatar image

updated 2022-05-26 04:50:35 -0500

I use ros melodic with ubuntu 18. I wrote this script to change robot speed but I got an error. How can I fix this error?

ERROR: service [/SetSpeedSliderFraction] responded with an error: service cannot process request: service handler returned None

the code:

#!/usr/bin/env python

from __future__ import print_function
from ur_msgs.srv import SetSpeedSliderFraction, SetSpeedSliderFractionRequest, SetSpeedSliderFractionResponse

import rospy

def handle_req(req):
    print(SetSpeedSliderFractionRequest(req))

def set_robot_speed_server():
    rospy.init_node('set_robot_speed')
    s = rospy.Service('SetSpeedSliderFraction', SetSpeedSliderFraction, handle_req)
    print("Ready to set robot speed..")
    rospy.spin()


if __name__ == '__main__':
    set_robot_speed_server()

EDIT and Solution:

The callback should be like this:

def handle_req(req):
    if(SetSpeedSliderFractionResponse(req).success == req):
        return True
    else:
        return False
edit retag flag offensive close merge delete

Comments

What are you trying to do exactly?

rospy.Service(..) creates a new service server.

From your description however I get the impression you're trying to call an existing service.

gvdhoorn gravatar image gvdhoorn  ( 2022-05-24 12:10:08 -0500 )edit

I would like to create a custom service that uses the existing ros service that is ur_msgs/setSpeedSliderFraction. My aim is to reduce the robot speed by calling my custom service. According to this.

yemre0642 gravatar image yemre0642  ( 2022-05-24 15:45:44 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2022-05-26 04:49:03 -0500

yemre0642 gravatar image

updated 2022-05-26 04:51:15 -0500

I found the solution. In my callback, I need to return a boolean type because my response is bool.

Another issue, when I try to control robot arm speed with the real robot I can see the all ros services but I can't see them for simulation. If you want to use the existing ros service for simulation write a script and call it. If you will use a real robot, all services would be there and running.

Please correct me if I'm wrong, but your problem seems: I want to be able to set the speed and I can't get the server that was implemented working.

Thanks man I really appreciate your detailed answer but this is a journey and we learn every day huh :)

edit flag offensive delete link more
0

answered 2022-05-25 01:52:19 -0500

Joe28965 gravatar image

updated 2022-05-25 04:23:23 -0500

As gvdhoorn said, you're creating a service server. You want to create a client.

Have you seen this tutorial? I've linked to the part of the tutorial that focuses on the client side.

EDIT to respond to your comment:

Okay, so if I understand you correctly, the server set_speed_slider isn't available, so you want to implement your own server that does exactly the same.

First, take a look at the tutorial that I've linked. In line 10 of the server you can see that it performs a task:

return AddTwoIntsResponse(req.a + req.b)

Which is a simple way of writing:

int answer = req.a + req.b
return AddTwoIntsResponse(answer)

Where the first line is the task that the server needs to do (adding two ints) and the second line is returning the answer.

Taking a look at the srv SetSpeedSliderFraction:

float64 speed_slider_fraction
---
bool success

The input is a float, to set the speed. The output is a bool, to let the client know if it successfully set the speed.

My question here is: Even if you get your custom server working in the sense that it doesn't give errors, how are you actually going to implement the task of setting the speed? How are you going to get the result that you want? I think that's going to take some hacky solution to get it working.

However, this feels like a question where you've got a problem, thought of a solution and now need help implementing that solution. Which is fine, nothing wrong with that, that's what we're here for.

Having said that, sometimes we're also here to point out that your original problem is: Why isn't the set_speed_slider of ur_robot_driver_node available and why can't I write a client to connect to it.

Please correct me if I'm wrong, but your problem seems: I want to be able to set the speed and I can't get the server that was implemented working.

edit flag offensive delete link more

Comments

I tried running as a client but the existing ros service wasn't available so I decided to create a custom server. As far as I know, If I want to use rospy.wait_for_service the ros service should run. I can't see the ros service when I call rosservice list. Then the question how can start a ros service via script?

yemre0642 gravatar image yemre0642  ( 2022-05-25 03:58:04 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-05-24 09:04:41 -0500

Seen: 55 times

Last updated: May 26