Aimsun Next Micro API Example 7:¶
Example of an ANG Connection (Updating an ANG Simulation Vehicle attribute)¶
This example shows how to create a new attribute "VehStatus" (as an integer) in the ANG Simulation Vehicle object and then set a value depending on the section where the vehicle is located (in section 241 the attribute is set to 1 meanwhile in section 250 is set to 2).
C++ Version¶
#include "AKIProxie.h"
#include "CIProxie.h"
#include "ANGConProxie.h"
#include "AAPI.h"
#include <stdio.h>
void * vehStatusAtt;
// Procedures could be modified by the user
int AAPILoad()
{
return 0;
}
int AAPIInit()
{
ANGConnEnableVehiclesInBatch(true);
//getting the attributes by name. A UNICODE conversion is required by using AKIConvertFromAsciiString method
vehStatusAtt = ANGConnCreateAttribute( AKIConvertFromAsciiString("GKSimVehicle"),
AKIConvertFromAsciiString("GKSimVehicle::VehStatusInt"),
AKIConvertFromAsciiString("Vehicle Status"), INTEGER_TYPE, EXTERNAL);
return 0;
}
int AAPISimulationReady()
{
return 0;
}
int AAPIManage(double time, double timeSta, double timeTrans, double acycle)
{
return 0;
}
int AAPIPostManage(double time, double timeSta, double timeTrans, double acycle)
{
int nbvehs, i, idVehANG;
InfVeh infveh;
nbvehs = AKIVehStateGetNbVehiclesSection(241, true);
for (i=0; i< nbvehs; i++) {
infveh = AKIVehStateGetVehicleInfSection(241,i);
if (infveh.report>=0) {
idVehANG = ANGConnVehGetGKSimVehicleId(infveh.idVeh);
if ( idVehANG > 0 ) {
ANGConnSetAttributeValueInt(vehStatusAtt, idVehANG, 1);
}
}
}
nbvehs = AKIVehStateGetNbVehiclesSection(250, true);
for (i=0; i< nbvehs; i++) {
infveh = AKIVehStateGetVehicleInfSection(250,i);
if (infveh.report>=0) {
idVehANG = ANGConnVehGetGKSimVehicleId(infveh.idVeh);
if ( idVehANG > 0 ) {
ANGConnSetAttributeValueInt(vehStatusAtt, idVehANG, 2);
}
}
}
return 0;
}
int AAPIFinish()
{
return 0;
}
int AAPIUnLoad()
{
return 0;
}
Python Version¶
from AAPI import *
def AAPILoad():
return 0
def AAPIInit():
ANGConnEnableVehiclesInBatch(True);
# getting the attributes by name. A UNICODE conversion is required by using AKIConvertFromAsciiString method
global vehStatusAtt
vehStatusAtt = ANGConnCreateAttribute( AKIConvertFromAsciiString("GKSimVehicle"),
AKIConvertFromAsciiString("GKSimVehicle::VehStatusInt"),
AKIConvertFromAsciiString("Vehicle Status"), 1, 2)
return 0
def AAPISimulationReady():
return 0
def AAPIManage(time, timeSta, timeTrans, acycle):
return 0
def AAPIPostManage(time, timeSta, timeTrans, acycle):
nbvehs = AKIVehStateGetNbVehiclesSection(241, True)
for i in range(0, nbvehs):
infveh = AKIVehStateGetVehicleInfSection(241,i)
if infveh.report >= 0 :
idVehANG = ANGConnVehGetGKSimVehicleId(infveh.idVeh)
if idVehANG > 0:
ANGConnSetAttributeValueInt(vehStatusAtt, idVehANG, 1)
nbvehs = AKIVehStateGetNbVehiclesSection(250, True)
for i in range(0, nbvehs):
infveh = AKIVehStateGetVehicleInfSection(250,i)
if infveh.report >= 0:
idVehANG = ANGConnVehGetGKSimVehicleId(infveh.idVeh)
if idVehANG > 0:
ANGConnSetAttributeValueInt(vehStatusAtt, idVehANG, 2)
return 0
def AAPIFinish():
return 0
def AAPIUnLoad():
return 0