Open MissMeriel opened 1 year ago
Hi, thank you for the report. I can reproduce this bug and we will work on fixing it.
Hi @MissMeriel,
We tested the steering input on a simpler script, and it shows better results. Here's the script we used:
import time
import random
from beamngpy import BeamNGpy, Scenario, Vehicle
from beamngpy.sensors import Electrics
# Initialize BeamNG
bng = BeamNGpy('localhost', 64256)
bng.open()
# Create a scenario and add a vehicle
scenario = Scenario('smallgrid', 'steering_test')
vehicle = Vehicle('ego_vehicle', model='etk800', licence='TEST')
vehicle.attach_sensor('electrics', Electrics())
scenario.add_vehicle(vehicle, pos=(0, 0, 0), rot_quat=(0, 0, 0, 1))
# Load and start the scenario
scenario.make(bng)
bng.load_scenario(scenario)
bng.start_scenario()
# Give the vehicle time to initialize
time.sleep(1)
# Function to apply steering and log results
def apply_steering(steering_cmd, duration=1):
print(f"Applying steering_cmd={steering_cmd}")
vehicle.control(steering=steering_cmd, throttle=0.3, brake=0)
time.sleep(duration)
vehicle.sensors.poll()
sensors = vehicle.sensors
steering_input = sensors['electrics']['steering_input']
print(f"Applied steering_cmd={steering_cmd:.6f}\tsteering_input={steering_input:.6f}")
# Function to apply random steering inputs
def apply_random_steering(num_iterations=10, duration=1):
print("\n--- Starting Random Steering Inputs ---")
for i in range(num_iterations):
steering_cmd = random.uniform(-1.0, 1.0) # Generate a random steering command between -1 and 1
apply_steering(steering_cmd, duration)
print("--- Finished Random Steering Inputs ---\n")
# --- Start of Testing ---
print("\n--- Testing Zero Steering ---")
apply_steering(0.0)
print("\n--- Testing Predefined Steering Commands ---")
steering_commands = [0.5, -0.5, 0.25, -0.25, 1.0, -1.0, 0.0]
for cmd in steering_commands:
apply_steering(cmd)
apply_random_steering(num_iterations=10, duration=1)
print("\n--- Resetting Steering to Zero ---")
apply_steering(0.0)
# --- End of Testing ---
# Stop the simulation and close BeamNG
bng.stop_scenario()
bng.close()
The script outputs the following:
--- Testing Zero Steering ---
Applying steering_cmd=0.0
Applied steering_cmd=0.000000 steering_input=-0.000008
--- Testing Predefined Steering Commands ---
Applying steering_cmd=0.5
Applied steering_cmd=0.500000 steering_input=0.511295
Applying steering_cmd=-0.5
Applied steering_cmd=-0.500000 steering_input=-0.520026
...
--- Resetting Steering to Zero ---
Applying steering_cmd=0.0
Applied steering_cmd=0.000000 steering_input=-0.000317
Let me know if this information helps in further debugging the issue.
Best regards,
Abdul
I've come across an issue while using BeamNG.tech.v0.27.1.0 with BeamNGpy==1.25.1. If I start a new scenario, I have no problem sending new commands to
vehicle.control(throttle, steering, brake)
. But, if I restart the same scenario, I have noticed that the vehicle ignores what is sent by vehicle.control(throttle, steering, brake) and uses the latest inputs from the end of the previous scenario. This seems to only affect steering, and not throttle or brake. I've included a script that reproduces my issue. On the first run, the vehicle's steering input is close to the steering command of 0 that it is given when it is accelerating. On the second through the fifth runs, the vehicle's steering angle is similar to the last steering command it received in the previous run, ignoring the steering command of 0. Perhaps this can be fixed by a call to the game engine or a different order of function calls to restart the scenario? If so, I haven't found it yet.