Hi Parth,
traci.vehicle.getParameter always returns a string you have to cast to float to use it in mathematical expressions:
float(traci.vehicle.getParameter(electricVeh, "device.battery.chargeLevel"))
Please note the complete parameter name above. You might be interested as well in the stationfinder device which reroutes vehicles to charging stations.
Best regards
Mirko
-----Original-Nachricht-----
Betreff: Re: [sumo-user] Error while running SUMO using Python
Datum: 2024-08-08T16:09:33+0200
Von: "Parth Loya" <loya.parth@xxxxxxxxx>
An: "Mirko Barthauer" <m.barthauer@xxxxxxxxxxx>
Hi Mirko,
I am trying to model a scenario where an EV is moving in a loop on a route multiple times. If its charge gets below a certain threshold value, it needs to go to a nearby charging station.
I am implementing it by first checking current charge level:
charge_level = traci.vehicle.getParameter("v_0", "chargeLevel")
But this is giving me charge level in string. When I am doing -
float(traci.vehicle.getParameter("v_0", "chargeLevel")) it is giving me an error message.
Next, based on the charge level, I want to change its route.
current_edge = traci.vehicle.getRoadID("v_0")
current_route = traci.vehicle.getRouteID("v_0")
if current_edge == "B4A4" and current_charge < (threshold_low * max_charge):
traci.vehicle.setRouteID("v_0", "r_1")
traci.vehicle.setChargingStationStop("v_0", "cs_0", duration = time )
if current_edge == "A3A2" and current_charge > (threshold_high * max_charge):
traci.vehicle.setRouteID("v_0", "electric")
Can you please help? "B4A4" is not found.
Do you refer to your previous question about displaying the current charge in the GUI or do you want to read it using TraCI? Please follow the link I gave you if it is about the GUI, otherwise call traci.vehicle.getParameter(vehID, "chargeLevel").
Best regards
Mirko
-----Original-Nachricht-----
Betreff: Re: [sumo-user] Error while running SUMO using Python
Datum: 2024-08-08T14:02:01+0200
Von: "Parth Loya" <loya.parth@xxxxxxxxx>
An: "Mirko Barthauer" <m.barthauer@xxxxxxxxxxx>
I want to find the current charge of the battery of an electric vehicle during simulation run. Can you tell me how to do that?
Hi,
did you check that the sumocfg runs without errors when loaded directly in sumo? If it does, then you miss at least a traci.close() call (see example in documentation).
Best regards
Mirko
-----Original-Nachricht-----
Betreff: [sumo-user] Error while running SUMO using Python
Datum: 2024-08-08T07:35:28+0200
Von: "Parth Loya via sumo-user" <sumo-user@xxxxxxxxxxx>
An: "sumo-user@xxxxxxxxxxx" <sumo-user@xxxxxxxxxxx>
Hi,
I am trying to run SUMO using python code. I am getting the following error -
Error: tcpip::Socket::recvAndCheck @ recv: peer shutdown
Quitting (on error).
Can you suggest why I am getting this error?
--
--
--