Robotics StackExchange | Archived questions

How can i get the robot to move after clicking 2d nav goal on rviz?

Hey guys, i'm trying to implement the ros navigation stack. I am using a Jetson nano Dev kit and a waveshare's Jetracer Ai Kit as my robot(it has 4 wheels without encoders). i am using ros melodic and ubuntu 18.04.

I have been able to successfully set up the robot follow these instructions (https://tutorial.cytron.io/2021/04/16/getting-started-with-robotic-operating-system-ros-and-jetracer-ai-kit/)

using ros package RPLiDAR_S1 and hector slam i was able to create 2D map of an environment.

Now i am trying to implement the ros navigation stack following these instructions https://automaticaddison.com/how-to-set-up-the-ros-navigation-stack-on-a-robot/

i modified the launch file to suit the nodes i have running. I also included save my hector slam map into the launch file.

these are the are the topics being published after launching the file.

user@user-jetracer:~$ rostopic list
/amcl/parameter_descriptions
/amcl/parameter_updates
/amcl_pose
/clicked_point
/cmd_vel
/diagnostics
/goal_2d
/imu/data
/imu/data_raw
/initial_2d
/initialpose
/map
/map_metadata
/move_base/NavfnROS/plan
/move_base/TrajectoryPlannerROS/cost_cloud
/move_base/TrajectoryPlannerROS/global_plan
/move_base/TrajectoryPlannerROS/local_plan
/move_base/TrajectoryPlannerROS/parameter_descriptions
/move_base/TrajectoryPlannerROS/parameter_updates
/move_base/cancel
/move_base/current_goal
/move_base/feedback
/move_base/global_costmap/costmap
/move_base/global_costmap/costmap_updates
/move_base/global_costmap/footprint
/move_base/global_costmap/inflation_layer/parameter_descriptions
/move_base/global_costmap/inflation_layer/parameter_updates
/move_base/global_costmap/obstacle_layer/parameter_descriptions
/move_base/global_costmap/obstacle_layer/parameter_updates
/move_base/global_costmap/parameter_descriptions
/move_base/global_costmap/parameter_updates
/move_base/global_costmap/static_layer/parameter_descriptions
/move_base/global_costmap/static_layer/parameter_updates
/move_base/goal
/move_base/local_costmap/costmap
/move_base/local_costmap/costmap_updates
/move_base/local_costmap/footprint
/move_base/local_costmap/inflation_layer/parameter_descriptions
/move_base/local_costmap/inflation_layer/parameter_updates
/move_base/local_costmap/obstacle_layer/parameter_descriptions
/move_base/local_costmap/obstacle_layer/parameter_updates
/move_base/local_costmap/parameter_descriptions
/move_base/local_costmap/parameter_updates
/move_base/local_costmap/static_layer/parameter_descriptions
/move_base/local_costmap/static_layer/parameter_updates
/move_base/parameter_descriptions
/move_base/parameter_updates
/move_base/recovery_status
/move_base/result
/move_base/status
/move_base_simple/goal
/odom_data_quat
/particlecloud
/robot_pose_ekf/odom_combined
/rosout
/rosout_agg
/scan
/temperature
/tf
/tf_static

on the python code for my robot i try to subcribe to the topic /cmd_vel which i understand is responsible for getting the mobile base to move in a linear and angular direction.

bottom line is on Rviz when i click 2d Nav Goal on the map, my robot doesn;t move. rather i am getting this error.

[INFO] [1663328447.037749]: Throttle: 0.0
[INFO] [1663328447.042918]: Steering: 0.0
[INFO] [1663328447.141553]: Throttle: 0.0
[INFO] [1663328447.144452]: Steering: 0.0
[INFO] [1663328447.191959]: /cmd_vel: x: -0.1
y: 0.0
z: 0.0
[ERROR] [1663328447.221475]: bad callback: <function callback_cmd at 0x7fa28af7b8>
Traceback (most recent call last):
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
    cb(msg)
  File "/home/user/catkin_ws/src/cytron_jetracer/scripts/racecar.py", line 32, in callback_cmd
    car.throttle = cmd.linear
  File "/usr/local/lib/python3.6/dist-packages/traitlets/traitlets.py", line 585, in __set__
    self.set(obj, value)
  File "/usr/local/lib/python3.6/dist-packages/traitlets/traitlets.py", line 559, in set
    new_value = self._validate(obj, value)
  File "/usr/local/lib/python3.6/dist-packages/traitlets/traitlets.py", line 591, in _validate
    value = self.validate(obj, value)
  File "/usr/local/lib/python3.6/dist-packages/traitlets/traitlets.py", line 1976, in validate
    self.error(obj, value)
  File "/usr/local/lib/python3.6/dist-packages/traitlets/traitlets.py", line 625, in error
    raise TraitError(e)
traitlets.traitlets.TraitError: The 'throttle' trait of a NvidiaRacecar instance must be a float, but a value of x: -0.1
y: 0.0
z: 0.0 <class 'geometry_msgs.msg._Vector3.Vector3'> was specified.

this is the python code for my robot.

#!/usr/bin/env python3

import rospy
from jetracer.nvidia_racecar import NvidiaRacecar
from std_msgs.msg import Float64
from nav_msgs.msg import Odometry
from geometry_msgs.msg import Point, Twist, Vector3
from math import atan2


#Initialize car variable and tune settings
car = NvidiaRacecar()
car.steering_gain = 0.65
car.steering_offset = 0
car.throttle_gain = 0.8
car.throttle = 0.0

#Throttle
def callback_throttle(throt):
    car.throttle = throt.data
    rospy.loginfo("Throttle: %s", str(throt.data))

#Steering
def callback_steering(steer):
    car.steering = steer.data
    rospy.loginfo("Steering: %s", str(steer.data))


#Steering
def callback_cmd(cmd):
    rospy.loginfo("/cmd_vel: %s", str(cmd))
    car.throttle = cmd




#Setup node and topics subscription
def racecar():
    rospy.init_node('racecar', anonymous=True)
    rospy.Subscriber("throttle", Float64, callback_throttle)
    rospy.Subscriber("steering", Float64, callback_steering)
    rospy.Subscriber("/cmd_vel", Twist, callback_cmd)


    rospy.spin()

if __name__ == '__main__':
    print("Running racecar.py")
    racecar()

i am not very conversant with ros, i would really appreciate your help thanks in advance.

Asked by PBT on 2022-09-16 08:40:59 UTC

Comments

Answers

Hey there, seems like a issue with your cmd callback. The throttle field of car seems to have a different data type than the cmd vel data type. You need to extract the throttle and steering values from cmd vel and then provide them to respective fields. Directly providing cmd vel to throttle will result in such error.

Asked by tomarRobin on 2022-09-18 19:44:36 UTC

Comments

This is it right here. The car.throttle attribute is a float, but a geometry_msgs.msg._Vector3.Vector3 was given instead. See the error (truncated) message below:

traitlets.traitlets.TraitError: The 'throttle' trait of a NvidiaRacecar instance must be a float, but a value of x: -0.1
y: 0.0
z: 0.0 <class 'geometry_msgs.msg._Vector3.Vector3'> was specified.

Asked by jayess on 2022-09-18 22:05:49 UTC