Repository navigation
Is there any way to enable keyboard control while using the ROS wrapper? (Car mode) #3562
Unanswered
Mohammed Almatar (matar251)
asked this question in
Support Q&A
Replies: 1 comment 3 replies
|
Hi Mohammed Almatar (@matar251), my understanding is that the ROS wrapper uses the C++ APIs to monitor sensors and control the vehicles (through movebyvelocity I think). Since enabling API control automatically disables manual control (atleast on the drone side of things), the more elegant way of doing what you want to do is to modify the wrapper's code and get rid of the bits that perform the motion control leaving only the monitoring sections (AFAIK sensor monitoring doesnt require API control to be enabled). An easier approach is, as you mentioned, to write a python (or C++) program that translates keyboard key-presses to setCarControls calls (for example). Something like: import airsim
import keyboard # using module keyboard (install using pip3 install keyboard)
client = airsim.CarClient()
car_controls = airsim.CarControls()
client.confirmConnection()
client.enableApiControl(True)
while True: # making a loop
try: # used try so that if user pressed other than the given key error will not be shown
if keyboard.is_pressed('w'):
car_controls.throttle = 1
elif keyboard.is_pressed('s'):
car_controls.throttle = -1
else:
car_controls.throttle = 0
if keyboard.is_pressed('d'):
car_controls.steering = 1
elif keyboard.is_pressed('a'):
car_controls.steering = -1
else:
car_controls.steering = 0
if keyboard.is_pressed('space'):
car_controls.brake = 1
else:
car_controls.brake = 0
print(car_controls)
client.setCarControls(car_controls)
except:
break # if user pressed a key other than the given key the loop will breakshould do the trick |
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi, just trying to use the ROS wrapper to monitor vehicle data (speed, position, etc.). But once I enable the ROS wrapper, Control Mode is set to API and I can no longer manually control the car.
I tried to set RemoteControlID = -1 in settings.json but that doesnt seem to work. Is there any way to use ROS just to monitor and not control the vehicle? I've seen some scripts where users (e.g. Ahmed Elsaharti (@ahmed-elsaharti) ) input commands through an API but I want to expand this to steering wheels later.
All reactions