Bell crank Ventilator with Ambi Bag - Servo speed control code help

Hi there,

I am presently working on a simplistic ventilator project.

From reading the government specification I believe as do many others that a simple Arduino based ventilator (Ignoring the chip not technically allowed to be used) would make a very cost effective list suport system when combined with an Ambi bag and with some help I believe that it could meet almost all of the governments requirements. Better than the CPAP adaptations being shown at the moment in the UK.

My design uses a servo motor and bell crank to provide compression to an ambi bag with variable compression and velocity to control breath rate. At present rate being fixed at 1:2 Inhalation and Exhalation cycle.

I am now at a loss with my code and wondered if any of the more experience programmers would be able to end a hand?

The premise is that the servo sweeps between 150Deg starting point to a specific angle defined by a potentiometer, 150=> 140,130,120,110 etc. and back again.

This sweep is controlled via another potentiometer defining the breath cyce between 2 and 6 seconds.

The arm then returns to the 150 degree mark to await the elapsed time before starting another cycle.

The problem for all my trials I cannot get the arm to sweep correctly.

At the moment it is sweeping from 100 >150 slowly
then 150 > 100 quickly and undertaking the wait at 100 Deg

I need it to sweep from 150 > 100 Slowly Return to 150 then wait/delay at 150.

Any help would be much apreciated.

Other items in project are;

  1. Pressure overide - If Pressure on A2 >= 40cmH20 then only run to that pressure not full sweep angle
  2. Soft stop at end of compression so run al of compression stroke at fixed speed untill last 5 degrees then slow down to stop allows pressure transducer t not become overtaken and softens impact on lungs.
  3. Screen - Awaiting to go back into work to grab some resistors from my cabinet
  4. Pressure or volume control

Big project that seems simple, I am trying to hit as much of the governmet specs as possible for a project under about £250, if it doesnt help this time is an interesting project and will publish the plans. I also might need a baby home built ventilator to test a possible ventilator test rig I might be involved in making. Coded in LV which I am better at!

Any help is much appreciated!!

Trial_from_backup_2.ino (3.33 KB)

p.s I am pretty sure it is just the logic I am struggling with in the two for statements.

Thanks

First problem fixed definetly was the logic, I have posted the code with the fixed logic if it helps anyone. I also forgot to say that the servo is a 20kg £18 item just from amazon and the rest of the items can all be purchsed from RS. If someone wants the bell crank drwing I have included.

Help with the soft stop or any of the other points would still be very much appreciated.

Lever Arms.pdf (17.9 KB)

Breath_Cycle_and_Angle_Control.ino (3.49 KB)

Not sure if this helps, but, I just finished running some experiments with servos this week..

Was using MG996R servos, but specs vary. First obvious thing is to make sure you can draw sufficient amps. In my case 2.5A is needed for one of these, at 5V. I'll assume you figured that much out..

BUT, here's what I discovered, testing 3 different MG996R:

Each one, needed to be calibrated!

You need to know the documented angle range of your servo, and the calibrated min and max time it takes to reach these angles. The spec for MG996R states 1000uS-2000uS pulse durations which correspond to 0-120 degree rotation. However, I determined, for my servos, I had to use values as low as 800uS for 0 degree rotation, up to as high as 2500uS for 120 degree rotation

So, instead of calling a 45 degree rotation with..

_Servo.write(45); this will not generate consistent results between servos!!

I ended up getting precise responses with..

_Servo.writeMicroseconds(map(45,0,120,800,2500));

Your device will need a calibration component when it is assembled, to determine these values.

In this example, 45 is the target angle. 0 and 120 are the range of the servo. And 800 and 2500 were the observed timings needed to reach those precise measured angles using a protractor. Each servo had a different calibration range, so this is an example of one of them.

Also keep in mind, too, that you can only have so much torque on the air compression. So, you are probably right, you may need to step it in small increments.. not just min and max, to keep the servo from overheating.

However, you would need more control variables to do that in the main loop. minAngle, maxAngle, stepSize and a currAngle that is built on those other 3 values that actually gets called in the writeMicroseconds() method. Techincally, minAngle, maxAngle and stepSize should be constants, or #defines.