Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed FastIO FastPWM USBDevice
Fork of Pinscape_Controller by
plunger.h@43:7a6364d82a41, 2016-02-06 (annotated)
- Committer:
- mjr
- Date:
- Sat Feb 06 20:21:48 2016 +0000
- Revision:
- 43:7a6364d82a41
- Parent:
- 35:e959ffba78fd
- Child:
- 44:b5ac89b9cd5d
Before floating point plunger ranging
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mjr | 35:e959ffba78fd | 1 | // Plunger Sensor Interface |
| mjr | 35:e959ffba78fd | 2 | // |
| mjr | 35:e959ffba78fd | 3 | // This module defines the abstract interface to the plunger sensors. |
| mjr | 35:e959ffba78fd | 4 | // We support several different physical sensor types, so we need a |
| mjr | 35:e959ffba78fd | 5 | // common interface for use in the main code. |
| mjr | 35:e959ffba78fd | 6 | // |
| mjr | 35:e959ffba78fd | 7 | |
| mjr | 35:e959ffba78fd | 8 | #ifndef PLUNGER_H |
| mjr | 35:e959ffba78fd | 9 | #define PLUNGER_H |
| mjr | 35:e959ffba78fd | 10 | |
| mjr | 35:e959ffba78fd | 11 | class PlungerSensor |
| mjr | 35:e959ffba78fd | 12 | { |
| mjr | 35:e959ffba78fd | 13 | public: |
| mjr | 35:e959ffba78fd | 14 | |
| mjr | 35:e959ffba78fd | 15 | PlungerSensor() { } |
| mjr | 35:e959ffba78fd | 16 | virtual ~PlungerSensor() { } |
| mjr | 35:e959ffba78fd | 17 | |
| mjr | 35:e959ffba78fd | 18 | // Number of "pixels" in the sensor's range. We use the term "pixels" |
| mjr | 35:e959ffba78fd | 19 | // here for historical reasons, namely that the first sensor we implemented |
| mjr | 35:e959ffba78fd | 20 | // was an imaging sensor that physically sensed the plunger position as |
| mjr | 35:e959ffba78fd | 21 | // a pixel coordinate in the image. But it's no longer the right word, |
| mjr | 35:e959ffba78fd | 22 | // since we support sensor types that have nothing to do with imaging. |
| mjr | 35:e959ffba78fd | 23 | // Even so, the function this serves is still applicable. Abstractly, |
| mjr | 43:7a6364d82a41 | 24 | // it represents the physical resolution of the sensor in terms of |
| mjr | 43:7a6364d82a41 | 25 | // the number of quanta over the full range of travel of the plunger. |
| mjr | 43:7a6364d82a41 | 26 | // For sensors that inherently quantize the position reading at the |
| mjr | 43:7a6364d82a41 | 27 | // physical level, such as imaging sensors and quadrature sensors, |
| mjr | 43:7a6364d82a41 | 28 | // this should be set to the total number of position steps over the |
| mjr | 43:7a6364d82a41 | 29 | // range of travel. For devices with physically analog outputs, such |
| mjr | 43:7a6364d82a41 | 30 | // as potentiometers or LVDTs, the reading still has to be digitized |
| mjr | 43:7a6364d82a41 | 31 | // for us to be able to work with it, which means it has to be turned |
| mjr | 43:7a6364d82a41 | 32 | // into a value that's fundamentally an integer. But this happens in |
| mjr | 43:7a6364d82a41 | 33 | // the ADC, so the quantization scale is hidden in the mbed libraries. |
| mjr | 43:7a6364d82a41 | 34 | // The normal KL25Z ADC configuration is 16-bit quantization, so the |
| mjr | 43:7a6364d82a41 | 35 | // quantization factor is usually 65535. But you might prefer to set |
| mjr | 43:7a6364d82a41 | 36 | // this to the joystick maximum so that there are no more rounding |
| mjr | 43:7a6364d82a41 | 37 | // errors in scale conversions after the point of initial conversion. |
| mjr | 35:e959ffba78fd | 38 | // |
| mjr | 43:7a6364d82a41 | 39 | // IMPORTANT! This value MUST be initialized in the constructor for |
| mjr | 43:7a6364d82a41 | 40 | // each concrete subclass. |
| mjr | 35:e959ffba78fd | 41 | int npix; |
| mjr | 35:e959ffba78fd | 42 | |
| mjr | 35:e959ffba78fd | 43 | // Initialize the physical sensor device. This is called at startup |
| mjr | 35:e959ffba78fd | 44 | // to set up the device for first use. |
| mjr | 35:e959ffba78fd | 45 | virtual void init() = 0; |
| mjr | 35:e959ffba78fd | 46 | |
| mjr | 35:e959ffba78fd | 47 | // Take a high-resolution reading. Sets pos to the current position, |
| mjr | 35:e959ffba78fd | 48 | // on a scale from 0 to npix: 0 is the maximum forward plunger position, |
| mjr | 35:e959ffba78fd | 49 | // and npix is the maximum retracted position, in terms of the sensor's |
| mjr | 35:e959ffba78fd | 50 | // extremes. This is a raw reading in terms of the sensor range; the |
| mjr | 35:e959ffba78fd | 51 | // caller is responsible for applying calibration data and scaling the |
| mjr | 35:e959ffba78fd | 52 | // result to the the joystick report range. |
| mjr | 35:e959ffba78fd | 53 | // |
| mjr | 35:e959ffba78fd | 54 | // Returns true on success, false on failure. Return false if it wasn't |
| mjr | 35:e959ffba78fd | 55 | // possible to take a good reading for any reason. |
| mjr | 35:e959ffba78fd | 56 | virtual bool highResScan(int &pos) = 0; |
| mjr | 35:e959ffba78fd | 57 | |
| mjr | 35:e959ffba78fd | 58 | // Take a low-resolution reading. This reports the result on the same |
| mjr | 35:e959ffba78fd | 59 | // 0..npix scale as highResScan(). Returns true on success, false on |
| mjr | 35:e959ffba78fd | 60 | // failure. |
| mjr | 35:e959ffba78fd | 61 | // |
| mjr | 35:e959ffba78fd | 62 | // The difference between the high-res and low-res scans is the amount |
| mjr | 35:e959ffba78fd | 63 | // of time it takes to complete the reading. The high-res scan is allowed |
| mjr | 35:e959ffba78fd | 64 | // to take about 10ms; a low-res scan take less than 1ms. For many |
| mjr | 35:e959ffba78fd | 65 | // sensors, either of these time scales would yield identical resolution; |
| mjr | 35:e959ffba78fd | 66 | // if that's the case, simply take a reading the same way in both functions. |
| mjr | 35:e959ffba78fd | 67 | // The distinction is for the benefit of sensors that need significantly |
| mjr | 35:e959ffba78fd | 68 | // longer to read at higher resolutions, such as image sensors that have |
| mjr | 35:e959ffba78fd | 69 | // to sample pixels serially. |
| mjr | 35:e959ffba78fd | 70 | virtual bool lowResScan(int &pos) = 0; |
| mjr | 35:e959ffba78fd | 71 | |
| mjr | 35:e959ffba78fd | 72 | // Send an exposure report to the joystick interface. This is specifically |
| mjr | 35:e959ffba78fd | 73 | // for image sensors, and should be omitted by other sensor types. For |
| mjr | 35:e959ffba78fd | 74 | // image sensors, this takes one exposure and sends all pixels to the host |
| mjr | 35:e959ffba78fd | 75 | // through special joystick reports. This is used for PC-side testing tools |
| mjr | 35:e959ffba78fd | 76 | // to let the user check the sensor installation by directly viewing its |
| mjr | 35:e959ffba78fd | 77 | // pixel output. |
| mjr | 35:e959ffba78fd | 78 | virtual void sendExposureReport(class USBJoystick &js) { } |
| mjr | 35:e959ffba78fd | 79 | }; |
| mjr | 35:e959ffba78fd | 80 | |
| mjr | 35:e959ffba78fd | 81 | #endif /* PLUNGER_H */ |
