Class 4 · All four motors¶
The two-belt robot draws, but gravity is all that holds the gondola down, so it swings if you go fast and the marker's drag pulls it off its point. Today the bottom two motors join in, each with a spring in its belt, and your drawings move from hand-written moves to a list of points stored in the code.
By the end of class
All four belts hold the gondola, and the robot draws a picture stored as a list of points, faster than it drew in Class 3.
New parts today¶
| Part | What it's for |
|---|---|
| Two more lengths of GT2 belt | Bottom-left and bottom-right motors to the gondola |
| Two small extension springs | One in each bottom belt, between the belt and the gondola |
Why four belts fight each other
The pen's position is two numbers, x and y. Two belts already fix those two numbers: that's why the polargraph works. A third and a fourth belt don't add information; their lengths have to agree exactly with the first two.
They never agree exactly. Belts stretch a little, a step gets skipped, a pulley sits a millimeter off from where you measured. If a bottom belt comes out 1 mm too long, it goes slack and does nothing. If it comes out 1 mm too short, it pulls against the top belts, and belts barely stretch, so the motors fight until one of them skips a step. Now every point after that is off.
Steppers can't feel this. They don't know the tension in their belt; they just count steps.
A spring in each bottom belt solves it. The spring stretches or relaxes by a few millimeters to soak up the error, while still pulling the gondola down and sideways. It doesn't make the bottom belts precise; it makes them forgiving. The top two belts still decide where the pen is. The bottom two hold it steady.
If the bottom belts ever misbehave, unhook them. You still have the Class 3 machine.
Build it¶
- 24 V off. Plug the bottom-left motor into socket Z and the bottom-right into socket A, with the coil pairs you checked in Class 1. Socket A only works if you set its jumpers to D12 and D13 in Class 1.
- Measure H, the vertical distance from the top pulleys' centers down to the bottom pulleys' centers. The bottom-left pulley is at (0, H) and the bottom-right at (W, H) in your coordinates. Check that the bottom pulleys are really in line with the top ones; if not, measure where they actually are.
- Hook a spring to the gondola on each bottom side, and the belt to the other end of the spring. Run each belt around its pulley with a small weight on the tail, as you did on top.
- With the gondola at home, pull each bottom belt until its spring is stretched to about the middle of its range, and clamp the belt there. It should pull, but gently: if the top motors can't hold the gondola anymore, the springs are too strong.
| Motor | Corner | Socket | Step | Dir | Pulley at |
|---|---|---|---|---|---|
| 1 | Top left | X | 2 | 5 | (0, 0) |
| 2 | Top right | Y | 3 | 6 | (W, 0) |
| 3 | Bottom left | Z | 4 | 7 | (0, H) |
| 4 | Bottom right | A | 12 | 13 | (W, H) |
Enable for all four is still pin 8, LOW. The servo stays on pin 9.
Mission 1 · Positive means longer, on all four
Move each bottom motor +800 steps on its own, with the gondola hanging. As on top, positive must let the belt out: the spring relaxes. Fix any motor that goes the wrong way in code.
Done when
For every one of the four motors, a positive move lets its belt out.
Mission 2 · Four-length goTo
Extend goTo(x, y) to work out all four belt lengths and move all four motors together with one MultiStepper. The bottom lengths use the same Pythagoras as the top ones; only the corner changes. The spring's length doesn't appear in your math: your code only ever uses the change in length from home, and the spring is part of the home length. Run your Class 3 drawing (square, circle, initials), then raise the speed.
Done when
The Class 3 drawing comes out as straight and closed as before, at least 1.5 times as fast. During the whole drawing neither spring goes slack or stretches to its limit (watch them), and the pen comes back to the home cross within 3 mm at the end.
Tool: a list of points (arrays of pairs)
An array can hold rows of values instead of single values. Each row is { ..., ... }. Here a melody is stored as rows of {note, length} and played with tone():
const int SPEAKER = 11;
const int melody[][2] = {
{262, 250}, // C, a quarter second
{294, 250}, // D
{330, 500}, // E, longer
{0, 250}, // 0 = a rest
{330, 250},
{262, 500},
};
const int NOTES = sizeof(melody) / sizeof(melody[0]); // number of rows: 6
void setup() {
for (int i = 0; i < NOTES; i++) {
int frequency = melody[i][0];
int duration = melody[i][1];
if (frequency > 0) {
tone(SPEAKER, frequency, duration);
}
delay(duration + 50);
}
}
void loop() {}
melody[i][0]is rowi, first value;melody[i][1]is the second.sizeof(melody) / sizeof(melody[0])counts the rows for you, so you can add notes without changing a number somewhere else.- The rest uses a value that can't be a real note (0) to mean "something different here". A drawing needs the same trick: some way to say "lift the pen before the next point".
- The Uno has only 2 KB of memory for variables. A few hundred points fit; a few thousand don't. Class 5 gets around that.
Mission 3 · A stored drawing
Pick a simple line drawing (a house, a rocket, a logo you're allowed to use) and sketch it on graph paper with coordinates in millimeters. Store it as an array of {x, y} points, with a marker of your choosing for "pen up, then go to the next point". Write the code that walks the list and draws it with lineTo, penUp and penDown.
Done when
A drawing of at least 30 points, with at least two separate pen-down strokes, comes out recognizably on the board. Video in the build log.
If you finish early¶
- Add a scale and an offset to your drawing code, so the same list draws at any size, anywhere on the board.
- Draw the same picture three times on top of itself. Do the lines overlap? That's the real test of whether steps are being lost.
- Find the speed where it starts to skip with four belts, and compare with two.
- Try springs of different strength and note what changes.
Sign-off with Dr. Alvear
- Bottom belts on, with a spring in each, motors on Z and A
- Your group can explain why the springs are there
- Four-length
goTodraws the Class 3 shapes at least 1.5 times faster - A stored drawing of 30+ points with pen lifts
- Build log updated (photo + two sentences)