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



  • A user wrote in with some questions regarding the path following script posted here:

    1) How do I reset the waypointsList within the code? I am trying to create multiple paths within the same run using a while loop and need to reset the waypointsList after creating the path so that it will start fresh waypoints list for the next path.

    Within the context of the PathRecorder sample script, at the end of your while loop just place the previous path that has been recorded and then either create a new array to overwrite the old one, or create a list of arrays if you want to keep all paths for later, or delete all the points from the first array and refill the array with the new path waypoint positions.

    2) How do I place the waypoints after a certain distance instead of time? For example, can I place waypoint for every 1m distance traveled by vehicle?

    There is a property that you can poll called “Driven Distance”, under your vehicle in the properties tab, that tracks the distance traveled in the forward direction. Be aware that it is a bit of a misnomer and the value decreases if you do reverse throttle and travel backwards.

    With that value you should be able to have it place a waypoint per 1 m travelled.

    3) Is there a way to turn off the way points and just show the path in ANVEL GUI?

    You can get the path programmatically and set its world object Opacity property to 0 which will make the waypoint dots invisible and leave the path behind with the color specified in the Path object. Your properties tab should look like the image below with Opacity highlighted with an orange box.

    0_1502912655655_circle.png

    4) When I run the parametric controller, I can see the turn radius and lateral G. Is there a way to write out these values from a python program?

    Using the GetProperty or GetProperties commands from the external API, you can call those two values and graph them through other python libraries. Alternatively you can also right click those two properties in the properties tab and select “Add ‘YourPropHere” to Chart”, which will add these properties to the chart found in the chart tab.


Log in to reply
 

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