Reader small image

You're reading from  Practical Arduino Robotics

Product typeBook
Published inMar 2023
PublisherPackt
ISBN-139781804613177
Edition1st Edition
Tools
Concepts
Right arrow
Author (1)
Lukas Kaul
Lukas Kaul
author image
Lukas Kaul

Lukas Kaul is a robotics Research Scientist, currently working at the Toyota Research Institute in Silicon Valley, where he develops mobile manipulation technologies to support people in their homes and in their workplace. Throughout his career he has worked on projects as diverse as humanoid robots, aerial robots and mobile manipulation systems. A maker at heart, Lukas has been using Arduino technology extensively for more than a decade in countless side-projects, ranging from mapping systems to self-balancing robots. Lukas is passionate about teaching robotics with Arduino to inspire and empower anyone who wants to enter the exciting field of robotics. He holds a PhD degree from the Karlsruhe Institute of Technology, Germany.
Read more about Lukas Kaul

Right arrow

Testing and Debugging with the Arduino IDE

Testing and debugging are essential parts of every development process. Testing becomes more important and more difficult the more complex a robot is. As we have already seen, even a relatively simple Arduino robot consists of several physical subsystems, such as motors, sensors, batteries, the Arduino board itself, and all the wiring in between. The program that runs on your robot also consists of several components, including hardware interfaces, external libraries, and tasks that need to cooperate with one another to efficiently share CPU resources.

It is common for robot builders, especially less experienced ones, to build an entire robot, write the program for it, and then test the hardware and software all at once. It is very unlikely that everything works as expected on the first attempt, and trying to identify the underlying problems can be very difficult and a major source of frustration in this scenario. This approach is sometimes...

Technical requirements

All you need to recreate the examples in this chapter is your Arduino Uno. If you have a logic analyzer on hand, you can use it for this chapter, but it is not required.

Building modular robot hardware

Modularity is the key to enabling efficient testing of subcomponents to avoid the potentially frustrating experience of Big Bang Integration. This is true for hardware and software, and for the hardware it applies to both the mechanical as well as electrical components of your robot.

Mechanical components

Problems with the mechanical subsystems of your robot, such as the wheels with their motors or a gripper mechanism, are typically the easiest to troubleshoot. Issues like too much friction, overheating, or a motor turning in the wrong direction are easy to spot without dedicated tools. In addition, the mechanical components of your robot will usually be quite modular in nature without having to put too much thought into them.

Especially during the development phase of your first robot prototype, it is best to keep all mechanisms as simple as possible to make it easy to spot where a particular problem comes from. Ideally, you have a dedicated...

Writing testable robot programs

Gaining insight into the inner workings of the program that is running on your Arduino with your own senses is even more difficult than debugging the electronic systems of your robot. That is why it is important to design and write your robot programs with testability in mind from the very beginning.

The most important aspect of testability is modularity. This lets you run a smaller program that only contains some parts of the overall program and test these parts independently. In the previous chapters, we have already learned important techniques for modularity—namely, cooperative multitasking and object-oriented programming (OOP). If your program consists of multiple cooperative tasks running at the same time, you can simply disable all but one task to only test this one. And if you have a class that can perform a certain core function, such as the Blinker class we developed in Chapter 6, Understanding Object-Oriented Programming and Creating...

Using the Arduino IDE for testing and debugging

There are several methods of testing the modules of your robot program. If you write a piece of code that can make an LED blink with variable frequency, you can create the desired frequency with a potentiometer and use an LED to see if the blinker code is reacting correctly to the input signal. However, the Arduino IDE provides us with two additional powerful tools for testing and debugging: the Serial Monitor and the Serial Plotter. Although we have used them in previous chapters already, let us take a deeper dive into both and learn how we can use them as very effective tools in our development process.

Using the Serial Monitor as input

The Arduino IDE’s Serial Monitor is a character-based interface to send and receive data to and from a connected Arduino via its Serial interface. So far, we have only used it to receive and display data to show the output of the program that runs on your Arduino. But it can also be used...

Summary

In this chapter, we discussed the importance of component testing and how to design the hardware and software components of your robots with testability in mind. It is crucial to split your systems into modules that can be tested individually before you combine them into a more complex system that can be difficult and frustrating to debug. We further learned how to use the Arduino IDE’s built-in Serial Monitor as a flexible tool during the testing phase of your project, allowing you to input arbitrary values and change any parameter of your program while it is running. Finally, we took a closer look at the Arduino IDE’s immensely useful Serial Plotter and discussed its features. This chapter concludes Part 2, Writing Effective and Reliable Robot Programs for Arduino, of this book, in which we learned a lot about writing effective, high-quality code for Arduino robots. Now that we know the components we can choose for our robot and how to write the code to use...

Further reading

Here are a few additional resources that can help you learn even more about debugging your robot:

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Practical Arduino Robotics
Published in: Mar 2023Publisher: PacktISBN-13: 9781804613177
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Lukas Kaul

Lukas Kaul is a robotics Research Scientist, currently working at the Toyota Research Institute in Silicon Valley, where he develops mobile manipulation technologies to support people in their homes and in their workplace. Throughout his career he has worked on projects as diverse as humanoid robots, aerial robots and mobile manipulation systems. A maker at heart, Lukas has been using Arduino technology extensively for more than a decade in countless side-projects, ranging from mapping systems to self-balancing robots. Lukas is passionate about teaching robotics with Arduino to inspire and empower anyone who wants to enter the exciting field of robotics. He holds a PhD degree from the Karlsruhe Institute of Technology, Germany.
Read more about Lukas Kaul