VisibleSim: Your simulator for Programmable Matter Benoit PIRANDA, André NAZ, Julien BOURGEOIS github.com/claytronics/visiblesim Dagstuhl Seminar,"Algorithmic Foundations of Programmable Matter" (16271) Schloss Dagstuhl - Leibniz-Zentrum für Informatik July 03-08, 2016 1
Recalls on Programmable Matter? • We consider that Matter is composed of micro-robots • They execute the same code. • They can interact with their environment – Sensors – Actuators • They exchange data with their neighbors Goal of the simulator • Schedule events • Visualize colored modules and motions Toy y car car : : 427 427,921 ,921 ca catoms toms 2
VisibleSim: How does it work ? • Choose a geometry of robot – Linked to a lattice and a neighborhood • Associate a behavioral program: the Code-block – Languages: C++, MELD, Java, JavaScript, Python • Place copies of these robots in the lattice • Run all programs – Robots exchange messages – Activate actuators – Get sensor data • VisibleSim – Shows effects of actuators – Schedules events 3
Geometry of robots and lattices • 5 different Robots and 4 different Lattices D Robot name Lattice Hardware Smart Blocks Square 1 cm cubes 4 2D Catoms Hexagonal 1 mm cylinders 6 Blinky Blocks Square Cubic 4 cm cubes 6 Robot Blocks Square Cubic Theoretical 6 3D Catoms Faces Centered Cubic In progress 12
Algorithm by example • We want to write a distributed Code-block that colors robots depending on the distance (network) to the Leader. • We choose to test our algorithm in Robot Blocks modules, and we call this algorithm “ distanceRB ” • Rules: – We decide that the Leader is block with ID = 1 – Initialization: (startup function) • Every module has distance=MAX but the Leader has distance=0 • The leader sends its distance (0) to all its neighbors using BROADCAST(0) messages – When a module receives a BROADCAST(d) message, • If local distance > d+1 – it updates its distance (= d+1) – it sends a message BROADCAST(distance) to all its neighbors but the sender – It changes its color 5
Algorithm by example 0 d+1 d+1 0 0 d Robot #1 distance > d+1 distance:=0; distance := d+1; Change the color d Robot #i (i!=1) distance:=max; distance <= d+1 6
Writing the code-block for VisibleSim • Using a web application in the web site: http://ceram.pu-pm.univ-fcomte.fr:5015/visiblesim/doc/codeblock.php distanceRB.cpp distanceRBCode.h distanceRBCode.cpp Makefile 7
Writing the code-block for VisibleSim • Completing codes (distanceRBCode.h) #ifndef distanceRBCode_H_ #define distanceRBCode_H_ #include "robotBlocksGeneric.h" static const int BROADCAST_MSG_MSG=1001; using namespace RobotBlocks; class DistanceRBCode : public GenericCodeBlock { private: uint16_t distance; public : DistanceRBCode(RobotBlocksBlock *host):GenericCodeBlock(host) {}; ~DistanceRBCode() {}; void startup(); void myBROADCAST_MSGFunc(const MessageOf<uint16_t>*msg, P2PNetworkInterface *sender); #endif /* distanceRBCode_H_ */ 8
Writing the code-block for VisibleSim • Completing codes (distanceRBCode.cpp 1/2) #include "distanceRBCode.h" void DistanceRBCode::startup() { addMessageEventFunc(BROADCAST_MSG_MSG,_myBROADCAST_MSGFunc); console << "start " << module->blockId << "\n"; if (module->blockId==1) { // leader id is 1 distance = 0; sendMessageToAllNeighbors( new MessageOf<uint16_t>(BROADCAST_MSG,0) ,2000,100,0); setColor(RED); } else { distance = UINT16_MAX; setColor(LIGHTGREY); } } 9
Writing the code-block for VisibleSim • Completing codes (distanceRBCode.cpp 2/2) void DistanceRBCode::myBROADCAST_MSGFunc( const MessageOf<uint16_t>*msg, P2PNetworkInterface*sender) { uint16_t d = *msg->getData()+1; if (distance>d) { distance = d; setColor(Colors[distance % 9]); sendMessageToAllNeighbors("Broadcast", new MessageOf<uint16_t>(BROADCAST_MSG, distance), 2000,100, 1,sender); } }; 10
Configuration file • XML description of the scene (config.xml) <world gridSize="5,5,6"> <camera target="25,20,10" directionSpherical="10,20,100" angle="45" near="0.01" far="1000.0"/> <spotlight target="25,25,0" directionSpherical="-35,40,150" angle="30"/> <blockList color="128,128,128" blockSize="10,10,10"> <block position="1,1,1" color="255,255,64"/> <block position="2,1,1" color="255,64,255"/> <block position="1,0,1" color="64,255,255"/> <block position="0,0,1"/> <block position="1,2,1" color="255,153,10"/> <block position="0,1,1"/> <block position="0,2,1"/> <block position="0,1,2"/> </blockList> </world> 11
Examples of execution 12
Adding the ‘tap’ event • When the user hits a module, the module becomes the new leader and sends messages again. • Manage conflicts with previous assets – Memorize current stage • Need to transmit more complex message data – distance – stage number • If a block receives a message (d,s) – If (distance>d+1 || currentStage!=s) • update distance • update currentStage • send distance to neighbors but the sender 13
Writing the code-block for VisibleSim • Completing codes (distanceRBCode.h) class DistanceMessage { public: uint16_t distance; uint8_t stage; DistanceMessage(uint16_t d,uint8_t s):distance(d),stage(s) {}; }; class DistanceRBCode : public GenericCodeBlock { private: uint16_t distance; uint8_t currentStage; public: DistanceRBCode(RobotBlocksBlock *host):GenericCodeBlock(host) {}; ~DistanceRBCode() {}; void startup(); void myBROADCAST_MSGFunc(const MessageOf<DistanceMessage>*msg, P2PNetworkInterface *sender); void onTap(); 14
Writing the code-block for VisibleSim • Completing codes (distanceRBCode.cpp 1/3) void DistanceRBCode::startup() { currentStage = 0; if (module->blockId==1) { // master id is 1 distance = 0; setColor(RED); sendMessageToAllNeighbors("Broadcast", new MessageOf<DistanceMessage> (BROADCAST_MSG,DistanceMessage(0,1)), 200,50,0); } else { distance=UINT16_MAX; setColor(LIGHTGREY); } } 15
Writing the code-block for VisibleSim • Completing codes (distanceRBCode.cpp 2/3) void DistanceRBCode::myBROADCAST_MSGFunc( const MessageOf<DistanceMessage>*msg, P2PNetworkInterface*sender) { DistanceMessage *dm = msg->getData(); uint16_t d = dm->distance+1; uint8_t stage = dm->stage; if (distance>d || stage!=currentStage) { distance = d; currentStage = stage; setColor(Colors[distance % 9]); sendMessageToAllNeighbors("Broadcast", new MessageOf<DistanceMessage> (BROADCAST_MSG,DistanceMessage(distance,stage)), 200,50,1,sender); } }; 16
Writing the code-block for VisibleSim • Completing codes (distanceRBCode.cpp 3/3) void DistanceRBCode::onTap() { distance=0; setColor(RED); currentStage = currentStage+1; sendMessageToAllNeighbors("Broadcast", new MessageOf<DistanceMessage> (BROADCAST_MSG,DistanceMessage(0,currentStage)) ,200,50,0); } 17
Compile and run 18
VisibleSim applications • Reconfiguration 19
Online version of VisibleSim • No installation, just sends 2 files – Code-block – and xml config file. http://ceram.pu-pm.univ-fcomte.fr:5015/visiblesim/ 20
Conclusion and future works • Conclusion – VisibleSim is a 3D simulator for distributed robots in a simulated environments. – Is able to schedule execution of programs in huge set of robots – Deterministic process • Future Works – More robot geometries in the online Version – More physics in VisibleSim • Interaction with gravity • Collision forces and sensors 21
Recommend
More recommend