Giter Club home page Giter Club logo

codingconnected.traci's Introduction

CodingConnected.TraCI

Join the chat at https://gitter.im/mennowo/CodingConnected.TraCI License

Currently, this repository is home to two independent implementations of the TraCI protocol (see http://sumo.dlr.de/wiki/TraCI):

  • TraCI.NET offers an incomplete, though growing implementation of TraCI in C#/.NET. This implementation requires SUMO V1.0.0 (or higher)
  • TraCI.C offers an even partialler implementation of TraCI in native (ANSI) C (for now, this is Windows only)

The implementation in C# is currently (January 2018) being expanded to include the complete TraCI API. Complete implementation will take a while (orientation: end of March 2018). The implementation in C is oriented exclusively on connecting external traffic controllers to SUMO, and therefor covers only a very small portion of the TraCI API.

codingconnected.traci's People

Contributors

caxepok avatar cchadj avatar florianja avatar kamikyit avatar mahbub-iut avatar mennowo avatar zicyair avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

codingconnected.traci's Issues

Step answers with Error on command 0xD4

Hi!
Much appreciate your work on the C# implementation of the interface.

I've recently tried to extend the TraCI.NET lib on subscription but kinda got stuck now.
My goal is to use TraCI# directly within Unity3D to retrieve data from SUMO and manipulate vehicle-movement in Unity.

I forked the repo and created a branch "clean-up". TraCI.NET's readme shows which scripts are modified or extended. Please excuse my amateurish approach - hope there is something to take from.
The readme also shows how I retrieve the data.

With this approach and sumo run with --verbose I get an error after invoking the subscription:
Step #0.20Error: Answered with error to command 0xd4: Wrong position in requestMessage after dispatching command. Expected command length was 21 but 16 Bytes were read.

Response-array's variable is D4 (but should be E4) and response-byte-array is:
FF-00-00-00-72-57-72-6F-6E-67-20-70-6F-73-69-74-69-6F-6E-20-69-6E-20-72-65-71-75-65-73-74-4D-65-73-73-61-67-65-20-61-66-74-65-72-20-64-69-73-70-61-74-63-68-69-6E-67-20-63-6F-6D-6D-61-6E-64-2E-20-45-78-70-65-63-74-65-64-20-63-6F-6D-6D-61-6E-64-20-6C-65-6E-67-74-68-20-77-61-73-20-32-31-20-62-75-74-20-31-36-20-42-79-74-65-73-20-77-65-72-65-20-72-65-61-64-2E

With given information and pseudo-script in the above mentioned branch, it should be possible to reproduce the error. Maybe someone has an idea.

HandleResponse doesn't support Context Subscription.

Hello,
I am currently adding functionality for context subscription and I am having problem making HandleResponse handle both Context and Variable Subscription. In particular I don't understand this piece of code

                trresult.Identifier = response[i + j++];

                if (trresult.Identifier == TraCIConstants.CMD_SIMSTEP && totlength == response.Count() && len + 8 != response.Count())
                {
                    var revSubCount = response.Skip(i + len).Take(4).Reverse().ToArray();
                    var subCount = BitConverter.ToInt32(revSubCount, 0);
                    len += 5;
                    for (int n = 0; n < subCount; n++)
                    {
                        var revSubResponseLength = response.Skip(i + len).Take(4).Reverse().ToArray();
                        var SubResponseLength = BitConverter.ToInt32(revSubResponseLength, 0);
                        len += SubResponseLength;

                    }

                    trresult.Length = --len;
                }

What is len in this context and why do you decrement by one at the end?

I have implemented Context Subscription and it works when changing the above code but I can't support both Context and Variable Subscription.

Any input on how HandleResponse code works would be very helpful.

Thank you,
Tom

P.S I didn't know how I could contact you otherwise.

  • I have made the context subscription following the pattern for the variable subscription (using events). Is there any important guidelines I must follow so I can push my code?

Does not work with SUMO V1.0

Most important:
Following methods are now using double for time instead of int.
traci.simulationStep
traci.vehicle.slowDown
traci.vehicle.changeLane
traci.vehicle.setStop
traci.simulation.getDeltaT
traci.trafficlight.getNextSwitch
traci.trafficlight.getPhaseDuration
traci.trafficlight.setPhaseDuration

Also see: http://sumo.dlr.de/wiki/ChangeLog

Screenshot - known issues

Gui command "screenshot" does not create screenshot as aspected.
But command returns "success"...

Vehicle.Remove is not working

When i trying to remove any vehicle from the simulation by calling
Vehicle.Remove(vehID, TraCIConstants.REMOVE_VAPORIZED);
Sumo throws an error with message:
Error: Answered with error to command 0xc4: Wrong position in requestMessage after dispatching command 196. Expected command length was 11 but 10 Bytes were read.

Is this a known error or maybe I am doing something wrong?

is "GetControlledLinks(str).Content.NumberofSignals;" valid?

getting " InvalidOperationException: Sequence contains no elements " error when trying to call

var linkcount = client.TrafficLight.GetControlledLinks(newjunction.name).Content.NumberOfSignals;

Not my code. It seems to me that possibly the .NumberofSignals is not a defined value.
The original code is trying to return the controlledlinks.length integer value from SUMO, I believe.

Vehicle Command : MoveToXY

Hi,
While using TraCI.NET, I found something wrong with the MoveToXY() function.
I checked the code. Variables ( itemNumber & yPosition ) are not used in this function.
It seems that the function is not completed.

        public TraCIResponse<object> MoveToXY(string id, int itemNumber, string edgeId, int laneIndex, double xPosition, double yPosition, double angle, int keepRoute = -1)
        {
            var tmp = new CompoundObject();
            tmp.Value.Add(new TraCIString() { Value = edgeId });
            tmp.Value.Add(new TraCIInteger() { Value = laneIndex });
            tmp.Value.Add(new TraCIDouble() { Value = xPosition });
            tmp.Value.Add(new TraCIDouble() { Value = angle });
            if (keepRoute == 0 || keepRoute == 1 || keepRoute == 2)
            {
                tmp.Value.Add(new TraCIByte() { Value = (byte)keepRoute });
            }

            return TraCICommandHelper.ExecuteSetCommand<object, CompoundObject>(
                     Client,
                     id,
                     TraCIConstants.CMD_SET_VEHICLE_VARIABLE,
                     TraCIConstants.MOVE_TO_XY,
                     tmp
                     );
        }

Get Vehicle Variable: Unsupported Variable 0x57 specified.

Hello,
From vehicle value retrieval in sumo docs there is no Get Vehicle Command with code 0x57. In your VehicleCommands Class you have
/// <summary> /// Returns the ids of the edges the vehicle's route is made of /// </summary> /// <param name="id"></param> /// <returns></returns> public TraCIResponse<List<string>> GetRoute(string id) { return TraCICommandHelper.ExecuteGetCommand<List<string>>( Client, id, TraCIConstants.CMD_GET_VEHICLE_VARIABLE, TraCIConstants.VAR_ROUTE); }
Where you attempt to to use VAR_ROUTE which is 0x57 as a CMD_GET_VEHICLE_VARIABLE command. The 0x57 is only a set command. You might want to replace VAR_ROUTE with VAR_EDGES which is 0x54. In the sumo docs the python library uses getRoute() using 0x54. I want to add that you have getRoute() implemented as GetEdges() which correctly uses 0x54 but I'd suggest you remove it or deprecate it and use GetRoute() with VAR_EDGES just to be consistent with python conventions.

Thank you.

Edit: You don't actually have GetEdges() in VehicleCommands so you should just Implement GetRoute() command. I mistook it with RouteCommands.GetEdges(). Sorry for the inconvenience.

Duplicates

Something weird happened in this commit ae67cfc

the folder CodingConnected.Traci.NET/CodingConnected.TraCI.NET is now twice there.
one time with CI in TraCI
and one time with ci in Traci

the ci folder does not appear on my pc after fetch & pull.

i want to submit a new pull request and it's telling me that changed each file twice.

Answered with error to command 0x00

Hi, I am using OMNeT++-5.5.1, Veins-5.0, and SUMO-1.2.0. I am trying to stop a vehicle at a parking area through setParkingAreaStop command, but the simulation terminated with the following error:

Error: Answered with error to command 0x00: Wrong position in requestMessage after dispatching command 0. Expected command length was 70 but 2 Bytes were read.

The following is the code of my setParkingAreaStop command:

void TraCICommandInterface::Vehicle::setParkingAreaStop(std::string edgeId, double endPos, uint8_t laneInd,double duration,uint8_t flag){
    uint8_t variableId = CMD_STOP;
    uint8_t variableType = TYPE_COMPOUND;
    uint8_t Edgetype= TYPE_STRING;
    uint8_t Postype= TYPE_DOUBLE;
    uint8_t Lanetype= TYPE_BYTE;
    uint8_t Durtype= TYPE_INTEGER;
    int32_t count = 5;
    TraCIBuffer buf = connection->query(CMD_SET_VEHICLE_VARIABLE, TraCIBuffer() << variableId << nodeId << variableType << count << Edgetype << edgeId << Postype << endPos << Lanetype << laneInd  << Postype << duration << Lanetype << flag);
        ASSERT(buf.eof());
}

How can I solve this problem? please help. Thanks.

Vehicle GetPosition Method not Working.

Hi,
While trying Vehicle.GetPosition() Method, It return "System.ArgumentOutOfRangeException".
I Debug the "TraCIDataConverter Class" and found this method returning "type" 0x01 as Response.
I think it should actual return First 0x0F because this method is of compound type and then 0x01 as for Position2D.

How to retrieve vehicle position in the example for .net

Hi there, really thanks for making this library. I am just starting to learn this and want to retrieve the vehicle position in the example. I have added the VAR_POSITION to subscribed variables, and create output as Console.WriteLine("VAR_POSITION " + (r as TraCIResponse).Content); But when I run it, the output is VAR_POSITIONCodingConnected.TraCI.NET.Types.Position2D. Can you help to point out what is wrong and where shall I edit, please? Thanks so much.

Error or missunderstanding how to subscribe for vehicles

Hello, I'm using your project for visualizing and real time controlling SUMO simulation.
ASP server for controlling simulation(change trafficlights, summone some vehicles and so on) with Unity3D client.
Behind the scene, I'm starting sumo with project with given ip and port.
C:\Program Files (x86)\Eclipse\Sumo\bin\sumo
-c net_bel.sumocfg
--step-length 0.2
--additional-files // some xml files here.
--remote-port 4321

Every 0.2 seconds (same as step length) calling MakeStep.

List<string> _vehicleIds = new List<string>();
float _stepLength = 0.2f;
void Start()
    {
        _client = new TraCIClient();

        _client.TrafficLightSubscription += Client_TrafficLightSubscription;
        _client.VehicleContextSubscription += Client_VehicleContextSubscription;
        var res = _client.Connect("localhost", 4321);

        // That's just for tests. The forsing sumo to make a step is called outside at ASP server.
        InvokeRepeating("MakeSumoStep", 1f, _stepLength);
    }
    void MakeSumoStep()
    {
        _client.Control.SimStep();

        _simulationStep += _stepLengthDecimal;

        var activeIds = _client.Vehicle.GetIdList().Content;
        var newIds = activeIds.Where(id => !_vehicleIds.Contains(id)).ToList();
        var removeIds = _vehicleIds.Where(id => !activeIds.Contains(id)).ToList();

        _vehicleIds.AddRange(newIds);

        foreach (var id in newIds)
            _client.Vehicle.SubscribeContext(id, 0, 1000, TraCIConstants.CMD_GET_VEHICLE_VARIABLE, 1000f, vehicleVariablesToSubscribeTo);

        foreach (var id in removeIds)
            _client.Vehicle.UnsubscribeContext(id, TraCIConstants.CMD_GET_VEHICLE_VARIABLE);
    }

    void Client_VehicleContextSubscription(object sender, ContextSubscriptionEventArgs e)
    {
        var simStep = _simulationStep;

        foreach (var item in e.VariableSubscriptionByObjectId)
        {
            var id = item.Value.ObjectId;
            var angle = item.Value.ResponseByVariableCode[TraCIConstants.VAR_ANGLE].GetContentAs<decimal>();
            var position = item.Value.ResponseByVariableCode[TraCIConstants.VAR_POSITION].GetContentAs<Position2D>();
            var lights = item.Value.ResponseByVariableCode[TraCIConstants.VAR_SIGNALS].GetContentAs<int>();
            var type = item.Value.ResponseByVariableCode[TraCIConstants.VAR_TYPE].GetContentAs<string>();

            // Next there're code for visualizing this vehicle at Unity world, but for the text I'll write Debug.Log
            Debug.Log($"{e.ObjectId} {position.X} {position.Y} {_simulationStep}");
        }
    }

As you can see, I subscribe to VehicleContextSubscription to handle vehicle's move behvaiour, and caching the _vehicleIds of current active vehicles.
On each forsing SUMO simulation step I subscribe (doing _client.Vehicle.SubscribeContext) to new vehilce IDs and unsubscribe to (doing _client.Vehicle.UnsubscribeContext) to removed vehicle IDs.
But, there's a problem that many vehicle datas are duclicated, so my debug logging is writeing many duplicates.
For example, "car1_1 0.1 0.1 0.2" was written like 4 times. And this is repeated constantly.

Error while trying to use SetOrder() for multiple Clients

I was trying to use .net version of TracI to control a sumo simulation from multiple clients. To do that I needed to set the order from each client using SetOrder(). I'm calling the SetOrder(int m) method just after creating the connection but It's showing me an error
"Error: Answered with error to command 0x00: Wrong position in requestMessage after dispatching command 0. Expected command length was 6 but 2 Bytes were read. ". I'm still pretty new to Sumo and yet to figure out what went wrong actually.

Lane.GetLinks | InvalidOperationException: Sequence contains no elements

When calling client.Lane.GetLinks(someLaneID), I get the following error:

InvalidOperationException: Sequence contains no elements
System.Linq.Enumerable.First[TSource] (System.Collections.Generic.IEnumerable`1[T] source) (at <351e49e2a5bf4fd6beabb458ce2255f3>:0)
CodingConnected.TraCI.NET.Helpers.TraCIDataConverter.GetValueFromTypeAndArray (System.Byte type, System.Collections.Generic.IEnumerable`1[T] array, System.Object& Object) (at Assets/Scripts/Simulation/CodingConnected.TraCI.NET/Helpers/TraCIDataConverter.cs:781)
CodingConnected.TraCI.NET.Helpers.TraCIDataConverter.ExtractDataFromResponse[T] (CodingConnected.TraCI.NET.TraCIResult[] response, System.Byte commandType, System.Byte messageType) (at Assets/Scripts/Simulation/CodingConnected.TraCI.NET/Helpers/TraCIDataConverter.cs:47)
CodingConnected.TraCI.NET.Helpers.TraCICommandHelper.ExecuteGetCommand[T] (CodingConnected.TraCI.NET.TraCIClient client, System.String id, System.Byte commandType, System.Byte messageType) (at Assets/Scripts/Simulation/CodingConnected.TraCI.NET/Helpers/TraCICommandHelper.cs:121)
CodingConnected.TraCI.NET.Commands.LaneCommands.GetLinks (System.String id) (at Assets/Scripts/Simulation/CodingConnected.TraCI.NET/Commands/LaneCommands.cs:83)
SumoClientClass.MainLoop () (at Assets/Scripts/SumoClient/SumoClientClass.cs:93)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.