Page 1 of 1

Get values omni directional camera in Lua

Posted: Thu Oct 20, 2016 11:06 pm
by emerckx
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

Re: Get values omni directional camera in Lua

Posted: Sat Oct 22, 2016 3:19 pm
by pincy
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

Re: Get values omni directional camera in Lua

Posted: Mon Oct 24, 2016 10:10 pm
by emerckx
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

Re: Get values omni directional camera in Lua

Posted: Mon Oct 24, 2016 10:12 pm
by pincy
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

Re: Get values omni directional camera in Lua

Posted: Mon Oct 24, 2016 10:55 pm
by emerckx
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

Re: Get values omni directional camera in Lua

Posted: Tue Oct 25, 2016 12:23 am
by pincy
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

Re: Get values omni directional camera in Lua

Posted: Tue Oct 25, 2016 10:10 pm
by emerckx
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

Re: Get values omni directional camera in Lua

Posted: Wed Nov 02, 2016 5:41 pm
by pincy
Hello Ewout,

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

Cheers,
Carlo