How can i len() the Path.msg from path planing?
The coding bolow get a waypoint from csv that the waypoint was saved time by time. I try to change calling way from get waypoint from csv to get realtime path. I not sure that i try the right way. I want to use pure pursuit for autonomous driving.
def read_waypoints(self):
rospack = rospkg.RosPack()
package_path=rospack.get_path('a_stars_pure_pursuit')
filename=package_path+'/waypoints/waypoints_1.csv'
with open(filename) as f:
path_points = [tuple(line) for line in csv.reader(f)]
self.path_points_x = [float(point[0]) for point in path_points]
self.path_points_y = [float(point[1]) for point in path_points]
self.path_points_w = [float(point[2]) for point in path_points]
#Initialize array of zeros with the same number of entries as the waypoint markers
self.dist_arr= np.zeros(len(self.path_points_y))
I try this :
path_points_x = []
path_points_y = []
path_points_w = []
def read_waypoints(self):
pose = PoseStamped()
for i in len(Path):
self.path_points_x = path_points_x.append([float(Path[i].pose.pose.position.x)])
self.path_points_y = path_points_y.append([float(Path[i].pose.pose.position.y)])
self.path_points_w = path_points_w.append([float(Path[i].pose.pose.orientation.w)])
#Initialize array of zeros with the same number of entries as the waypoint markers
self.dist_arr= np.zeros(len(self.path_points_y))
The error show they cannot len the Path.msg. Can we count the Path.msg?
Asked by JimiaR on 2022-09-10 23:07:41 UTC
Answers
The Path
message is not an array. You should use rosmsg to see the format of the message:
rosmsg info nav_msgs/Path
If your message variable is named Path, you need use code like this:
n = len(Path.poses)
x = Path.poses[i].pose.position.x
Another problem this code has is that it makes no sense to read only 1 field of the orientation. w
is meaningless on its own.
Asked by Mike Scheutzow on 2022-09-12 11:07:22 UTC
Comments