Clarification on the operation of the ambient light sensor and distance from it

Requests regarding how to set up experiments in ARGoS.
AntonioC
Posts: 48
Joined: Mon Aug 30, 2021 7:02 pm

Clarification on the operation of the ambient light sensor and distance from it

Postby AntonioC » Sat Jan 29, 2022 5:08 pm

I am trying to make the kilobot stop when it is near a light source. I encounter some problems and I have a series of questions.
what is the unit of measurement of the value specified in the <light> tag in the intensity attribute?
I read that the greater the distance of the Kilobot from the light source, the greater the value that the get_ambientlight () function returns. This is right?
Sometimes when the Kilobots are far from the light source they return low values while sometimes when they are close they return high values.
What value should I put on the Kilobots to be able to say that they are close to the light source?

pincy
Site Admin
Posts: 632
Joined: Thu Mar 08, 2012 8:04 pm
Location: Boston, MA
Contact:

Re: Clarification on the operation of the ambient light sensor and distance from it

Postby pincy » Sat Jan 29, 2022 5:49 pm

The answer to all of your questions are in the original Kilobot paper and in the source code. I encourage you read both, they should make everything clear.
what is the unit of measurement of the value specified in the <light> tag in the intensity attribute?
It's an intensity multiplier. See this code for more explanations.
I read that the greater the distance of the Kilobot from the light source, the greater the value that the get_ambientlight () function returns. This is right?
I don't know where you read it, but no – it's a signal that decays with the distance exponentially.
What value should I put on the Kilobots to be able to say that they are close to the light source?
I don't know, it depends on your application and where the light source is located in the environment.
I made ARGoS.

AntonioC
Posts: 48
Joined: Mon Aug 30, 2021 7:02 pm

Re: Clarification on the operation of the ambient light sensor and distance from it

Postby AntonioC » Sat Jan 29, 2022 6:23 pm

I put a high maximum value but still I get strange values.
For example, in this experiment a kilobot stops very far from the light source.

Code: Select all

#include<kilolib.h> #include<stdlib.h> #include<stdio.h> #include<stdbool.h> #define MAXLIGHT 900 #define SAMPLEMAX 300 int randomAngle; int randomForeward; int iter = 0; float ambientLightValue = 0; void ExitKilobot(){ while(true){ set_motors(0, 0); set_color(RGB(3, 3, 3)); delay(60000); } } void setup(){ uint8_t randSeed = rand_hard(); srand(randSeed); } double sampleLight(){ double current_light; int numberSample = 0; int sum = 0; int i; for(i = 0; i < SAMPLEMAX; i++){ int sample = get_ambientlight(); if (sample != -1){ sum = sum + sample; numberSample++; } } printf("Light K%d > %f\n", kilo_uid, (current_light = sum / numberSample)); return current_light = sum / numberSample; } void loop(){ set_color(RGB(3, 0, 0)); spinup_motors(); set_motors(kilo_turn_left, 0); randomAngle = rand() % 39 + 1; randomAngle = randomAngle * 0.2 * 1000; delay(randomAngle); set_color(RGB(0, 3, 0)); spinup_motors(); set_motors(kilo_straight_left, kilo_straight_right); randomForeward = rand() % 12; randomForeward = randomForeward * 0.5 * 1000; delay(randomForeward); set_motors(0, 0); set_color(RGB(3, 0, 3)); delay(1000); ambientLightValue = sampleLight(); if(ambientLightValue >= MAXLIGHT){ ExitKilobot(); } } int main(){ kilo_init(); kilo_start(setup, loop); return 0; }

Code: Select all

<?xml version="1.0" ?> <argos-configuration> <!-- ************************* --> <!-- * General configuration * --> <!-- ************************* --> <framework> <system threads="0" /> <experiment length="0" ticks_per_second="10" random_seed="25" /> </framework> <!-- *************** --> <!-- * Controllers * --> <!-- *************** --> <controllers> <kilobot_controller id="kbc"> <actuators> <differential_steering implementation="default" /> <kilobot_led implementation="default" /> </actuators> <sensors> <kilobot_light implementation="rot_z_only" show_rays="true" /> </sensors> <params behavior="build/examples/behaviors/simple_movement" /> </kilobot_controller> </controllers> <!-- ****************** --> <!-- * Loop functions * --> <!-- ****************** --> <loop_functions library="build/examples/loop_functions/trajectory_loop_functions/libtrajectory_loop_functions" label="trajectory_loop_functions" /> <!-- *********************** --> <!-- * Arena configuration * --> <!-- *********************** --> <arena size = "1, 1, 1" center = "0, 0, 0.5"> <box id = "W0" size = "0.2, 0.05, 0.05" movable = "false"> <body position = "0, 0.3, 0" orientation = "0, 0, 0"/> </box> <box id = "W1" size = "0.05, 0.65, 0.05" movable = "false"> <body position = "0.125, 0, 0" orientation = "0, 0, 0"/> </box> <box id = "W2" size = "0.05, 0.65, 0.05" movable = "false"> <body position = "-0.125, 0, 0" orientation = "0, 0, 0"/> </box> <light id="l0" position="0, -0.4, 0" orientation="0,0,0" color="yellow" intensity="10.0" medium="leds"/> <kilobot id="k1"> <body position="0,0.15,0" orientation="0,0,0" /> <controller config="kbc" />> </kilobot> <kilobot id="k2"> <body position="0.05,0.15,0" orientation="0,0,0" /> <controller config="kbc" />> </kilobot> <kilobot id="k3"> <body position="-0.05,0.15,0" orientation="0,0,0" /> <controller config="kbc" />> </kilobot> <kilobot id="k4"> <body position="0,0.25,0" orientation="0,0,0" /> <controller config="kbc" />> </kilobot> <kilobot id="k5"> <body position="0.05,0.25,0" orientation="0,0,0" /> <controller config="kbc" />> </kilobot> </arena> <!-- ******************* --> <!-- * Physics engines * --> <!-- ******************* --> <physics_engines> <dynamics2d id="dyn2d" /> </physics_engines> <!-- ********* --> <!-- * Media * --> <!-- ********* --> <media> <led id="leds"/> </media> <!-- ****************** --> <!-- * Visualization * --> <!-- ****************** --> <visualization> <!-- This shows how to add customized drawing in the world using the qt user functions. Check 'argos3 -q qt-opengl' for more help. --> <qt-opengl> <user_functions library="build/examples/loop_functions/trajectory_loop_functions/libtrajectory_loop_functions" label="trajectory_qtuser_functions" /> <camera> <placements> <placement index="0" position="0,0,8.14689" look_at="0,0,0" up="1,0,0" lens_focal_length="330"/> </placements> </camera> </qt-opengl> </visualization> </argos-configuration>

pincy
Site Admin
Posts: 632
Joined: Thu Mar 08, 2012 8:04 pm
Location: Boston, MA
Contact:

Re: Clarification on the operation of the ambient light sensor and distance from it

Postby pincy » Sat Jan 29, 2022 8:02 pm

Did you notice the position of the light sensor on the kilobot,, and how that affects the calculation of the readings? Also the position of your light is at height zero, which is unusual.
I made ARGoS.

pincy
Site Admin
Posts: 632
Joined: Thu Mar 08, 2012 8:04 pm
Location: Boston, MA
Contact:

Re: Clarification on the operation of the ambient light sensor and distance from it

Postby pincy » Sat Jan 29, 2022 8:07 pm

In your code, the use of print is not correct. It seems to print a double using the format for an int.

Also the return statement in the same function contains a redundant assignment.
I made ARGoS.

AntonioC
Posts: 48
Joined: Mon Aug 30, 2021 7:02 pm

Re: Clarification on the operation of the ambient light sensor and distance from it

Postby AntonioC » Sun Jan 30, 2022 3:43 pm

I positioned the light source at the same height as the Kilobot (0.03) and I eliminated the function that made 300 samples and I directly used the function for the ambient light. Since the greater the distance, the smaller the value the function returns, then I expect high values when the Kilobot is near the light source. On the other hand, during the experiment I still get strange values. When the kilobot is close, indeed it also enters inside, the function returns a low value to the sphere that represents the light source.


Return to “How to... ?”