Search code examples
arduinoschedulingpriority-queueinterrupt-handlingpreemption

Preemptive scheduling algorithm for autonomous vehicle


I'm not sure if this is the best place for this question, but I think the problem has some relations to optimal scheduling algorithms and queueing theory, so hopefully it will be okay.

I'm setting out to build an RC car to navigate courses autonomously. The idea is that it will just go in a straight line until one of its proximity sensors detects a wall or other obstacle, which will cause an interrupt and a steering adjustment.

I learned a bit about RTOS scheduling algorithms in an embedded systems course and preemptive queueing in a network performance course, so I was wondering if I would benefit from applying any of these concepts to this task when going to program the microcontroller, or if I'm overthinking it? The main goal is to develop it in such a way that the car drives as fast as possible without a collision, but I'd also like to prevent it from being jittery as a secondary goal.

So, in I guess a high-level sense, is there a particular method, scheme, or type of scheduling policy for using interrupts that would result in the best performance for a system like this? Are there any particular critical sections for which I should disable interrupts? For reference on hardware limitations, I'm planning to use a microcontroller similar to an arduino with probably three IR sensors. Any advice or suggestions is greatly appreciated.


Solution

  • Using a RTOS here is an overkill. What you need to think of is:

    • What type of sensors you will use: distance (which will return a distance to an object) or presence (which will only indicate if there is an obstacle or not)? Distance sensors will require some to to process (either run an ADC conversion or read I2C) while presence sensors can be directly hooked up to an external interrupt of a uC.
    • How to ensure your car really drives straight? You will find that it may turn slightly even if in theory you ordered it to go straight.

    Depending on answers to the questions above:

    • if you use presence sensors, process them as quickly as possible. Even if you have any other control algorithm running (like some PID), interrupting it will not be a problem.

    • if you use analog distance sensors, use ADC conversion ready interrupt. Then, if you have sensors looking to the sides, you may use returned value to keep a constant distance from the wall, and in result, driving straight (check out micromouse robots)

    Bottom line: if you want to go fast and avoid hitting the walls - process sensors as fast as possible.