0

How can I change the veins vehicle icon color according to its function?

In the tictoc 2 example, this was possible by changing @display ("i =, cyan") from your ned file.

campos
  • 153
  • 2
  • 12

1 Answers1

0

Add the following lines at the beginning of your application code:

#define black TraCIColor(0,0,0,0)
#define red TraCIColor(255,0,0,0)
#define green TraCIColor(0,255,0,0)
#define yellow TraCIColor(255,255,0,0)
#define blue TraCIColor(0,0,255,0)
#define violet TraCIColor(255,0,255,0)
#define cyan TraCIColor(0,255,255,0)
#define white TraCIColor(255,255,255,0)

Then, to set the color to green of car with number carId, add to your code the following lines:

self = getParentModule()->getIndex();
traciVehicle = mobility->getVehicleCommandInterface();
if(self==carId) traciVehicle->setColor(green);
osga
  • 56
  • 3
  • Thanks. I will make this configuration and then return to you. – campos Sep 17 '19 at 11:48
  • For avoid errors I put the line #include "veins / modules / mobility / traci / TraCIColor.h" However the following errors are displayed: `self` was not declared in this scope `carId` was not declared in this scope – campos Sep 17 '19 at 13:13
  • Open the application file .h and add: int self. carId is just a numerical identification (integer) of the car you intend to change the color. Every car has a numerical identification that you can know it by printing the respective self value: cout << self << endl; – osga Sep 18 '19 at 14:03
  • Even setting the variable didn't work. is it necessary to define carId too? – campos Sep 18 '19 at 18:57
  • In my case, I was able to solve the problem by copying the default veins image folder to the OMNET ++ images folder. So I defined the line: findHost()->getDisplayString().updateWith("r=16,red;i=node/car,gold");. That way, every time an accident occurs, the crashed car changes color and sends a message. This was the test I did, later I want to define the member car, CH and gateway of a cluster with different colors. – campos Sep 24 '19 at 23:04