Problem with execise 4.4

Hi I wrote the class sendgoalsclass as follow

#! /usr/bin/env python

import rospy

import actionlib

from move_base_msgs.msg import MoveBaseAction, MoveBaseActionGoal, MoveBaseActionFeedback, MoveBaseActionResult

class SendGoalsClient(object):

def __init__(self):

    self.send_goal_client = actionlib.SimpleActionClient(

        "/move_base", MoveBaseAction)

    rospy.loginfo("Waiting for /move_base Action Server")

    self.send_goal_client.wait_for_server()

    rospy.loginfo("connected with /move_base Action Server")

    self.sg = MoveBaseActionGoal()

def feedback_callback(self, feedback):

    rospy.loginfo("I am in feedback_callback function...")

def send(self, msg):

    rospy.loginfo("I am in send function...")

    self.send_goal_client.send_goal(

        msg, feedback_cb=self.feedback_callback)

if name == “main”:

rospy.init_node("send_goals_node")

rospy.loginfo("creating send_goals_node")

send_goals_obj = SendGoalsClient()

send_goals_obj.sg.goal.target_pose.header.frame_id = "map"

while True:

    rospy.loginfo("I am in the while...")

    send_goals_obj.sg.goal.target_pose.pose.position.x = 2

    send_goals_obj.sg.goal.target_pose.pose.position.y = 1

    send_goals_obj.send(send_goals_obj.sg)

    """ 

    send_goals_obj.sg.goal.target_pose.pose.position.x = 4

    send_goals_obj.sg.goal.target_pose.pose.position.y = 2

    send_goals_obj.send(send_goals_obj.sg)

    send_goals_obj.sg.goal.target_pose.pose.position.x = 5

    send_goals_obj.sg.goal.target_pose.pose.position.y = 3

    send_goals_obj.send(send_goals_obj.sg)

    """

rospy.spin()

“”"

user:~$ rosmsg info move_base_msgs/MoveBaseActionGoal

std_msgs/Header header

uint32 seq

time stamp

string frame_id

actionlib_msgs/GoalID goal_id

time stamp

string id

move_base_msgs/MoveBaseGoal goal

geometry_msgs/PoseStamped target_pose

std_msgs/Header header

  uint32 seq

  time stamp

  string frame_id

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

“”"

I execute
launch roslaunch husky_navigation move_base_demo.launch
and after I running rosrun send_goals send_goal_client.py I get this error

user:~$ rosrun send_goals send_goal_client.py
[INFO] [1646573889.597408, 0.000000]: creating send_goals_node
[INFO] [1646573889.613600, 181.635000]: Waiting for /move_base Action Server
[INFO] [1646573889.849724, 181.871000]: connected with /move_base Action Server[INFO] [1646573889.851347, 181.872000]: I am in the while…
[INFO] [1646573889.852715, 181.874000]: I am in send function…Traceback (most recent call last):
File “/home/user/catkin_ws/src/send_goals/src/scripts/send_goal_client.py”, line 37, in
send_goals_obj.send(send_goals_obj.sg)
File “/home/user/catkin_ws/src/send_goals/src/scripts/send_goal_client.py”, line 22, in send
self.send_goal_client.send_goal(
File “/opt/ros/noetic/lib/python3/dist-packages/actionlib/simple_action_client.py”, line 92, in send_goal
self.gh = self.action_client.send_goal(goal, self._handle_transition, self._handle_feedback)
File “/opt/ros/noetic/lib/python3/dist-packages/actionlib/action_client.py”, line 561, in send_goal
return self.manager.init_goal(goal, transition_cb, feedback_cb)
File “/opt/ros/noetic/lib/python3/dist-packages/actionlib/action_client.py”, line 466, in init_goal
self.send_goal_fn(action_goal)
File “/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py”, line 882, in publish
self.impl.publish(data)
File “/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py”, line 1066, in publish
serialize_message(b, self.seq, message)
File “/opt/ros/noetic/lib/python3/dist-packages/rospy/msg.py”, line 152, in serialize_message
msg.serialize(b)
File “/opt/ros/noetic/lib/python3/dist-packages/move_base_msgs/msg/_MoveBaseActionGoal.py”, line 147, in serialize
buff.write(_get_struct_3I().pack(_x.goal.target_pose.header.seq, _x.goal.target_pose.header.stamp.secs, _x.goal.target_pose.header.stamp.nsecs))
AttributeError: ‘MoveBaseActionGoal’ object has no attribute 'target_pose’

I am trying to do the debug but I have not found the error yet
thanks for any suggestions
Salvatore

Hello

I think instead of these:

you should write these:

from move_base_msgs.msg import MoveBaseAction, MoveBaseGoal
self.sg = MoveBaseGoal()

because MoveBaseActionGoal is the type of the topic related to this action, not the message you are using here.

1 Like

Hi hag,
thanks I resoved

This topic was automatically closed after 21 hours. New replies are no longer allowed.