Ros Basics Real Robot Project Action Client

Hello, I ask you a question, I am making an actions client in which the actions server is going to be axclient.py. What you have to do is how goal receives the meters that the robot has to do, as a result the list (x,y,z) of its position that values ​​are added every 1 second and as feedback the meters traveled so far. I’m going to pass you the code, the problem I have is when the axclient.py GUI opens, it tells me that no goal, disconnected from server.

#!/usr/bin/env python
# ---------------------IMPORTACION DE MODULOS Y MENSAJES--------------------------
import rospy

import actionlib

from scan_test.msg import OdomRecordAction,OdomRecordGoal, OdomRecordResult, OdomRecordFeedback

from nav_msgs.msg import Odometry

#----------------------DECLARACION DE OBJETOS Y INICIALIZACION DE VARIABLES-----------------

goal = OdomRecordGoal()

odom = Odometry()

feedback = OdomRecordFeedback()

result = OdomRecordResult()

goal.meter = 10.0

feedback.current_total = 0

result.list_of_odoms = []

def callback(msg):
    global list_of_odoms
    result.list_of_odoms.append([msg.pose.pose.position.x, msg.pose.pose.position.y, msg.pose.pose.position.z])

    rospy.sleep(1)

def feedback_callback(msg):
    global current_total
    if msg.pose.pose.position.x not in result.list_of_odoms:
        feedback.current_total += 1
        print('Cantidad de metros recorridos: ', feedback.current_total)
        
rospy.init_node('odometria_robot')

client = actionlib.SimpleActionClient('/my_action', OdomRecordAction)

client.wait_for_server()

rospy.Subscriber('/odom', Odometry, callback)

client.send_goal(goal, feedback_cb=feedback_callback)

rospy.sleep(1)

if feedback.current_total >= goal.meter:
    client.wait_for_result()

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

and I pass them the action message

float32 meter
---
geometry_msgs/Point32[] list_of_odoms
---
float32 current_total

Hi @FranROS99 ,

I am sure that you cannot use axclient.py as “actions server”. You need to have action server programmed and running. You use axclient.py as a action client. It is in the name itself.

ax = action
client = client (gui for action calling)
so, axclient.py => action client gui in python

You must have the action server running and only then you can use axclient.py. Otherwise it will not work.

The code that you have posted is “action client” code, which is clear from the following line:
client = actionlib.SimpleActionClient('/my_action', OdomRecordAction).

Have you written the action server program yet?

Also, it would be better if you use OOP methods for your python program (just making an observation, not enforcing you to do so).

Regards,
Girish

Ah Ok!! . Thank you very much!!.