ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

krushnal's profile - activity

2021-09-08 09:23:30 -0500 received badge  Famous Question (source)
2021-08-20 04:53:21 -0500 received badge  Notable Question (source)
2021-08-02 01:24:50 -0500 received badge  Popular Question (source)
2021-07-19 07:02:46 -0500 commented answer vscode: rospy import error

thanks a lot .... that solves it!!!

2021-07-19 07:02:32 -0500 marked best answer vscode: rospy import error

The env I am using is ROS Noetic and VS Code along with Pylance.

  1. launching rospy nodes is working fine
  2. importing rospy gives a squiggle error in VSCode.
  3. Also, python syntax is not being highlighted properly. Along with that, I am also not getting auto-complete options.

I think it should be a configuration issue, but I don't know where and what I have to configure to resolve this. Any help would be appreciated.

2021-07-19 01:52:13 -0500 received badge  Notable Question (source)
2021-07-19 01:52:13 -0500 received badge  Famous Question (source)
2021-07-19 01:51:38 -0500 asked a question vscode: rospy import error

rospy import error The env I am using is ROS Noetic and VS Code along with Pylance. launching rospy nodes is working f

2021-03-10 15:32:29 -0500 commented answer unable to publish Path waypoints for pure pursuit

thanks a lot!!!! that solved the problem.... i changed the Path() function name to something else

2021-03-10 15:31:52 -0500 marked best answer unable to publish Path waypoints for pure pursuit

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 ...
(more)
2021-03-10 15:31:52 -0500 received badge  Scholar (source)
2021-03-10 15:31:52 -0500 received badge  Supporter (source)
2021-03-10 12:32:28 -0500 received badge  Popular Question (source)
2021-03-10 11:30:12 -0500 commented answer unable to publish Path waypoints for pure pursuit

i have added my code as an answer

2021-03-10 11:30:06 -0500 commented answer unable to publish Path waypoints for pure pursuit

i have added my code as an comment

2021-03-10 11:29:39 -0500 answered a question unable to publish Path waypoints for pure pursuit

#! /usr/bin/env python3 import math import numpy as np import rospy from geometry_msgs.msg import PoseStamped from nav

2021-03-10 11:29:39 -0500 received badge  Rapid Responder (source)
2021-03-10 03:31:59 -0500 commented answer unable to publish Path waypoints for pure pursuit

Path is of the type nav_msgs/Path which I have imported at the top using from nav_msgs.msg import Path

2021-03-09 08:19:09 -0500 asked a question unable to publish Path waypoints for pure pursuit

unable to launch rospy file using launch file These are the initial line of my rospy code: if __name__ == "__main__":