Calling a service through an action?

Just a quick question on the exam, task 3:

I’ve got the rest of the stuff running, and i can return the action result fine when i do a rostopic pub to the action server topic. However, i’m considering my next step in regards to the timed recording of the /gt_pose. The task doesnt specifically state to make use of the service server previously created, however, this seems obvious to use, since it records the required data, just not in time intervals. But i’m a little confused as to how i should make a call to the service server from within the action server?

This is what i have so far (with some added pseudo code in the middle).
Any hints would be appreciated! Thanks

#!/usr/bin/env python

import rospy

import actionlib

import time

from path_exam.msg import RecordOdomAction, RecordOdomGoal, RecordOdomResult


class CheckDistanceActionServer:

    def __init__(self):

        self._as = actionlib.SimpleActionServer('/rec_pose_as', RecordOdomAction, execute_cb=self.on_goal, auto_start=False)

        self._as.start()

        rospy.loginfo("Check Distance Action Server has been started")

    def on_goal(self, goal):

        rospy.loginfo("A goal has been received!")
        
       #start some timer in ROS time
       # all_positions = []
       # while timer < 20 seconds:
            #for each second in 20 seconds:
                 #variable = current /gt_pose data
                 # all_positions.append(variable)


        #result = RecordOdomResult()

        #result.position = all_positions

        rospy.loginfo(result)

        rospy.loginfo("send goal result to client")

        self._as.set_succeeded(result)

if __name__== '__main__':

    rospy.init_node('distance_action_server')

    server = CheckDistanceActionServer()

    rospy.spin()    # keeps the node alive. with ctrl + c this allows the shutdown of the node.

Some limited hints (this is an exam after all):

  • You need to keep your service service running in order to call it.
  • Call it as you did in the Services Quiz: create a service client that connects to the service server.

Please note that there are several ways to achieve the same thing; as long as you achieve the aim, you are good to go!

Understood, thanks.

Will it mess with the test if i create more files than asked for? Say, a file motion_service_client.py with a class ServiceClient that i can then import into the check_distance_action.py in an instance variable to access the service call response data?

You don’t need to create the service client in another file - you can create it right within the action server file. This keeps things simple.

I finished the exam with a score of 9 this morning. When i had no accomplishment yet i was able to see the 2 that are possible to acquire under my “accomplishments”, but since i got the ROS Code foundation certificate, i’m unable to find anything about the one from the beginners learning path.

I think its a little hard to figure out what i have to do to acquire the ROS beginners certificate. I thought i just had to pass the final exam, but there’s quite a bit of misleading information in the final exam notebook. Can you please clarify what has to be done? Thank you

Update: i’ve just now found the “View scores”. From this, i figure i’ll need to make sure i finish ALL the quizzes in the path, with a grade good enough to amount to a total of minimum 8.

1 Like