PID control for submarine

Hi

I am gradually building a sketch to control my submarine. I have it nearly working. I have a pressure gauge that is perfect for the job. I can take a snapshot of the pressure I want but now I want to write in a PID program that can control the hydroplane in the bow to control the depth.

I have attached my long sketch so far, but would love it if someone could provide an example code for what I want.

I have a channel from the RC coming in to the arduino, on this sketch it is HYDRO_IN_PIN. It is read by the arduino and then goes out to the servo through… servoHydro.attach(HYDRO_OUT_PIN).

I have a pressure gauge input to pressurePin = A0; and I can take a snapshot of the pressure I want to keep, found at ‘depthsnapshot.’

The reading of depthsnapshot will sit at for example 700 which is equivalent to periscope depth. I would like some code to use with the pid library to take over running the hydro when I throw another switch I have not yet created but maybe ‘depthkeeping’ for example. Ie when depthkeeping is = 1 then take over the control of the servo to keep the depth at for example 700.

This is a long shot, but does anyone have some code that can do this?

My problem is that I don’t know the basics and just need something to get me started.

Cheers. John

subsketchlatest4.ino (17.8 KB)

Hello, Do a search for "PID library" Check all the developer's links and blog.

http://diydrones.com/profiles/blogs/tutorial-series-for-new-arduin

http://brettbeauregard.com/blog/tag/pid/