ScaledFoundations / GRID-Forum

0 stars 0 forks source link

[BUG] Setting the throttle in car does not change CarControls #1

Open LegendaryGene opened 1 month ago

LegendaryGene commented 1 month ago

Describe the bug The throttle and brake are not updated, while the car controls are set using the setCarControls() API. The other parameters, like steering and handbrake, are working and do get updated.

To Reproduce Steps to reproduce the behavior:

  1. Launch a car in the neighborhood scene
  2. Run the default boilerplate code block
  3. Set the throttle and steering using the following code
    import airgen
    import time
    client = airgen_car_0.client
    client.confirmConnection()
    client.enableApiControl(True)
    car_controls = client.getCarControls()
    car_controls.throttle = 0.1
    car_controls.steering = 1.0
    print(car_controls)
    client.setCarControls(car_controls)
    print(client.getCarControls())
    time.sleep(5)
    car_controls.throttle = 0.0
    car_controls.steering = 0.0
    car_controls.brake = 0.0
    client.setCarControls(car_controls)

Expected behavior Using the code above, I expect the car to move ahead full throttle while making a hard left for 5 seconds before stopping.

Metadata

erwincoumans commented 3 weeks ago

I noticed the same, running the Simulation Control script (driving forward for 3 seconds) didn't move the car, while turning did indeed turn the wheels.

image

# control the car
car_controls = airgen.CarControls()
car_controls.throttle=0.5
car_controls.steering=0.0
airgen_car_0.client.setCarControls(car_controls)
print("Going forward...")
time.sleep(3)   # Let car drive a bit
print("Stopping...")
airgen_car_0.client.setCarControls(car_controls)
saihv commented 3 weeks ago

@erwincoumans AirGen wheeled robots have speed controls enabled by default, which works with the function setCarTargetSpeed() (and ignores throttle inputs from setCarControls()). In order to work with CarControls, you will need to run enableCarSpeedControl(False) first. Thanks for pointing this out - the Car Control sample notebook needs an update!

The right way to do move forward and stop using CarControls() would be

airgen_car_0.client.enableCarSpeedControl(False)

# control the car
car_controls = airgen.CarControls()
car_controls.throttle=0.5
car_controls.steering=0.0
airgen_car_0.client.setCarControls(car_controls)
print("Going forward...")
time.sleep(3)   # Let car drive a bit

print("Stopping...")
car_controls.throttle=0.0
airgen_car_0.client.setCarControls(car_controls)