Skip to content

Instantly share code, notes, and snippets.

@mithi
Created Jun 25, 2015
Embed
What would you like to do?
A program that tests the gripper, servo and wheels of Arcbotic's Sparki robot. For the wheels, the Robot will write the letter M and you can specify its proportions (1, 2, 3, 4, 5)
#include <Sparki.h>
void beepx(int x, int d){
for (int i = 0; i < x; i++){
delay(d);
sparki.beep();
}
}
void writeM(int s){
sparki.moveForward(6*s);
sparki.moveRight(90);
sparki.moveForward(1*s);
sparki.moveRight(45);
sparki.moveForward(2.5*s);
sparki.moveLeft(90);
sparki.moveForward(2.5*s);
sparki.moveRight(45);
sparki.moveForward(1*s);
sparki.moveRight(90);
sparki.moveForward(6*s);
sparki.moveRight(90);
sparki.moveForward(1*s);
sparki.moveRight(90);
sparki.moveForward(4*s);
sparki.moveLeft(135);
sparki.moveForward(2.5*s);
sparki.moveRight(90);
sparki.moveForward(2.5*s);
sparki.moveLeft(135);
sparki.moveForward(4*s);
sparki.moveRight(90);
sparki.moveForward(1*s);
}
void wheelTest(){
beepx(3, 200);
writeM(4);
beepx(3, 200);
}
void servoLeftToRight(int degree, int d){
for (int angle = -90; angle < 90; angle += degree){
sparki.servo(angle);
delay(d);
}
}
void servoRightToLeft(int degree, int d){
for (int angle = 90; angle > -90; angle -= degree){
sparki.servo(angle);
delay(d);
}
}
void servoNodsNo(int xTimes, int d){
for (int x = 0; x < xTimes; x++){
sparki.servo(-90);
delay(d);
sparki.servo(90);
delay(d);
}
}
void servoNodsNoTest(){
for (int interval = 1000; interval > 0; interval -= 200){
servoNodsNo(4, interval);
beepx(1, 200);
}
}
void servoTest(){
servoNodsNoTest();
servoLeftToRight(45, 1000);
servoRightToLeft(45, 1000);
}
void gripperTestA(){
int interval;
for (int cm = 1; cm < 7; cm++){
interval = cm*1000 + 1500;
sparki.gripperOpen(cm);
beepx(1, interval);
sparki.gripperClose(cm);
beepx(1, interval);
}
}
void gripperTestB(){
for (int interval = 1; interval < 7; interval++){
sparki.gripperOpen();
beepx(1, interval*1000);
sparki.gripperStop();
beepx(1, 1500);
sparki.gripperClose(interval*1000);
beepx(1, interval*1000);
sparki.gripperStop();
beepx(1, 1500);
}
}
void gripperTestC(){
for (int interval = 1; interval < 7; interval++){
sparki.gripperOpen();
beepx(1, interval*1000);
sparki.gripperClose(interval*1000);
beepx(1, interval*1000);
}
}
void setup(){
wheelTest();
gripperTestA();
gripperTestB();
gripperTestC();
servoTest();
}
void loop(){
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment