publishing in odometry,airsim
i connected airsim with turtlebot using API.Now i need to publish into the odometry of turtlebot.I tried the below code but the turtlebot is not moving.What could be the issue?
!/usr/bin/env python
import airsim import rospy from nav_msgs.msg import Odometry import cv2 #conda install opencv import time
rospy.init_node('s_shapes',anonymous= True) pub = rospy.Publisher('odom',Odometry,queue_size= 2) rate=rospy.Rate(2) sshape= Odometry()
connect to the AirSim simulator
client = airsim.CarClient() client.confirmConnection() car_controls = airsim.CarControls()
start = time.time()
print("Time,Speed,Gear,PX,PY,PZ,OW,OX,OY,OZ")
monitor car state while you drive it manually.
while (cv2.waitKey(1) & 0xFF) == 0xFF: # get state of the car car_state = client.getCarState() pos = car_state.kinematics_estimated.position orientation = car_state.kinematics_estimated.orientation linvel = car_state.kinematics_estimated.linear_velocity angvel = car_state.kinematics_estimated.angular_velocity milliseconds = (time.time() - start) * 1000
sshape.twist.twist.linear.x = linvel.x_val
sshape.twist.twist.linear.y = linvel.y_val
sshape.twist.twist.linear.z = linvel.z_val
sshape.twist.twist.angular.x = angvel.x_val
sshape.twist.twist.angular.y = angvel.y_val
sshape.twist.twist.angular.z = angvel.z_val
if not rospy.is_shutdown():
pub.publish(sshape)
time.sleep(0.1)