These are the initial line of my rospy code:
if __name__ == "__main__":
rospy.init_node('path_for_control', anonymous=True)
pub = rospy.Publisher('path', Path, queue_size=10)
rate = rospy.Rate(1) # small amount on purpose (20m in 20 sec)
while not rospy.is_shutdown():
Trajectory()
rate.sleep()
This is the launch file in which is being used:
<launch>
<node pkg="pure_pursuit" name="pure_pursuit" type="pure_pursuit" />
<node pkg="pure_pursuit" name="waypoint_publisher" type="control_listpath.py" />
</launch>
And this is the error while launching the launch file using
roslaunch pure_pursuit pure_pursuit.launch
Traceback (most recent call last):
File "/home/krush/SDC/src/pure_pursuit/src/control_listpath.py", line 148, in <module>
pub = rospy.Publisher('path', Path, queue_size=10)
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 842, in __init__
super(Publisher, self).__init__(name, data_class, Registration.PUB)
File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 142, in __init__
raise ValueError("data_class [%s] is not a class"%data_class)
ValueError: data_class [<function Path at 0x7f636ecb6280>] is not a class
Edit:
#! /usr/bin/env python3
import math
import numpy as np
import rospy
from geometry_msgs.msg import PoseStamped
from nav_msgs.msg import Path
def Path():
# path = [(2.0, 0.0), (4.0, 0.0), (6.0, 0.0), (8.0, 0.0), (10.0, 0.0), (13.0, 0.0), (16.0, 1.5), (20.0, 2.5)]
global i
point_X, point_Y = path[i]
i += 1
if i == 8:
i = 0
pitch = 0
roll = 0
carPosX, carPosY = (0.0, 0.0)
track = Path()
track.header.frame_id = "base_link"
track.header.stamp = rospy.Time.now()
# for point_X, point_Y in path:
# yaw = math.atan((point_Y - carPosY)/(point_X - carPosX))
# print(yaw)
dir_vec = np.array([point_X - carPosX, point_Y - carPosY])
axis = np.array([1.0, 0.0])
# #do dot product between them
cos_theta = np.dot(dir_vec, axis) / (np.sqrt((point_X - carPosX) ** 2 + (point_Y - carPosY) ** 2))
yaw = math.acos(_cos_theta)
qx = np.sin(roll/2) * np.cos(pitch/2) * np.cos(yaw/2) - np.cos(roll/2) * np.sin(pitch/2) * np.sin(yaw/2)
qy = np.cos(roll/2) * np.sin(pitch/2) * np.cos(yaw/2) + np.sin(roll/2) * np.cos(pitch/2) * np.sin(yaw/2)
qz = np.cos(roll/2) * np.cos(pitch/2) * np.sin(yaw/2) - np.sin(roll/2) * np.sin(pitch/2) * np.cos(yaw/2)
qw = np.cos(roll/2) * np.cos(pitch/2) * np.cos(yaw/2) + np.sin(roll/2) * np.sin(pitch/2) * np.sin(yaw/2)
pose = PoseStamped()
pose.pose.position.x = point_X
pose.pose.position.y = point_Y
pose.pose.position.z = 0.0
pose.pose.orientation.x = qx
pose.pose.orientation.y = qy
pose.pose.orientation.z = qz
pose.pose.orientation.w = qw
track.poses.append(pose)
pub.publish(track)
carPosX, carPosY = point_X, point_Y
def interm(k=0):
path = [
(2.0, 0.0),
(4.0, 0.0),
(6.0, 0.0),
(8.0, 0.0),
(10.0, 0.0),
(13.0, 0.0),
(16.0, 1.5),
(20.0, 2.5),
]
point_X, point_Y = path[k]
path(point_X, point_Y)
# k = path.index((point_X, point_Y))
print(k)
if k < 8:
k += 1
else:
k = 0
if __name__ == "__main__":
rospy.init_node('path_for_control', anonymous=True)
pub = rospy.Publisher('path', Path, queue_size=10)
# pub = rospy.Publisher('path_segment', PoseStamped, queue_size = 1)
# k = 0
rate = rospy.Rate(1) # small amount on purpose (20m in 20 sec)
while not rospy.is_shutdown():
Path()
rate.sleep()
# rospy.spin()
Originally posted by krushnal on ROS Answers with karma: 5 on 2021-03-09
Post score: 0