Hi Ifezue,

my proposoal for a state machine is to use enums (see https://docs.python.org/3/library/enum.html).

In the beginning you should write something like

from enum import Enum

class VehicleStatus(Enum):
  running = 0
  goingToCharge = 1
  charging = 2

vehicles = ["0", "1", "2", "3", "4", "5", "6", "7"]
# have a dictionary of vehicles and their states, initially all running
vehicleStatus = {}
for v in vehicles:
  vehicleStatus[v] = VehicleStatus.running

At certain places change the status like this (e.g. after sending a vehicle to the charging station)

                        vehicleStatus[e] = VehicleStatus.goingToCharge

you can query the status like this

                if vehicleStatus[e] == VehicleStatus.charging:

One general remark

You should use very small try except blocks and print an error message in the exception part. This helps you to identify errors and solve them one by one. Here is an example

                    try:
                        traci.vehicle.replaceStop(e, 0, "chargingStation_-7855681#1_0_0", duration=100, flags=32) #chargingStation_-7855681#1_0_0
                        vehicleStatus[e] = VehicleStatus.goingToCharge
                    except Exception as ex:
                        print('Cannot set new stop for vehicle %s (%s)' % (e, str(ex)))

Regards Harald

Am 27.10.21 um 02:54 schrieb Ifezue Obiako:
Just checking but are you asking me to essentially build a state machine in Python, I am just trying to understand what seems to be missing in my code. If so, how do you go about building states in Python as a beginner? Any tips?

On Tue, Oct 26, 2021, 3:29 PM Ifezue Obiako <[email protected]> wrote:

    Harald

    I am a little confused. Is the 'for loop' the issue and I need to
    make refuel commands for each of the simulated vehicles? Or are
    you saying that I need to leave the 'for loop' and make a
    'running', 'goingToCharge', 'Charging' function in Python with TraCI?

    On Tue, Oct 26, 2021 at 1:01 PM Harald Schaefer
    <[email protected]> wrote:

        Hi Ifezue,

        you should put the traci call at line 65 (actualFuelLevel =
        traci.vehicle.getParameter(e,
        "device.battery.actualBatteryCapacity") ) also in a try block,
        because at about 28000 secs Vehicle 0 disappears

        You should issue the rerouting command only once. Create a
        state for each vehicle ('running', 'goingToCharge',
        'Charging'). Send cars only to Charging if they are in state
        running, then put them in state 'goingToCharge' etc,

        Regards, Harald

        Am 26.10.21 um 16:35 schrieb vincentobiako:

        Thanks for the response Harald. The arguments I used for the
        Python script look something like this:

        *python compute-pass-per-vehicle-with-sumo_3b.py -f 3600 -l
        60000 -v 0 1 2 3 4 5 6 7 -g True -- -c test.sumocfg*

        **

        *-f 3600*

        *-l 60000*

        *-v 0 1 2 3 4 5 6 7 *

        *-g True*

        *--*

        *-c test.sumocfg*

        I ran the scenario in the sumo gui rather than in sumo to see
        how some of the vehicles in the simulation were behaving
        based on the commands in the Python script. That may be why
        the vehicles are teleporting when you run it in plain sumo as
        opposed to giving you a fatal error (as seen when you run in
        sumo gui).

        Sent from Mail
        <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows

        *From: *Harald Schaefer <mailto:[email protected]>
        *Sent: *Tuesday, October 26, 2021 8:30 AM
        *To: *[email protected]
        *Subject: *Re: [sumo-user] Fatal Error during vehicle
        Refueling using TraCI

        Hi Ifezue,

        please provide also the arguments for the python script or
        add a simple run.bat file, which just calls
        compute-pass-per-vehicle-with-sumo_3b.py with the correct
        parameters

        Running a program with traci is always slower than without.

        If I run your scenario with plain sumo, I see that buses 3
        and 4 are teleported:


        Warning: Teleporting *vehicle '3'*; waited too long (wrong
        lane), lane='374986789.109.16_1', time=5435.00.
        Warning: *Vehicle '3'*ends teleporting on edge
        '374986789.138', time 5435.00.
        Warning: Teleporting *vehicle '4'*; waited too long (wrong
        lane), lane='374986789.109.16_1', time=34896.00.
        Warning: *Vehicle '4'*ends teleporting on edge
        '374986789.138', time 34896.00.
        Warning: Teleporting *vehicle '4'*; waited too long (wrong
        lane), lane='374986789.109.16_1', time=53365.00.
        Warning: *Vehicle '4'*ends teleporting on edge
        '374986789.138', time 53365.00.

        If you have still trouble or fatal errors, please provide the
        scenario with the calling parameters, so I can reproduce your
        error.

        Harald

        Am 23.10.21 um 00:57 schrieb vincentobiako:

            Hello Everyone

            I have a simulation with buses that are running on
            multiple routes and when each bus reaches a certain fuel
            capacity and a bus capacity equal to 0, they are required
            to begin the process of refueling by going to a charging
            station. I have been able to get the vehicles to move to
            their recharging station when two conditions are met but
            once they get to the station and begin recharging they
            all seem to get stuck on the same lane or charging
            location and the SUMO gui crashes and I get a Fatal Error
            message in my command prompt.

            I have tried shortening the charging delay and actual
            charging duration that each bus spends in the process of
            refueling or recharging to see if that will prevent the
            Fatal Error from occurring and allow the buses to move on
            to their next bus stop, but I keep getting a Fatal Error
            message. Another thing I noticed when I was doing this is
            that the simulation in the GUI seemed to run
            significantly slower than normal for some reason and I am
            not sure why.

            Does anyone know why I am getting a Fatal Error message
            and how I can get the buses to refuel and then move on
            with rest of their bus routes after they are done
            refueling/recharging? Also, why is my simulation running
            slow when I execute my code in TraCI?

            I have attached my testing files for reference.

            Thank you

            Ifezue

            Sent from Mail
            <https://go.microsoft.com/fwlink/?LinkId=550986> for Windows



            _______________________________________________

            sumo-user mailing list

            [email protected]

        To unsubscribe from this list, 
visithttps://www.eclipse.org/mailman/listinfo/sumo-user


        _______________________________________________
        sumo-user mailing list
        [email protected]
        To unsubscribe from this list, 
visithttps://www.eclipse.org/mailman/listinfo/sumo-user
        _______________________________________________
        sumo-user mailing list
        [email protected]
        To unsubscribe from this list, visit
        https://www.eclipse.org/mailman/listinfo/sumo-user


_______________________________________________
sumo-user mailing list
[email protected]
To unsubscribe from this list, 
visithttps://www.eclipse.org/mailman/listinfo/sumo-user
_______________________________________________
sumo-user mailing list
[email protected]
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/sumo-user

Reply via email to