ZipLine 2024: My first dive in robotics

Our line follower, ZipLine
Our line follower, ZipLine

Introduction

So this October, our team decided to participate in the IITB Techfest Zonals as is tradition. We usually participate in 2 competitions, Cosmoclench & Meshmerize, with 2 teams for each competition.

Cosmoclench is simple at heart: you make an RC bot with a human driver and an arm or gripper capable of picking up a specified object and traversing an obstacle course while carrying it.

In Meshmerize (what I participated in), you make a line follower that can solve line mazes. This is different from making a micromouse, since those solve mazes with physical walls; we are operating with inverted mazes (no walls, just lines).

Not sure how to structure this document as I am writing it in retrospect, but I think I'm just going to start talking and organize the result at the end 👍

This is mostly from my own experience and I'm sure details will be missing in places I wasn't too involved in – especially chassis and electronics and such. It is my hope that my team members will help fill in the gaps.

Design

Since we were given a deadline to come up with a parts list and a basic vision for our bot, after many discussions we decided to build a bot with the following:

Overall I think it was an alright decision and I don't think I would swap it out unless for something a bit more robust with a better voltage regulator.

I don't think this was a bad choice, but knowing more about the quirks of the ESP and being very very careful with that 3.3V and 5V rail difference would have saved us a lot of headaches and debugging time. In all honesty, considering our experience level, an Arduino Mega would have served us better.

I'm just disappointed we were not able to make full use of this sensor, since we weren't able to harness it for anything besides providing error values to our PID control system.

The critical flaw, which we were aware of but only discovered how detrimental it would be at the end of the competition, is that the motors cut out at something like 3V, since they are designed to operate at around 10-11V. Due to this we were not able to get PID to make movements as smooth as we wanted.

I think that about covers all the mission-critical parts; the other smaller parts aren't of too much consequence and I have probably forgotten them 😅

Code Architecture

Okay, so I will probably talk the most here since I spent most of my time writing code for the bot. Initially, while waiting for components to arrive, I wanted to at least be able to complete an implementation of LSRB with some kind of maze solving and then a way to find the optimal path.

To support this research, I created a very simple simulator in C with Raylib (undefinedDarkness/line-follower-sim) wherein one can easily test drive various algorithms and see how the bot would behave traversing several mazes. Eventually I hope to make it easier to use and potentially create a web-based version to make it more accessible.

Using this simulator, we were able to successfully implement a working version of the algorithm described in 1410.4145, and after that, utilizing a simple matrix mapping, we were able to get to finding a "more optimal" path using A*.

In the end, we only got as far as implementing LSRB on the bot, and even that didn't work quite right: while the logic was sound, we were simply unable to reliably detect intersections. That was caused by the combination of brittle intersection detection code and a sub-optimal PID (caused by hardware issues).

This document was also helpful: Pololu's line maze algorithm slides.

Implementation and issues faced

This is easily going to be the longest section compared to our planning and initial building phase. Ironing out all the issues took forever and we never really finished in the end. If I had to guess, our time was spent something like this:

70%10%10%10%Debugging wiresSoftware issuesHardware failing$HIT didn't work
Time spent on issues

The Story

Our initial plan was something like this:

  1. Gather components
  2. Build a bot that can follow a line (line follower)
  3. Figure out how to do the maze solving part

Considering we had only drafted this plan on September 20th and we had to go for the competition on the 8th of October, we were none too confident, but we tried our best with that time limit looming over our heads. By some grace of God, before we were set to go to Bangalore, the competition was postponed to the tail end of October, on the 26th. That worked out really handily for us since we didn't have anything to show on the 8th. We had just had a couple of days to work on it after spending like 2 days sourcing an N25 motor and getting it all assembled, and as such had very little time to tune PID on the bot, so it was barely able to follow a line.

Even getting our components was an adventure. Most of the parts we had decided on we were able to get quickly, but the initial set of motors we acquired didn't work, so we had to sit on our hands for about a week and a half to get a set that worked at all. We burned quite a few of the motor drivers, so we had to get and keep spares for those. The sensor we got from the team, luckily, since it's a hard part to find on its own.

As the timeline was shifted, we all took a large breath of relief. It had given us just enough breathing room to actually have something to go to Bangalore with.

This is where we had one of our fumbles, I'd say: we weren't able to keep our high-pitched intensity from that hectic week (before the 8th) going till the 26th. We slowed down by a lot, and for a couple of weeks not much work was done since we had our 2nd batch of mid-sem exams. Even during the exams we worked what little we could, creating charts for testing and doing whatever small modifications we could while still waiting for some parts.

(Not enough detail here; if anyone can write about what all we did here, that'd be great.)

During this time, we spent a good week and a half debugging issues with the bot and burnt through like 5 L298Ns, but by the end we had a mostly functioning bot that we could trust wouldn't suddenly fail on us.

Obviously I'm glossing over a lot here, as it's been a while since then and my memory fails me.

Some of the issues we faced:

After a couple of days' work tuning the PID to a reasonable level, we started work on the maze solving part (this is like 1 week before the competition now).

We had already written a fully working algorithm for LSRB maze navigation, and later A* for path optimization, along with a specialized simulator for the same.

The maze simulator
The maze simulator

Porting it to the ESP wasn't a big deal since we had already written it in C11, but this is where we faced one of our big issues: intersection detection.

For some reason, no matter what we did, we couldn't get intersection detection to work smoothly. Our QTR16, while fine for the PID control, simply couldn't reliably detect the intersections, and in the end we even tried a janky solution with an array of 3 individual IR sensors positioned far enough apart to not cause issues (if only they worked). In the end we figured out that it was also due to our N25 motors not being precise enough to make the minute movements we required for smooth PID, so our PID was jankier than we could allow (that was the death knell).

It's been a while, so I'm not really able to write with as much detail and knowledge as I could at the time, but I will say it was a very, let's say, humbling experience, and I learnt a lot internally even if I couldn't list it out if I wanted to.

Oh yeah, the motors we got had encoders, which we spent a lot of time trying to get working, as they would allow us to accurately measure the distance we had travelled and use that in our control code (to stop at the end of every 30cm segment). But that simply didn't work: they were inconsistent with themselves. Eventually, on a senior's recommendation, we even wondered if we should try wheel odometry, taking several readings of the encoders at various speeds to try and derive some kind of relation to get some distance out.