Here a small presentation that I have prepared for our students so that they can learn how to program modular snake robots.
Presentation: Programming Modular Robots
Here a simple example.
// Copyright Filippo Sanfilippo #include <SoftwareServo.h> #include <math.h> SoftwareServo servo1; SoftwareServo servo2; float position_angle1; float position_angle2; float amplitude=280; float period=1000; float phase1=0; float phase2=120; float offset=0; //unsigned long time=0; void setup() { pinMode(13,OUTPUT); // This function sets a servo position to the maximum (or 180 degrees position). servo1.attach(10); servo1.setMaximumPulse(2200); servo2.attach(11); servo2.setMaximumPulse(2200); Serial.begin(9600); } void loop() { position_angle1=amplitude*sin(2*PI*millis()/period+phase1)+offset; servo1.write(position_angle1); position_angle2=amplitude*sin(2*PI*millis()/period+phase2)+offset; servo2.write(position_angle2); SoftwareServo::refresh(); }
Here is a more advanced example with TimedActions (multi-threading).
// Copyright Filippo Sanfilippo #include <TimedAction.h> #include <SoftwareServo.h> #include <math.h> TimedAction thread1Action=TimedAction(100, thread1); TimedAction thread2Action=TimedAction(100, thread2); SoftwareServo servo1; SoftwareServo servo2; float position_angle1; float position_angle2; float amplitude=280; float period=1000; float phase1=0; float phase2=120; float offset=0; //unsigned long time=0; void setup() { pinMode(13,OUTPUT); // This function sets a servo position to the maximum (or 180 degrees position). servo1.attach(10); servo1.setMaximumPulse(2200); servo2.attach(11); servo2.setMaximumPulse(2200); Serial.begin(9600); } void loop() { thread1Action.check(); thread2Action.check(); SoftwareServo::refresh(); } void thread1(){ position_angle1=amplitude*sin(2*PI*millis()/period+phase1)+offset; servo1.write(position_angle1); } void thread2(){ position_angle2=amplitude*sin(2*PI*millis()/period+phase2)+offset; servo2.write(position_angle2); }
Other related papers to modular robots are listed in the following.
Filippo Sanfilippo, Houxiang Zhang, Kristin Ytterstad Pettersen, Gionata Salvietti and Domenico Prattichizzo. ModGrasp: an Open-Source Rapid-Prototyping Framework for Designing Low-Cost Sensorised Modular Hands. In Proceeding of the 5th IEEE RAS & EMBS International Conference on Biomedical Robotics and Biomechatronics (BioRob), São Paulo, Brazil. 2014, 951–957.
Filippo Sanfilippo, Gionata Salvietti, Houxiang Zhang, Hans Petter Hildre and Domenico Prattichizzo. Efficient modular grasping: An iterative approach. In Proceedings of the 4th IEEE RAS & EMBS International Conference on Biomedical Robotics and Biomechatronics (BioRob), Rome, Italy. 2012, 1281–1286.
Cong Liu, Filippo Sanfilippo, Houxiang Zhang, Hans Petter Hildre, Chang Liu and Shusheng Bi. Locomotion Analysis of a Modular Pentapedal Walking Robot. In Proceedings of the 26th European Conference on Modelling and Simulation (ECMS), Koblenz, Germany. 2012, 441–447.