Page 1 of 1
play music fluently
Posted: Mon Dec 07, 2020 11:08 pm
by InnoBoy
Hello,
I am making a simulation to play music with Lua.
However, when a bot plays music, the simulation stops for as long as the music ends.
Is there a way to run two bots' algorithms in parallel?
For example that bots can play music simultaneously without disturbing the simulation.
Thanks
Re: play music fluently
Posted: Mon Dec 07, 2020 11:12 pm
by pincy
You need to extend the Lua controller to use threads, and run the simulation in real-time mode. ARGoS is not really designed for this use case, though. What should the music accomplish?
Re: play music fluently
Posted: Tue Dec 08, 2020 11:54 am
by InnoBoy
hello,
The aim is to play music when a bot hits an obstacle.
what does real-time mode mean? and what is the difference between this type of execution and normal execution?
thanks
Re: play music fluently
Posted: Tue Dec 08, 2020 1:45 pm
by pincy
ARGoS can run much faster than real-time - 100x times faster or more, depending on the user code. When using the GUI, this means using the "play" button; when not using the GUI, one needs to set a flag in the .argos file.
Can you share your code? There are many aspects of what you're trying to do that I can't grasp. ARGoS is not designed for this, it's not a game engine, but maybe something can be done.
Re: play music fluently
Posted: Tue Dec 08, 2020 5:52 pm
by InnoBoy
When a bot touches an obstacle, it emits a small sound according to the sensor in contact with the obstacle. I use for the moment a system command "play music.mp3".
lua code
Code: Select all
function step()
sensingLeft = robot.proximity[3].value + robot.proximity[4].value + robot.proximity[5].value + robot.proximity[6].value
sensingRight = robot.proximity[22].value+ robot.proximity[21].value + robot.proximity[20].value + robot.proximity[19].value
if( sensingLeft ~= 0 ) then
driveAsCar(25,-15)
elseif( sensingRight ~= 0 ) then
driveAsCar(25,10)
else
driveAsCar(30,0)
end
log("--Proximity Sensors bot 1--")
for i = 1,24 do
log("capteur: " .. i)
log("Value: " .. robot.proximity[i].value)
if robot.proximity[i].value > 0.5 then
if i % 2 == 0 then -- check if sensors is pair
log("play music pair")
os.execute ("play musics/bip.mp3")
else
-- check if sensors is impair sensors
log("play music impair")
os.execute ("play musics/bop.mp3")
end
end
end
end
.argos code
Code: Select all
<framework>
<experiment length="0" ticks_per_second="10" random_seed="100"/>
<system threads="2" method ="balance_length"/>
</framework>
<controllers>
<lua_controller id="lua1"><!-- controller of bot1 -->
<actuators>
<differential_steering implementation="default" />
<leds implementation="default" medium="leds" />
</actuators>
<sensors>
<differential_steering implementation="default" />
<footbot_motor_ground implementation="rot_z_only" />
<footbot_proximity implementation="default" show_rays="true" />
<colored_blob_omnidirectional_camera implementation="rot_z_only" medium="leds" show_rays="true" />
</sensors>
<params script="./algo_bot/lua1.lua"/>
</lua_controller>
</controllers>
Re: play music fluently
Posted: Tue Dec 08, 2020 7:42 pm
by pincy
I see. I think that the easiest way to make this work would be to use threads. There are many Lua packages for threads, like for instance this one:
https://github.com/torch/threads.
Re: play music fluently
Posted: Tue Dec 08, 2020 11:36 pm
by InnoBoy
Thank you for the replies, I'll try it.