Introduction

Welcome to the code page for the project

Because of my background as a systems developer I am devoting a full page for the code and technicalities of the project


The main use case is the robot is on standby at home - meaning Pi-a, the standby pi, is on and listening for ssh connections.

I want to log in from somewhere outside the house using a phone or pc and be able to drive the robot and take a look around.

I am going to talk through what happens when a user sucessfully logs in to the control center page.

The main functions.js file is responsible for the order of things.

The file is loaded and the process begins on document ready. First it checks to see if Pi-b the main controller Pi is on using the pinger function. This ends up calling a ping function in php as follows:

In our use case the robot is on standby so Pi-a would be on and Pi-b would be off. Once this is established using the pinger function it tells Pi-a to switch Pi-b on. The power supply for Pi-b is wired through a transistor switch which is controlled by Pi-a, so we send a message to Pi-a to switch on the power to Pi-b

This function calls a python script on Pi-a which switches on the GPIO pin which is connected to the switch which controls the power for Pi-b

Next the script sleeps for 60 seconds to give Pi-b a chance to boot up. Then the check Status function is called again, the pinger is called again and this time Pi-b should be on. We want two things to run on Pi-b - mjpg streamer to stream video and nodejs with socket io to control the motors and servos. So the script calls a status function to find out which is on and if not switch them on.

There is another thing that happens here too...

Shut down timer

So we have switched the robot on from outside the house. What happens if we lose the connection (phone battery, out of phone coverage etc)

The robot is programmed to switch itself off if it dosent recieve any calls for a given period of time. So the webpage calls the pi and sends a call to start its shutdown timer. The 5 minute timer starts on Pi-b. There is another timer on the web page which recalls the function in 4 minutes so the Pi resets its timer to 5 minutes again. If the webpage closes for whatever reason the timer will run out on Pi-b and when it does Pi-b shuts down.

Meanwhile, on the Standby Pi. After it switches on the power for Pi-b it pings Pi-b every two minutes. If there is no answer (Pi-b has shut itself down) Pi-a will turn off the power switch. This renders the robot back to its original standby state

Controller Script