ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

calling a service from an other file on the same machine

asked 2011-12-26 08:32:44 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

Hello guys, I am a newbie to ROS, I am trying to make my ARDRONE more intelligent by using Brown's package for ARDRONE.T I I need to call this service :

bool toggleCamCallback(std_srvs::Empty::Request& request, std_srvs::Empty::Response& response)
{
  if (cam_state == 0) // toggle to 1, the vertical camera
    {
      cam_state = 1;
#ifdef _USING_SDK_1_7_
      ARDRONE_TOOL_CONFIGURATION_ADDEVENT (video_channel, &cam_state, NULL);
#else
      ardrone_at_set_toy_configuration("video:video_channel","1");
#endif
      fprintf(stderr, "\nToggling from frontal camera to vertical camera.\n");
    }
  else if (cam_state == 1) // toggle to the forward camera
    {
      cam_state = 0;
#ifdef _USING_SDK_1_7_
      ARDRONE_TOOL_CONFIGURATION_ADDEVENT (video_channel, &cam_state, NULL);
#elsebool toggleCamCallback(std_srvs::Empty::Request& request, std_srvs::Empty::Response& response)
{
  if (cam_state == 0) // toggle to 1, the vertical camera
    {
      cam_state = 1;
#ifdef _USING_SDK_1_7_
      ARDRONE_TOOL_CONFIGURATION_ADDEVENT (video_channel, &cam_state, NULL);
#else
      ardrone_at_set_toy_configuration("video:video_channel","1");
#endif
      fprintf(stderr, "\nToggling from frontal camera to vertical camera.\n");
    }
  else if (cam_state == 1) // toggle to the forward camera
    {
      cam_state = 0;
#ifdef _USING_SDK_1_7_
      ARDRONE_TOOL_CONFIGURATION_ADDEVENT (video_channel, &cam_state, NULL);
#else
      ardrone_at_set_toy_configuration("video:video_channel","0");
#endif
      fprintf(stderr, "\nToggling from vertical camera to frontal camera.\n");      
    }
  return true;
}
      ardrone_at_set_toy_configuration("video:video_channel","0");
#endif
      fprintf(stderr, "\nToggling from vertical camera to frontal camera.\n");      
    }
  return true;
}

I was able to invoke the service by entering the command: "rosservice call/ardrone/togglecam"*

But ,I am trying to find a way to call the service from other file(so that I can toggle between the cameras easily) please help!!!!!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2011-12-26 09:50:09 -0600

Eric Perko gravatar image

Take a look at the service client tutorial. This gives an example of making a simple service client in C++ and calling the service from that C++ code, as opposed to with rosservice on the command line.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2011-12-26 08:32:44 -0600

Seen: 615 times

Last updated: Dec 26 '11