Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Service Call capability #35

Closed
jaguardo opened this issue Apr 28, 2021 · 7 comments
Closed

Add Service Call capability #35

jaguardo opened this issue Apr 28, 2021 · 7 comments

Comments

@jaguardo
Copy link
Contributor

Should be similar to Topic?

@flynneva
Copy link
Owner

that would definitely be something if we could enable services and actions. would have to do some research how difficult this would be...

@jaguardo
Copy link
Contributor Author

jaguardo commented May 6, 2021

so, ros services is just an array, whereas topics is an object with an array (RobotWebTools/roslibjs#363)... so stay true to roslibjs and just pass through the array, or add the functionality so that topics and services act the same? (I chose the later to get it to work):

  function getServices() {
    const servicesPromise = new Promise((resolve, reject) => {
      ros.ROS.getServices((services) => {
        const serviceList = services.map((serviceName) => {
          return {
            path: serviceName,
            type: "service",
          }
        });
        resolve({
          services: serviceList
        });
        reject({
          services: []
        });
      }, (message) => {
        console.error("Failed to get services", message)
        ros.services = []
      });
    });
    servicesPromise.then((services) => setROS(ros => ({ ...ros, services: services.services })));
    return ros.services;
  }

so instead of [... , ... , ... ] you get [{...}, {...}, {...}] returned... either way is probably fine, OCD in me likes the later to match the topic return... but you are not really getting any more information, since we are just arbitrarily adding type:"service" as another key:value element... but you already "know" that because of the react-ros variable is called "services"!

@jaguardo
Copy link
Contributor Author

jaguardo commented May 6, 2021

I tested the function above and it seems to work... this "may" work if we want to be purists and just return the array:

  function getServices() {
    const servicesPromise = new Promise((resolve, reject) => {
      ros.ROS.getServices((services) => {
        const serviceList = services.map((serviceName) => {
          return {
            serviceName,
          }
        });
        resolve({
          services: serviceList
        });
        reject({
          services: []
        });
      }, (message) => {
        console.error("Failed to get services", message)
        ros.services = []
      });
    });
    servicesPromise.then((services) => setROS(ros => ({ ...ros, services: services })));
    return ros.services;
  }

@jaguardo
Copy link
Contributor Author

jaguardo commented May 6, 2021

This works for a simple "clear" command to the turtlesim... not sure how to "universalize it" within react-ros:

      var cleanTurtle = new ROSLIB.Service({
         ros : ros,
         name : '/clear',
      });

      var request = new ROSLIB.ServiceRequest({});

      cleanTurtle.callService(request, function(result){console.log((result))});

instead of "listeners", could create an array of "servicers"? would be nice if react-ros returned a function call, so to send the service call, you would just call it, i.e. ( cleanTurtle())... I'm sure there are service calls that get a bit more complex though.

@jaguardo
Copy link
Contributor Author

jaguardo commented May 6, 2021

for a "/kill" service to the turtlesim, the request becomes

var request = new ROSLIB.ServiceRequest({name: 'turtle1'})

so it will get challenging to incorporate something "easy"... maybe a function that accepts arguments (defaults to none) and leave it to the user to figure out how to use it... because the arguments can get pretty complex! http://wiki.ros.org/roslibjs/Tutorials/Writing%20a%20dynamic_reconfigure%20client%20with%20roslibjs

  38     var request = new ROSLIB.ServiceRequest({
  39         config: {
  40             bools: [
  41                 // {name: '', value: false}
  42             ],
  43             ints: [
  44                 // {name: '', value: 0}
  45             ],
  46             strs: [
  47                 // {name: '', value: ''}
  48             ],
  49             doubles: [
  50                 {name: 'Kp_scale', value: 10.0},
  51                 {name: 'Kp', value: 0.1},
  52                 {name: 'Ki_scale', value: 0.1},
  53                 {name: 'Ki', value: 0.2},
  54                 {name: 'Kd_scale', value: 1.0},
  55                 {name: 'Kd', value: 0.3},
  56             ],
  57             groups: [
  58                 // {name: '', state: false, id: 0, parent: 0}
  59             ]
  60         }
  61     });

@flynneva
Copy link
Owner

@jaguardo this one too?

@jaguardo
Copy link
Contributor Author

No issue, actually making a service call is going to be pretty involved (getting the list is not bad)... not sure if it is worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants