Creating a path in Python with the API


  • administrators

    An ANVEL user asked:

    Is there a simple non-GUI way to create a path using waypoints? For example, I want to create a circular path using 120 points. Creating this graphically is not going to be accurate. I could go and manually edit the ASCII file but that is going to be tedious. Is there a way the path can be written out in Tabular Form for easy editing?"

    We spent some time constructing two simple Python scripts, which make use of the ANVEL API:

    0_1496768946074_PathConstructor.py
    This file will create a circle (with 120 points and a radius of 10 meters by default). Other shapes are available for creation based on parametric controller maneuvers.

    0_1496769354678_PathConstructor_circle_aerial.png
    0_1496769493497_PathConstructor_all_frame.png

    0_1496768953750_PathRecorder.py
    This file allows users to record new paths, based on vehicle position. This is very similar to how vehicle position replays work, but will result in a path object using the API.

    0_1496769395480_PathRecorder_circle.png



  • Thanks for the examples!



  • I append the following code to the PathRecorder.py and expect the vehicle is controlled to follow the path created:

    anv.SetVehicleInput(keyId, VehicleInputRecord(steering=0, throttle=1, brake=0))
    pathDesc=anv.EnumerateObjectsByType('PathObject')
    pathkeys=anv.GetObjectKeys(pathDesc)
    for k in pathkeys:
    pathkey= k

    anv.FollowPathVehicle(keyId, pathkey, 1.0)
    if (anv.GetSimulationState() == SimulationState.PAUSED):
    anv.SetSimulationState(SimulationState.RUNNING_REALTIME)
    timeVar = 0
    while (anv.GetSimulationState() != SimulationState.PAUSED):
    time.sleep(.25) #Can change this to how often you want a waypoint placed
    timeVar = timeVar + .25
    #waypointList.append(anv.GetPoseAbs(keyId).pos)
    if timeVar == 15.0:
    break

    However, the vehicle moves along a much smaller circular curve and stops unexpectedly earlier.

    I am new to ANVEL/Python and believe I missed something. Could anyone shed some light on my code?

    Peilin



  • The problem is fixed by setting the vehicle in the initial position and orientation by calling

    anv.SetPoseRelE(...)



  • @peilin said in Creating a path in Python with the API:

    I append the following code to the PathRecorder.py and expect the vehicle is controlled to follow >the path created:

    anv.SetVehicleInput(keyId, VehicleInputRecord(steering=0, throttle=1, brake=0))
    pathDesc=anv.EnumerateObjectsByType('PathObject')
    pathkeys=anv.GetObjectKeys(pathDesc)
    for k in pathkeys:
    pathkey= k

    anv.FollowPathVehicle(keyId, pathkey, 1.0)
    if (anv.GetSimulationState() == SimulationState.PAUSED):
    anv.SetSimulationState(SimulationState.RUNNING_REALTIME)
    timeVar = 0
    while (anv.GetSimulationState() != SimulationState.PAUSED):
    time.sleep(.25) #Can change this to how often you want a waypoint placed
    timeVar = timeVar + .25
    #waypointList.append(anv.GetPoseAbs(keyId).pos)
    if timeVar == 15.0:
    break

    However, the vehicle moves along a much smaller circular curve and stops unexpectedly earlier.

    I am new to ANVEL/Python and believe I missed something. Could anyone shed some light on my >code?

    Peilin

    Glad you were able to fix your issue. However, I noticed one small thing that I wanted to double check that you were aware of. You currently have the third parameter in the FollowPathVehicle set to 1.0, and I wanted to clarify that that parameter is speed in meters per second. It is not like the throttle value in SetVehicleInput where it is between -1.0 and 1.0.



  • @ANVEL-Team Yes, I noticed the difference.

    What I trying to do is to, eventually, duplicate the test of UGV (unmanned ground vehicle) in ANVEL. In the test, the throttle and steering are used. Is there any way for me to duplicate the test in the path-following mode with those two parameters?



  • ANVEL has a Replay feature that gathers data from sensors, vehicles, or ambient objects during a simulation so it can be viewed and replayed.

    https://wiki.anvelsim.com/index.php/Replays


Log in to reply
 

Looks like your connection to ANVEL Forum was lost, please wait while we try to reconnect.