Code Monkey home page Code Monkey logo

oilerexample's Introduction

OilerExample

Code to implement an oiler for a lathe using an Arduino Uno

This project is designed to implement an oiler for a metal lathe.

The Oiler consists of multiple motors to pump oil and for each motor there is a sensor that signals as drips of oil are delivered.

Additionally there can be inputs from the lathe that signal when the lathe is powered on/off and additionally for each revolution of its spindle. If these inputs are present the system has additional options to drive when the oiling starts.

This is sketch consists of an example 'OilerExample.ino' sketch that demonstrates how to use the oiler codebase.

The code is implemented in an object orientated approach. The code base defines and instatiates an object to represent the oiler system, called TheOiler. It also instantiates an object to represent the device being oiled, called TheMachine which tracks machine units (number of spindle revolutions) and number of seconds of powered on time that has elapsed and finally there is an object called TheTimer that schedules work on requested basis.

When run, the first step is to add motor(s) to TheOiler and provide the pin(s) that signal when the motor generates output (referred to as a unit of work). Once done, TheOiler can be turned on. In this mode it waits for a configurable time (in seconds) and then starts the motors. As the motors result in drips of oil, this is detected by the sensor and a count kept. The timer object regularly checks for the number of output 'units' and stops the related motor when a configurable target is reached. When all motors are idle the Timer starts to monitors elasped time and restarts the motors when a configurable length of time has passed.

The functionality above can be enhanced by adding TheMachine object to the TheOiler. Once TheOiler 'knows' about TheMachine it can query TheMachine object about how many revolutions the spindle has done (described in the code as machine work units) and also how long the lathe has been powered on. This information allows the Oiler to restart the motors on machine units (spindle revolutions) completed or on elapsed powered up time.

Currently the system supports two types of motors, a relay motor which uses the output of a single pin to drive a relay which in turn drives a dc motor. The second type is a four pin stepper driver & motor. This latter type has been tested using a ULN2003 stepper driver and 28BYJ-48 stepper motor. This latter motor has additional features that the dc motor does not implement e.g. ability to programatically change the motor direction and the ability to alter the speed. For the relay motor changing direction would be a wiring change at project setup.

Since the code uses a timer to monitor progress there is no need for a user to call any special function in the arduino loop function or worry that the loop is taking a long time and impacting the oiler processing. The loop is free for other uses such as a user interface to monitor and control TheOiler.

The arduino setup function should be used to add motors to TheOiler, attach TheMachine to TheOiler, if TheMachine inputs are implemented in the project install, and finally turn TheOiler on.

In this example there is code to demonstrate adding a 4 pin stepper motor, starting the oiler, changing direction, using inputs from 'TheMachine' to start the oiler after spindle revolutions or elapsed powered on time. A rudimentary system monitor and user interface is implemented in the loop function. This uses ANSI terminal control sequences (see https://en.wikipedia.org/wiki/ANSI_escape_code#Fe_Escape_sequences). To benefit from this connect to the Arduino serial port using a better terminal monitor than the default one that comes with the arduino IDE. This was tested with the free version of PuTTY. Note to use this download the ketch to the arduino and take note of the port the arduino is on. Start your emaulator and connect to that port at the baud rate used in the sketch (currently 19200) and off you go. Note that if you want to download the sketch again you will have to stop the terminal emulator so the arduino IDE can gain access.

One point of note in the code design. TheOiler is designed to run in the background without need of a sketch writer to make regular calls to any oiler function in the arduino loop function. By way of comparison this is a similar model to that used with the built in Serial function. The user does not need to do anything to keep pumping queued serial output to the serial monitor, this just happens in the background. In the same way, this code starts and stops the attached motors when specified thresholds are met. The use model is to configure TheOiler and optionally TheMachine in the arduino setup function and turn TheOiler on. The arduino loop function is free to fo whatever the user wants - create a user interface to monitor and control TheOiler or add completely separate functionality.

oilerexample's People

Contributors

naylom avatar

Watchers

 avatar

oilerexample's Issues

Change using Pin 2,3 for optical sensors and use these for the two inputs from the machine being oiled ( eg lathe)

Currently each motor has an associated optical sensor with a related input pin. In the current code the input pins are monitored using attachInterrupt. On the Uno these are limited to 2 once pins 0 & 1 are used for a user display / input. The net result is this limits the number of motors to 2. To add more flexibility the code will be changed to use Pin Change Interrupts to dectect input from the optical sensors, Pin Change Interrupts can detect changes and generate interrupts on a greater variaty of pins and hence allow more motors. The two optional inputs from the machine being oiled will be moved to use the freed up pins 2 and 3.

Motors should stop and start independently

Currently once the Oiler start oiling it waits for all motors to completed their target output (number of drips) before entering the mode waitinf for some restart criteria to be met. This means if one motors is not outputting then all will stop. In this error condition it is deemed better to allow a motor that has completed to be go into monitor mode and continue oiling when needed.

A result of this is that the Oiler will have an addtional state of PARTIALLY_RUNNING when the number of motors running > 0 and < NUM_MOTORS

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.