jsk-enshu / robot-programming

This is exercise for robot-programming.
38 stars 291 forks source link

AttributeError: 'MoveBaseActionGoal' object has no attribute 'target_pose' が解決できない #396

Closed takepiyo closed 3 years ago

takepiyo commented 3 years ago

第一回の課題2番について質問させていただきたいです。

rosmsg showコマンドやソースコードを確認しても確実にtarget_pose変数が存在するはずなのに上記のエラーが出てしまいます。 どこか見落としていたら教えていただきたいです。

#!/usr/bin/env python

import rospy
import actionlib
from move_base_msgs.msg import MoveBaseAction, MoveBaseActionGoal

if __name__ == "__main__":
    rospy.init_node('my_move_base')
    client = actionlib.SimpleActionClient('move_base', MoveBaseAction)
    client.wait_for_server()

    goal_point = MoveBaseActionGoal()
    goal_point.header.stamp = rospy.Time().now()
    goal_point.goal.target_pose.header.stamp = rospy.Time().now()
    goal_point.goal.target_pose.header.frame_id = "map"
    goal_point.goal.target_pose.pose.position.x = 20.0
    goal_point.goal.target_pose.pose.position.y = 30.0
    goal_point.goal.target_pose.pose.position.z = 0.0
    goal_point.goal.target_pose.pose.orientation.x = 0.0
    goal_point.goal.target_pose.pose.orientation.y = 0.0
    goal_point.goal.target_pose.pose.orientation.z = 0.0
    goal_point.goal.target_pose.pose.orientation.w = 1.0
    print(goal_point)
    client.send_goal(goal_point)
    client.wait_for_result(rospy.Duration.from_sec(10.0))
    result = client.get_result()
    print("result: ", result)

エラー全文

Traceback (most recent call last):
  File "/home/takeshi/catkin_ws/src/beginner_tutorials/scripts/2.py", line 25, in <module>
    client.send_goal(goal_point)
  File "/opt/ros/melodic/lib/python2.7/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/melodic/lib/python2.7/dist-packages/actionlib/action_client.py", line 553, in send_goal
    return self.manager.init_goal(goal, transition_cb, feedback_cb)
  File "/opt/ros/melodic/lib/python2.7/dist-packages/actionlib/action_client.py", line 466, in init_goal
    self.send_goal_fn(action_goal)
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/topics.py", line 882, in publish
    self.impl.publish(data)
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/topics.py", line 1066, in publish
    serialize_message(b, self.seq, message)
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/msg.py", line 152, in serialize_message
    msg.serialize(b)
  File "/opt/ros/melodic/lib/python2.7/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'

よろしくお願いいたします。

k-okada commented 3 years ago

これは,非常に難しんですが,

    client.send_goal(goal_point)

で送るメッセージはMoveBaseGoal であるひつようがあるます,なので,

    goal_point = MoveBaseActionGoal()

の部分は,

    goal_point = MoveBaseGoal()

として,

        goal_point.target_pose.header.frame_id = 'map'
        goal_point.target_pose.pose.position.x=0;

みたいにします.

なんでこうなっているの?というのは仕様だとしか言えませんが,

File "/opt/ros/melodic/lib/python2.7/dist-packages/actionlib/action_client.py", line 553, in send_goal
    return self.manager.init_goal(goal, transition_cb, feedback_cb)

がヒントで,rosmsg show で確かに,goal_point = MoveBaseActionGoal()goal_point.goal.target_pose は存在しますが,send_goal時に型が違ってエラーになります.

takepiyo commented 3 years ago

修正したら動きました。

そのような仕様なのですね。send_goalのdocumentationを見ていませんでした。

ありがとうございます。