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

State machines

In our introductory example of cooperative multitasking, we chose two tasks that are extremely small and that do the exact same thing each time they are executed. However, tasks can get much more complicated and might require us to execute several different steps each time they are called. In other words, we need to break a big chunk of code up into small pieces. A great way to implement these more complex tasks in the cooperative multitasking framework is by writing them as state machines.

A state machine is a piece of code that keeps track of the state of the task (hence the name). Certain conditions, such as timing checks, can trigger a transition between states, which causes a bit of code to be executed. The LED blink task from the last example can easily be implemented as a state machine. This adds a few lines of code, but it makes it much more readable. In the blink task state machine, the state is the state of the LED, which is either ON or OFF. The transition...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Practical Arduino Robotics
Published in: Mar 2023Publisher: PacktISBN-13: 9781804613177

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