Action server not working

Im having trouble getting my action server to return the result to the action client and i keep getting errors. i looked at the solution but i can’t see why my code is wrong since all its supposed to do is return a odometry array. Here is my code.

#! /usr/bin/env python
import rospy
import time
import actionlib
from my_turtlebot_actions.msg import record_odomAction, record_odomResult, record_odomFeedback
from nav_msgs.msg import Odometry
from odom_sub import OdomSub
from std_msgs.msg import Empty

class IsOut():

    def __init__(self):
        # creates the action server
        self._as = actionlib.SimpleActionServer("record_odom_as", record_odomAction, self.goal_callback, False)
        #self.ctrl_c = False
        #self.rate = rospy.Rate(10)
        self.read_odom = OdomSub()
        #self.odom_data = self.read_odom.get_odomdata()
        self._result = record_odomResult()

    def goal_callback(self,goal):
        success = True
        self.odom_data = self.read_odom.get_odomdata()
        self.odom_pose = self.odom_data.pose.pose.position
        rate = rospy.Rate(1)

        # this callback is called when the action server is called.
        # and returns to the node that called the action server
        print('as has been called')
        #self.l = [1,2]
        while i < 10:
            i +=1

        # If success, then we publish the final result
        # If not success, we do not publish anything in the result
        if success:

if __name__ == '__main__':

Here is my error when I try to call it.

user:~/catkin_ws/src/my_turtlebot_actions/src$ python

[WARN] [1609557919.440018, 9321.483000]: Inbound TCP/IP connection failed: connection from sender terminated before handshake header received. 0 bytes were received. Please check sender for additional details.
as has been called
x: -3.64741445896
y: -8.18342546336
z: -0.00017957276511
[INFO] [1609557932.118607, 9334.100000]: Succeeded
[ERROR] [1609557932.121599, 9334.103000]: Exception in your execute callback: 'function' object has no attribute 'header'
Traceback (most recent call last):
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/actionlib/", line 289, in executeLoop
  File "", line 47, in goal_callback
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/actionlib/", line 162, in set_succeeded
    self.current_goal.set_succeeded(result, text)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/actionlib/", line 195, in set_succeeded
    self.action_server.publish_result(self.status_tracker.status, result)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/actionlib/", line 182, in publish_result
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/", line 882, in publish
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/", line 1066, in publish
    serialize_message(b, self.seq, message)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/", line 152, in serialize_message
  File "/home/user/catkin_ws/devel/lib/python2.7/dist-packages/my_turtlebot_actions/msg/", line 231, in serialize
    _v1 = val1.header
AttributeError: 'function' object has no attribute 'header'

[ERROR] [1609557932.122512, 9334.104000]: To transition to an aborted state, the goal must be in a preempting or active state, it is currently in state: 3

The client I use to test it is simple and i don’t think its the issue but here is the client code.

#! /usr/bin/env python
import rospy
import time
import actionlib
from my_turtlebot_actions.msg import record_odomAction, record_odomResult, record_odomGoal

def feedback_callback(feedback):
# initializes the action client node
# create the connection to the action server
client = actionlib.SimpleActionClient('/record_odom_as', record_odomAction)
# waits until the action server is up and running
# creates a goal to send to the action server
goal = record_odomGoal()
#no goal
client.send_goal(goal, feedback_cb=feedback_callback)

print('[Result] State: %d'%(client.get_state()))

if it helps any, this is my OdomSub.

#! /usr/bin/env python

import time
import rospy
from nav_msgs.msg import Odometry

class OdomSub:
    def __init__(self):
        self.sub = rospy.Subscriber('/odom', Odometry, self.callback)
        self._odomdata = Odometry()

    def callback(self, msg): 
       # print msg.pose.pose.position.y
        self._odomdata = msg

    def get_odomdata(self):
        Returns the newest odom data

    std_msgs/Header header
      uint32 seq
      time stamp
      string frame_id
    string child_frame_id
    geometry_msgs/PoseWithCovariance pose
      geometry_msgs/Pose pose
        geometry_msgs/Point position
          float64 x
          float64 y
          float64 z
        geometry_msgs/Quaternion orientation
          float64 x
          float64 y
          float64 z
          float64 w
      float64[36] covariance
    geometry_msgs/TwistWithCovariance twist
      geometry_msgs/Twist twist
        geometry_msgs/Vector3 linear
          float64 x
          float64 y
          float64 z
       geometry_msgs/Vector3 angular
          float64 x
          float64 y
          float64 z
      float64[36] covariance

        return self._odomdata

if __name__ == "__main__":
    rospy.init_node('odom_subscriber', log_level=rospy.INFO)
    odom_reader_object = OdomSub()
    rate = rospy.Rate(0.5)
    #print odom_reader_object.get_msg()
    ctrl_c = False
    def shutdownhook():
        # works better than the rospy.is_shut_down()
        global ctrl_c
        print "shutdown time!"
        ctrl_c = True


    while not ctrl_c:
        data = odom_reader_object.get_odomdata()

Thanks in advanced to anyone who can help me troubleshoot this.

1 Like

Grrr. I figured it out. I forgot to add parenthesis at the end of my get_odomdata() funtion.