Discovery · Coding Project 16
Building Your Toolbox
Write it once. Use it in every project you ever make.
Student PIN:
Try It — How Many Copies Do You Have?
Open your projects from 12 onwards, one at a time, and count.
| Project | Has a drive function? | Has a turn function? |
|---|---|---|
| 12 — Teaching Your Robot New Moves | ||
| 13 — Deciding What to Do | ||
| 14 — Seeing Light and Dark | ||
| 15 — Following the Line |
Now find out whether they match
Put the drive functions from two different projects side by side and compare them line for line.
Somewhere along the way you improved one of these — a better number, a cleaner stop. Which project has your best version, and do the others have it?
⚠ Your Good Work Is Trapped
Project 12 fixed the problem of writing the same code twice inside one program. It did nothing about writing it again in the next program.
Right now every improvement you make lives in exactly one project, and the others quietly keep the old broken version.
Your team has four people, each working on a different mission in a different project. One of them finds a much better turn. How does that reach everyone else?
Learn It — Your Own header file
A is a collection of functions kept in a separate file that any program can include.
You have been using one since Project 2. It is the very first line of every program you have ever written:
#include <kipr/wombat.h>That is the KIPR library. You cannot change it — but you can make your own beside it.
Two kinds of include
| Code / part | What it means |
|---|---|
#include <kipr/wombat.h> | Angle brackets mean “a library that came with the system.” The Wombat knows where to find it. |
#include "myLibrary.h" | Quotation marks mean “a file sitting in my own project.” That is the one you are about to write. |
Get the brackets wrong and the goes looking in the wrong place. It is a small detail that causes a confusing error.
What goes in your header file
Your holds everything. Your and your definitions, all in the one .h file.
Include the KIPR Library Inside Your Library
Your functions call motor(), msleep(), analog(). Those come from KIPR — so your .h file needs its own #include <kipr/wombat.h> at the top.
Leave it out and every function inside your library breaks, even though the code looks perfect.
myLibrary.h
#include <kipr/wombat.h>
void drive_forward(int ticks);
void turn_right();
void drive_forward(int ticks)
{
cmpc(0);
while (gmpc(0) < ticks)
{
motor(0, 50);
motor(3, 50);
}
motor(0, 0);
motor(3, 0);
msleep(30);
msleep(500);
}
void turn_right()
{
// Your turn code
}#include <kipr/wombat.h>
#include "myLibrary.h"
int main()
{
drive_forward(4000);
turn_right();
drive_forward(2000);
return 0;
}Look at what main.c became. Two includes and a list of what the robot does. Nothing else.
Making a header file
- On the KIPR Software Suite home screen, click User Preferences and switch on the advanced interface. Without this you will not see the file options.
- In the KISS , select your user folder.
- Under Include File, click + Add File.
- Name it — something short and yours, like your team name.
- Click Create.
Include files are .h files. You may also see an option for source files, which are .c — you do not need those for this.
⚠ Save. Every Time.
Editing a .h file and forgetting to save it is the number one reason a library “does not work.” Your changes are sitting in the editor and the compiler never saw them.
Save the .h, then .
When it will not compile
| Check this | In which file |
|---|---|
| Did I include the KIPR library? | Both main.c and my .h |
| Did I include my own library, with quotation marks? | main.c |
| Does the name in the include exactly match the file name? | main.c |
Did I save the .h file after my last edit? | My .h |
| Is every function’s prototype above its definition? | My .h |
Do It — Move In
Step 1 — Turn on the advanced interface
Software Suite home screen → User Preferences → switch on the advanced interface.
Step 2 — Create your library file
Add an include file and name it. Then put the KIPR include at the top and save it immediately, before you write anything else.
| Question | My answer |
|---|---|
| What did I name my library? | |
What line do I put in main.c to use it? |
Step 3 — Move one function — just one
Pick your drive function. Cut the prototype and the definition out of a project and paste both into your .h file. Save it.
Then add the include to main.c and compile.
One at a Time, Same as Always
Move one function, compile, run it on the robot. If it works, move the next. Moving six at once and finding it broken tells you nothing about which one broke it.
Step 4 — Break it four ways
Each of these is a mistake you will make for real one day. Make it now, on purpose, and write down what the compiler says.
| Break this | What the error said |
|---|---|
Delete #include "myLibrary.h" from main.c | |
Delete the KIPR include from your .h | |
Edit the .h and compile without saving | |
Use <angle brackets> for your own library |
Step 5 — Move the rest
Go through the function list you wrote in Project 12 and move each one across, compiling as you go. For each function, take the best version you have written — not just the first one you find.
| Function | Best version came from | Moved? |
|---|---|---|
Step 6 — Start fresh and pull it in
Make a brand new project. Do not write a single function in it.
#include <kipr/wombat.h>
#include "myLibrary.h"
int main()
{
// Write a short run using only functions from your library
return 0;
}To use your library in a new project, add it under Include File and choose upload a file, then pick your .h.
main.c?Step 7 — Fix it once, watch it spread
Change something in your library — sharpen the turn, adjust the overshoot. Save. Then run two different projects that both include it.
What happened in the project you did not touch?
That Is the Whole Point
One edit, in one place, and every program that includes your library got better at the same instant. That is what a library buys you.
Step 8 — Write the instructions
A library nobody can use is not much good. Put a block at the top of your .h file listing what is in it.
// ============================================
// Team Bulldogs robot library
// Last updated: 12 March
//
// drive_forward(ticks) - drives straight, given distance
// turn_right() - zero radius 90 degrees right
// grab() - arm down, close claw, arm up
// release() - arm down, open claw, back away
// follow_line(ticks) - follows the left edge for a distance
// ============================================
Then hand your library to another team and ask them to write a short program with it — without asking you any questions.
What did they get stuck on? That is the thing your comments should have said.
Step 9 — Back it up
Your library is now the most valuable file your team owns. Download it from the File Menu and keep a copy somewhere off the robot.
Score It — Checkpoint
No mission points this time. What you built is the thing that makes every future run faster to write.
My library
| Question | My answer |
|---|---|
| Library file name | |
| How many functions are in it? | |
| Where is my backup copy? | |
| Who else on my team has a copy? |
Which file?
Say whether each line belongs in your .h file, in main.c, or in both.
| Line | Which file |
|---|---|
#include <kipr/wombat.h> | |
#include "myLibrary.h" | |
void turn_right(); | |
The body of turn_right() | |
int main() |
Can you do it again?
Think about it
The KIPR library was written by people you will never meet, and you have used it in every program since Project 2 without ever seeing inside it. Is that a problem?
Next season the game changes and the field is completely different. Which parts of your library would still be useful, and which would you throw away?
Look at what you have built across sixteen projects. Which one thing made the biggest difference to how your code works — , functions, , or the library?
Next
One project left. Several missions still have a bonus that means nothing more than “now do that again” — and you are going to stop doing it by hand.
In Project 17 — Repeating Without Retyping, you meet the last loop.
KIPR · Botball Explorer — Discovery Projects · © KISS Institute for Practical Robotics 1997–2026
When you are finished, press the button to turn in your work and save a copy.
KIPR · Botball Explorer · Discovery