Introduction
Sparki has a gripper, useful for grabbing and moving objects.
The gripper is rack and pinion mechanism driven by a stepper motor, the same kind of motor used to move Sparki’s wheels. The stepper motor’s shaft has a pinion attached, which drives a rack. Moving the motor in one direction opens the gripper, while moving the motor in the other direction closes it:
Programming the Gripper
With the mechanics explained, we are now going to program the gripper’s movements.
To move, Sparki needs batteries properly installed, and the power switch on.
These are the basic commands that Sparki’s software provides to control the gripper:
1 2 3 |
sparki.gripperOpen(); // opens the grippers sparki.gripperClose(); // closes the grippers sparki.gripperStop(); // stops the gripper from moving |
There is no sensor to detect if the grippers are open or closed. We will control the gripper movements in small, timed movements. To start, make sure the gripper is not fully opened or fully closed.
To open the grippers, we will run this code. It first tells Sparki to open the grippers, then to wait 1500 milliseconds (1.5 seconds), and then to stop the grippers from moving. The result should be that the grippers are opened:
1 2 3 4 5 6 7 8 9 10 11 12 |
#include <Sparki.h> // include the sparki library void setup() { sparki.gripperOpen(); // open the robot's gripper delay(1500); // for 1.5 seconds (1500 milliseconds) sparki.gripperStop(); } void loop() { } |
On the other hand (or gripper!), to close grippers, we will run this code. It first tells Sparki to open the grippers, then to wait 1500 milliseconds (1.5 seconds), and then to stop the grippers from moving. The result should be that the grippers are opened:
1 2 3 4 5 6 7 8 9 10 11 |
#include <Sparki.h> // include the sparki library void setup() { sparki.gripperClose(); // close the robot's gripper delay(1500); // for 1.5 seconds (1500 milliseconds) sparki.gripperStop(); } void loop() { } |
Now, try making small modifications to the time interval. For example, you can open (or close) it for 2 seconds. Please don’t try big numbers here, since you will reach the gripper’s mechanical limit fast. By making a few little experiments with the intervals of time, you will soon be familiarized with the gripper’s limits.
Finally, you can try the example program included with the SparkiDuino software.
This small program will open and close your Sparki’s gripper in a never-ending loop, opening it for 1 second (1000 milliseconds), closing it for 1 second, then pausing for 1 second:
Please go to the menu File > Examples > Gripper and download the code to your Sparki:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
/******************************************* Basic Gripper test Sparki has two little grippers it can be used to grab objects and drag them around. See what you can grab with them! ********************************************/ #include <Sparki.h>; // include the robot library void setup() { } void loop() { sparki.gripperOpen(); // open the robot's gripper delay(1000); // for 1 second (1000 milliseconds) sparki.gripperClose(); // close the robot's gripper delay(1000); // for 1 second (1000 milliseconds) sparki.gripperStop(); // stop the grippers from moving delay(1000); // for 1 second (1000 milliseconds) } |
Extra Activities
If you want to improve the control of the gripper, you can always use the stepper motor instructions that we have learned before:
1 2 |
sparki.motorRotate(int motor, int direction, int speed); sparki.motorStop(int motor); |
Although these two instructions (motorRotate and motorStop) will allow you to control the gripper’s speed, they aren’t as handy as the standard gripper functions learned in this lesson. But why not to experiment with them too? As a tip, the motor parameter that should be used in order to work with the gripper is MOTOR_GRIPPER.