Get values omni directional camera in Lua

Requests regarding how to set up experiments in ARGoS.
emerckx
Posts: 15
Joined: Tue Mar 29, 2016 1:37 pm
Location: Belgium
Contact:

Get values omni directional camera in Lua

Postby emerckx » Thu Oct 20, 2016 11:06 pm

Hello all,

I'm coding my foot-bot controller in Lua,
and I'm trying to get the readings from the omnidirectional camera of the foot-bot.

I'm able to get the table (= the readings), but I'm unable to iterate over it.
You can view this in the code below.

Code: Select all

function init() robot.colored_blob_omnidirectional_camera.enable() end function step() -- Here I'm logging the amount of entries in the table -- This shows the value 1 on the screen log(#robot.colored_blob_omnidirectional_camera) -- Here I'm trying to iterate over the entries -- However this doesn't show anything on the screen for i = 0, #robot.colored_blob_omnidirectional_camera do log(i .. " -> " .. robot.colored_blob_omnidirectional_camera[i].value) end end
Do you know what I'm doing wrong?

Sincerely yours,
Ewout Merckx

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

Re: Get values omni directional camera in Lua

Postby pincy » Sat Oct 22, 2016 3:19 pm

Hello Ewout,

The fields of each reading of the camera are called distance, angle, and color. You can see this either by CTRL+click on a robot (this shows you the list of variables and their values) or the actual code that fills this data.

So, your code should be:

Code: Select all

for i = 0, #robot.colored_blob_omnidirectional_camera do log(i .. " -> " .. robot.colored_blob_omnidirectional_camera[i].distance) log(i .. " -> " .. robot.colored_blob_omnidirectional_camera[i].angle) log(i .. " -> " .. robot.colored_blob_omnidirectional_camera[i].color) end
Cheers,
Carlo
I made ARGoS.

emerckx
Posts: 15
Joined: Tue Mar 29, 2016 1:37 pm
Location: Belgium
Contact:

Re: Get values omni directional camera in Lua

Postby emerckx » Mon Oct 24, 2016 10:10 pm

Hello Carlo,

Unfortunately, your solution doesn't work for me.
The output still doesn't appear on the screen.

The version of ARGoS that I'm currently using is 3.0.0-beta41.
Might that be the cause?

Sincerely yours,
Ewout Merckx

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

Re: Get values omni directional camera in Lua

Postby pincy » Mon Oct 24, 2016 10:12 pm

Hello Ewout,

I don't know, the camera has always worked well. What exactly is the output that you get? Can you post the entire script and .argos file?

Cheers,
Carlo
I made ARGoS.

emerckx
Posts: 15
Joined: Tue Mar 29, 2016 1:37 pm
Location: Belgium
Contact:

Re: Get values omni directional camera in Lua

Postby emerckx » Mon Oct 24, 2016 10:55 pm

Hello Carlo,

When copying the example, I noticed that the color value was causing problems.
So it seems partly fixed, however the color still doesn't appear on the screen...

Sincerely yours,
Ewout Merckx
Attachments
footbot_light_camera.zip
(1.51 KiB) Downloaded 533 times

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

Re: Get values omni directional camera in Lua

Postby pincy » Tue Oct 25, 2016 12:23 am

Hello Ewout,

It's because the color is a table itself (the code that fills it is here). The code should in fact be:

Code: Select all

for i = 1, #robot.colored_blob_omnidirectional_camera do log(i .. " -> " .. robot.colored_blob_omnidirectional_camera[i].distance) log(i .. " -> " .. robot.colored_blob_omnidirectional_camera[i].angle) log(i .. " -> " .. robot.colored_blob_omnidirectional_camera[i].color.red .. "," .. robot.colored_blob_omnidirectional_camera[i].color.green .. "," .. robot.colored_blob_omnidirectional_camera[i].color.blue) end
Cheers,
Carlo
I made ARGoS.

emerckx
Posts: 15
Joined: Tue Mar 29, 2016 1:37 pm
Location: Belgium
Contact:

Re: Get values omni directional camera in Lua

Postby emerckx » Tue Oct 25, 2016 10:10 pm

Hello Carlo,

Thank you very much, it works now :D
However, I had to start with i = 1, because robot.colored_blob_omnidirectional_camera[0] doesn't seem to be defined.

Sincerely yours,
Ewout Merckx

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

Re: Get values omni directional camera in Lua

Postby pincy » Wed Nov 02, 2016 5:41 pm

Hello Ewout,

Great! My bad, in Lua arrays start with 1, not with zero ;) I fixed the code above!

Cheers,
Carlo
I made ARGoS.


Return to “How to... ?”