Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why my vehicle don't move? #257

Open
lsm2842035890 opened this issue Mar 25, 2024 · 7 comments
Open

why my vehicle don't move? #257

lsm2842035890 opened this issue Mar 25, 2024 · 7 comments

Comments

@lsm2842035890
Copy link

72{17T04ULZ4NS5)DN ASCP
N`AXXJL@D(5(8SE_$5NQ{2
I loaded the gridsmall map and paved a simple road. I want the vehicle to run according to my trajectory. Why does the vehicle not move?

@ASionville
Copy link
Contributor

ASionville commented Mar 25, 2024

For now I think your "AI" stops with the python script.
You should add time.sleep(x) at the end of script for it to be "alive" for x more seconds and actually move.
You can put it in a while loop for better control.
You can consider using bng.step(n) too if you want, n here is the number of steps to go ahead to if I remember correctly

@lsm2842035890
Copy link
Author

I tried that, but I still can't get the vehicle to move according to my coordinates. Could it be related to the map? The map I loaded is gridsmall, and the road sign information in it is incomplete, making it impossible to move the vehicle.

@ASionville
Copy link
Contributor

If you put the AI in span mode, does it move at all ?

@aivora-beamng
Copy link
Contributor

Hi @lsm2842035890,
the script must be "realistic" (the vehicle AI tries to get the vehicle to the point (x, y, z) in the time t. You may use the ScriptAI Editor to create valid scripts. Also, the looped argument of the road_a road should be set to False, as your road is a straight one.

This code works for me, you can try yourself:

from beamngpy import BeamNGpy, Road, Scenario, Vehicle


def generate_scripts():
    script = [
        {'x': 0, 'y': 300, 'z': 0.1, 't': 0},
        {'x': 0, 'y': 400, 'z': 0.1, 't': 10},
        {'x': 0, 'y': 500, 'z': 0.1, 't': 20},
        {'x': 0, 'y': 600, 'z': 0.1, 't': 30}
    ]
    return script


def set_scripts():
    bng = BeamNGpy('localhost', 64256)
    bng.open()

    scenario = Scenario('smallgrid', 'custom_road_network')

    road_a = Road('track_editor_C_center', rid='center_road', looped=False)
    road_a.add_nodes(
        (0, 300, 0, 6),
        (0, 400, 0, 6),
        (0, 500, 0, 6),
        (0, 600, 0, 6)
    )
    scenario.add_road(road_a)

    vehicle = Vehicle('ego_vehicle', model='etk800')
    scenario.add_vehicle(vehicle, pos=(0, 300, 0), rot_quat=(0, 0, 1, 0))
    positions = [(0, 400, 0), (0, 500, 0), (0, 600, 0)]
    scales = [(1., 1., 1.)] * 3
    ids = ['my_waypoint_1', 'my_waypoint_2', 'my_waypoint_3']
    scenario.add_checkpoints(positions, scales, ids)
    scripts = generate_scripts()
    scenario.make(bng)
    bng.scenario.load(scenario)
    bng.scenario.start()

    vehicle.ai.set_speed(30, 'set')
    vehicle.ai.execute_script(scripts)


set_scripts()
input('Press Enter to exit...')

@lucena564
Copy link

I was with the same point. That function here:
start_recording()
stop_recording()
https://beamngpy.readthedocs.io/en/latest/beamngpy.html#beamngpy.api.vehicle.VehicleApi

It should record that points for us? Have some feacture that can helps with it? Or it is like try and error?

In ai_line.py we have points passed by sin function, like:
image

But if I load that map:

scenario = Scenario('west_coast_usa', 'Loop 1 da Rodovia')

It will load this:

image

I dont have the points to follow, but have someting to get the point at the moment to build it manualy?

Was thinking about run that using:

vehicle.ai.set_mode('disabled') 

@lucena564
Copy link

I got those points here:

script = [{'x': 460.86572265625, 'y': 328.2005615234375, 'z': 119.28526306152344, 't': 10}, {'x': 430.08746337890625, 'y': 301.0779724121094, 'z': 119.33838653564453, 't': 20.0}, {'x': 362.0964050292969, 'y': 250.7567138671875, 'z': 119.33403015136719, 't': 30}]
points = [(460.86572265625, 328.2005615234375, 119.28526306152344), (430.08746337890625, 301.0779724121094, 119.33838653564453), (362.0964050292969, 250.7567138671875, 119.33403015136719)]
sphere_coordinates = [(460.86572265625, 328.2005615234375, 119.28526306152344), (430.08746337890625, 301.0779724121094, 119.33838653564453), (362.0964050292969, 250.7567138671875, 119.33403015136719)]
sphere_radii = [0.0, 0.246201938253052, 0.08550503583141716]
sphere_colors = [(0.0, 0, 0, 0.8), (0.984807753012208, 0, 0, 0.8), (-0.34202014332566866, 0, 0, 0.8)]
scenario = Scenario('west_coast_usa', 'Loop 1 da Rodovia', description='Spanning the map with an advanced IMU sensor')
vehicle = Vehicle('ego_vehicle', model='etk800', license='RED', color='Red')
scenario.add_vehicle(vehicle, pos=(460, 328, 119.28), rot_quat=(0, 0, 0.3826834, 0.9238795))

But looks that AI is not looking collision, just going on to the left wall. Those points have time enough to go across.

image

image

@lucena564
Copy link

lucena564 commented Apr 26, 2024

I dont know if it will help anyone but..

The problem was that I was using the function to get my positions of the car on the street:

vehicle.get_bbox()

It returns:

{'front_bottom_left': [460.85791015625, 328.1919860839844, 119.28421783447266], 'front_bottom_right': [462.30120849609375, 326.7507019042969, 119.31969451904297], 'front_top_left': [460.831298828125, 328.1995544433594, 120.67394256591797], 'front_top_right': [462.27459716796875, 326.7582702636719, 120.70941925048828], 'rear_bottom_left': [464.15704345703125, 331.4969177246094, 119.32947540283203], 'rear_bottom_right': [465.600341796875, 330.0556335449219, 119.36495208740234], 'rear_top_left': [464.13043212890625, 331.5044860839844, 120.71920013427734], 'rear_top_right': [465.57373046875, 330.0632019042969, 120.75467681884766]}

The point is that the grid of the ground is a little bit higher then the grid of the car, so, when I passed the cling=True that makes the car try follow a really deep point (the first ground below the road grid). Looks that:

image

It is possible observe that have a line that going deep in to the ground, it is the second point that the car should go to, was the point of the bug.

To fix that needed use an offset of 0.9 at my node in 'z' position.

node = {
            'x': (points['front_bottom_left'][0] + points['front_bottom_right'][0])/2,
            'y': (points['front_bottom_left'][1] + points['front_bottom_right'][1])/2,
            'z': points['front_bottom_left'][2], # + 0.9,
            't': (current- initialization).total_seconds()
        }

Using that we can get someting like that:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants