Course Project - why complicated action setup

So I looked at the example solution for the action_server, with the 3 scripts and triple launch file and I fail to understand the purpose of this. My solution seems much simpler, shorter. What are the advantages of the example approach, what could be problems with mine?

My record_odom.action (kept the name from example):

#goal Empty

#result definition
bool success
float64 time

float64 distance
float64 time

my (I left out the imports here to make it shorter)

class RecordOdomClass(object):

def __init__(self):
    self.maxtime = 60
    self.maxdist = 2
    self.rate = rospy.Rate(25)
    self._odom_reader_object = OdomTopicReader()
    self._as = actionlib.SimpleActionServer("record_odom_as", record_odomAction, self.goal_callback, False)
    self.ctrl_c = False
    self._result   = record_odomResult()
    self._feedback = record_odomFeedback
    self._result.success = False
    rospy.loginfo('record_odom_as Server ready, waiting for calls')

def goal_callback(self, goal):
    # this callback is called when the action server is called.
    start_time = time.time()
    start_pos = self._odom_reader_object.get_odomdata().pose.pose.position
    while not self.ctrl_c:
        pos = self._odom_reader_object.get_odomdata().pose.pose.position
        distance = sqrt(pow(start_pos.x-pos.x,2)+pow(start_pos.y-pos.y,2)+pow(start_pos.z-pos.z,2))
        if distance > self.maxdist:
            self._result.success = True
        if time.time() - start_time > self.maxtime:

    self._result.time = time.time() - start_time
    return self._result

def shutdownhook(self):
    # works better than the rospy.is_shutdown()
    self.ctrl_c = True

if name == ‘main’:

Hi Simon,

Thank you for the feedback.

Please try out your solution and see if it achieves the objective. The solution provided is not the only way to do it and is not necessarily the best - we are open to “pull requests” for this :wink:.