ilpincy / argos3

A parallel, multi-engine simulator for heterogeneous swarm robotics
http://www.argos-sim.info/
271 stars 121 forks source link

How to dynamically create LEDs detectable by an omnidirectional camera #222

Open Legendorik opened 8 months ago

Legendorik commented 8 months ago

I'm trying to modify the foraging example and spawn light sources at the food positions in loop function to see them with sensors. However, the camera does not recognize the LEDs that have appeared in the arena. I think the problem here is the medium, but I don't know what else I can do.

So, I started with spawning boxes with leds on food points.

void CForagingLoopFunctions::Init(TConfigurationNode &t_node)
{
      .....
      for (UInt32 i = 0; i < unFoodItems; ++i)
      {
         CLEDMedium &cLEDMedium = GetSimulator().GetMedium<CLEDMedium>("leds");
         m_cFoodPos.push_back(
             CVector2(m_pcRNG->Uniform(m_cForagingArenaSideX),
                      m_pcRNG->Uniform(m_cForagingArenaSideY)));

         std::string food_id = "food_" + std::to_string(i);
         CBoxEntity *pcBox = new CBoxEntity(food_id,                                                 // id
                                            CVector3(m_cFoodPos[i].GetX(), m_cFoodPos[i].GetY(), 0), // position
                                            CQuaternion(),                                           // orientation
                                            false,                                                   // movable or not?
                                            CVector3(0.01, 0.01, 0),                                 // size
                                            1);                                                      // mass in kg

         pcBox->AddLED(CVector3(0, 0, 0), // offset
                       CColor::RED);      // color
         // Enable LED management for the box
         pcBox->EnableLEDs(cLEDMedium);
         // Add the box to the simulation
         AddEntity(*pcBox);
      }
      .....
}

This code spawns boxes (invisible due to zero height and small size) and LEDs, but the camera thinks that all 15 LEDs are spawned in the center (shown in the screenshot). изображение From this result, I concluded that the EnableLEDs function was used incorrectly. Although the code was taken from the answers from the Argos forum, I am not sure that the LEDs should be enabled after adding them, not before. So i switched calls

          ...
         // Enable LED management for the box
         pcBox->EnableLEDs(cLEDMedium);
         pcBox->AddLED(CVector3(0, 0, 0), // offset
                       CColor::RED);      // color
         // Add the box to the simulation
         AddEntity(*pcBox);

It has gotten worse, now LEDs are undetectable even in the center. I've tried moving them around and playing with offset, but to no avail.

Camera setup

      <sensors>
      ...
        <colored_blob_omnidirectional_camera implementation="rot_z_only" medium="leds" show_rays="true" />
      </sensors>

Media setup

  <media>
    <range_and_bearing id="rab" />
    <led id="leds" />
  </media>

I also tried to spawn just light sources without boxes, but they are still undetectable by camera

         auto pFoodLight = new CLightEntity(food_id, CVector3(m_cFoodPos[i].GetX(), m_cFoodPos[i].GetY(), 0), CColor::BLUE, 3);
         pFoodLight->SetMedium(cLEDMedium);
         pFoodLight->SetEnabled(true);

         AddEntity(*pFoodLight);

Please, tell me what's wrong

Legendorik commented 8 months ago

I accidentally solved the problem by duplicating the pcBox->EnableLEDs(cLEDMedium) call.

         // Enable LED management for the box
         pcBox->EnableLEDs(cLEDMedium);
         pcBox->AddLED(CVector3(0, 0, 0), // offset
                       CColor::RED);      // color
         pcBox->EnableLEDs(cLEDMedium);
         // Add the box to the simulation
         AddEntity(*pcBox);

I don't know why this works, but if this is a planned behavior, it should be mentioned in the documentation. At the moment the description of the addLED function says "Adds an LED to this entity. For the LEDs to be updated correctly, you must first call CBoxEntity::EnableLEDs().", but it doesn't work on my example described above