Servos and Steppers

Session 1


We will be exploring the four motors used to move its wheels, head and gripper. This includes teaching Sparki to shake its head, and write the first letter of your name!

This first session is designed to be finished in about 30–40 minutes.

Sparki has many features that you can use and experiment with. In this article, we will be exploring the four motors used to move its wheels, head and gripper. Let’s get started!


ACTUATING SPARKI

STEPPER. WHEELS. GRIPPER. SERVO.


STEPPER

Sparki has three unipolar stepper motors: two for the wheels, one for the gripper. Steppers are designed to provide precise and predictable movement. Unlike stepper motors, it is hard to tell how much a regular DC motor have turned. Steppers only move forward in a small predictable amount each time they are turned. With each activation, the internal gear inside the stepper turns a little bit to line up straight with that step’s magnetic coil, then it stands still as it continues to be pulled by that step’s coil. Only when that coil is turned off, and the next step’s coil is turned on does it move, otherwise it will not move.

EXPLORE ON YOUR OWN: How exactly does a stepper motor work? What is the difference between a unipolar and a bipolar stepper motor?


WHEELS

The two wheels of Sparki each use an independent stepper motor. You can use the following commands to move Sparki in a certain direction. Sparki will continue to drive towards that direction until a moveStop() or another move command is called.

You can also tell Sparki how much to precisely move with each command. For moveForward(d) and moveBackward(d), d is an integer that represents distance in centimeters. For moveLeft(a) and moveRight(a), ais an integer that represents the angle in degrees.

PROGRAMMING EXERCISE: Attach your pen to make some drawings with Sparki! Program Sparki to write the first letter of your name.

You can also control Sparki’s wheels with lower level instructions. You control each wheel independently and specify each speed. We will explore this on session 4. :)

CODE FOR WHEEL TEST


GRIPPERS

Sparki has a gripper that can grab objects and drag them around. The gripper is also driven by the same kind of motor that drive each wheel. The gripper is a simple mechanism in which the arm has racks that are driven by the pinion attached to the motor’s shaft. Moving the motor in one direction opens the gripper. Moving it in the opposite direction, closes it.

There are no sensors to detect if the gripper is fully closed or opened so be sure not to use big numbers as you might reach the mechanical limit fast and permanently damage your Sparki.

PROGRAMMING EXERCISE: Consider the three functions below. What do they do? What are their similarities and differences? Check by running them on Sparki!

CODE FOR GRIPPER TEST

You can also use lower level motor instructions with the gripper as with the wheel to improve control over it. We will discuss this in session 4.


SERVO

Sparki has a servo motor to move its head around. Servo is another type of motor that can go to the position you tell it to. It can do this because it has a sensor that measures the position of the servo and a chip that uses that information to control the motor. When the chip detects from the position sensor that the position is not where it is supposed to be, it tells the motor to move towards the correct position until it reaches it. Originally, servos are designed only to turn at a specific range and not turn a full 360 degrees. This servo can only turn within the range of 180 degrees.

EXPLORE ON YOUR OWN: What is the difference between steppers and servos?

You tell the chip what position you want it to be by sending a signal, but the Sparki’s code already takes care of this. All you have to do it specify the angle.

Fifty times a second (or every 20 milliseconds), Sparki sends an on-off pulse. The length of this pulse tells the servo what position it should be in. If it is 1 ms, then it is 90 degrees left (-90). If it is 1.5 ms, it is centered (0). If it is 2 ms then it is 90 degrees right (90).

What length of this pulse does Sparki send if the neck has an angle of 45 degrees to the left? How about 30 degrees to the right? If a pulse is sent every 1.75 ms, how many degrees will it turn?

You can use the commands below to control where Sparki is looking at.

PROGRAMMING EXERCISE: Move Sparki’s Head from left to right at 45 degree increments and at one second intervals.

PROGRAMMING EXERCISE: What do you think will happen if I run the function servoNodsNoTest() above on Sparki??

CODE FOR SERVO TEST


SUMMARY

In this session, we explored what steppers and servos are, and how to control Sparki’s wheels, head and gripper. You even wrote a program that can write the first letter of your name! But Sparki can not only move, it can sense its surroundings as well. In the next session, we will be exploring how Sparki can sense light, the darkness of the surface underneath it, and its distance from obstacles.

Like what you read? Give Nanica.io a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.