Problem with using Omni-directional camera using LUA in ARGoS Simulator

Requests regarding how to set up experiments in ARGoS.
Waqar731
Posts: 65
Joined: Thu Oct 23, 2014 12:33 pm
Location: Pakistan
Contact:

Problem with using Omni-directional camera using LUA in ARGoS Simulator

Postby Waqar731 » Sun Jun 23, 2019 8:53 am

Hi,
I am trying to get the led colors of nearby robots using omni-directional camera with LUA in ARGoS Simulator. But I am getting the wrong output. Actually my code is given below.

Code: Select all

if robot.id == 2 then for i = 1, #robot.colored_blob_omnidirectional_camera do if robot.colored_blob_omnidirectional_camera[i].color.red then log(robot.id .. "finds red") elseif robot.colored_blob_omnidirectional_camera[i].color.green then log(robot.id .. "finds green") elseif robot.colored_blob_omnidirectional_camera[i].color.blue then log(robot.id .. "finds blue") end end end
I have attached the screenshot of output here. According to above code, robot 2 should display the red messages two times while should display the green message 3 times in below attached output screenshot. But robot 2 only showing red message five times as it can be seen in log section in below image. While I think there is no mistake in above code.

Is there any mistake in above code?

Screenshot from 2019-06-23 13-11-04.png
Screenshot from 2019-06-23 13-11-04.png (99.34 KiB) Viewed 7569 times
Thanks for help!
Waqar Hussain

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

Re: Problem with using Omni-directional camera using LUA in ARGoS Simulator

Postby pincy » Sun Jun 23, 2019 4:52 pm

In Lua, if a variable evaluates to an integer (like in this case), it is always considered true. Check the Lua manual for more information on this.

The code you wrote is very brittle and should be done in a completely different way, but the simplest fix would be to use "if ... red > 0" to obtain the result you want.
I made ARGoS.


Return to “How to... ?”