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@47:df7a88cd249c, 2016-02-18 (annotated)
- Committer:
- mjr
- Date:
- Thu Feb 18 07:32:20 2016 +0000
- Revision:
- 47:df7a88cd249c
- Parent:
- 45:c42166b2878c
- Child:
- 48:058ace2aed1d
3-channel linked DMA scheme for CCD image capture working
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 | // Initialize the physical sensor device. This is called at startup |
| mjr | 35:e959ffba78fd | 19 | // to set up the device for first use. |
| mjr | 35:e959ffba78fd | 20 | virtual void init() = 0; |
| mjr | 35:e959ffba78fd | 21 | |
| mjr | 47:df7a88cd249c | 22 | // Read the sensor position. Sets 'pos' to the current plunger |
| mjr | 47:df7a88cd249c | 23 | // position registered on the sensor, normalized to a 16-bit unsigned |
| mjr | 47:df7a88cd249c | 24 | // integer (0x0000 to 0xFFFF). 0x0000 represents the maximum forward |
| mjr | 47:df7a88cd249c | 25 | // position, and 0xFFFF represents the maximum retracted position. |
| mjr | 47:df7a88cd249c | 26 | // The result returned by this routing isn't calibrated; it simply |
| mjr | 47:df7a88cd249c | 27 | // reflects the raw sensor reading. |
| mjr | 35:e959ffba78fd | 28 | // |
| mjr | 47:df7a88cd249c | 29 | // Timing requirements: for best results, readings should be taken |
| mjr | 47:df7a88cd249c | 30 | // in well under 5ms. There are two factors that go into this limit. |
| mjr | 47:df7a88cd249c | 31 | // The first is the joystick report rate in the main loop. We want |
| mjr | 47:df7a88cd249c | 32 | // to send those as fast as possible to avoid any perceptible control |
| mjr | 47:df7a88cd249c | 33 | // input lag in the pinball emulation. "As fast as possible" is about |
| mjr | 47:df7a88cd249c | 34 | // every 10ms - that's VP's approximate sampling rate, so any faster |
| mjr | 47:df7a88cd249c | 35 | // wouldn't do any good, and could even slow things down by adding CPU |
| mjr | 47:df7a88cd249c | 36 | // load in the Windows drivers handling the extra messages. The second |
| mjr | 47:df7a88cd249c | 37 | // is the speed of the plunger motion. During release events, the |
| mjr | 47:df7a88cd249c | 38 | // plunger moves in a sinusoidal pattern (back and forth) as it reaches |
| mjr | 47:df7a88cd249c | 39 | // the extreme of its travel and bounces back off the spring. To |
| mjr | 47:df7a88cd249c | 40 | // resolve this kind of cyclical motion accurately, we have to take |
| mjr | 47:df7a88cd249c | 41 | // samples much faster than the cycle period - otherwise we encounter |
| mjr | 47:df7a88cd249c | 42 | // an effect known as aliasing, where we mistake a bounce for a small |
| mjr | 47:df7a88cd249c | 43 | // forward motion. Tests with real plungers indicate that the bounce |
| mjr | 47:df7a88cd249c | 44 | // period is on the order of 10ms, so ideally we'd like to take |
| mjr | 47:df7a88cd249c | 45 | // samples much faster than that. |
| mjr | 35:e959ffba78fd | 46 | // |
| mjr | 47:df7a88cd249c | 47 | // Returns true on success, false on failure. Returning false means |
| mjr | 47:df7a88cd249c | 48 | // that it wasn't possible to take a valid reading. |
| mjr | 47:df7a88cd249c | 49 | virtual bool read(uint16_t &pos) = 0; |
| mjr | 47:df7a88cd249c | 50 | |
| mjr | 47:df7a88cd249c | 51 | // $$$ DEPRECATED - left in during transition to new design |
| mjr | 47:df7a88cd249c | 52 | bool lowResScan(float &pos) |
| mjr | 47:df7a88cd249c | 53 | { |
| mjr | 47:df7a88cd249c | 54 | uint16_t fpos; |
| mjr | 47:df7a88cd249c | 55 | if (read(fpos)) |
| mjr | 47:df7a88cd249c | 56 | { |
| mjr | 47:df7a88cd249c | 57 | pos = fpos / 65535.0; |
| mjr | 47:df7a88cd249c | 58 | return true; |
| mjr | 47:df7a88cd249c | 59 | } |
| mjr | 47:df7a88cd249c | 60 | else |
| mjr | 47:df7a88cd249c | 61 | return false; |
| mjr | 47:df7a88cd249c | 62 | } |
| mjr | 47:df7a88cd249c | 63 | bool highResScan(float &pos) { return lowResScan(pos); } |
| mjr | 47:df7a88cd249c | 64 | |
| mjr | 47:df7a88cd249c | 65 | // Send an exposure report to the host, via the joystick interface. This |
| mjr | 47:df7a88cd249c | 66 | // is for image sensors, and can be omitted by other sensor types. For |
| mjr | 35:e959ffba78fd | 67 | // image sensors, this takes one exposure and sends all pixels to the host |
| mjr | 47:df7a88cd249c | 68 | // through special joystick reports. This is used by tools on the host PC |
| mjr | 47:df7a88cd249c | 69 | // to let the user view the low-level sensor pixel data, which can be |
| mjr | 47:df7a88cd249c | 70 | // helpful during installation to adjust the sensor positioning and light |
| mjr | 47:df7a88cd249c | 71 | // source. |
| mjr | 45:c42166b2878c | 72 | // |
| mjr | 45:c42166b2878c | 73 | // Mode bits: |
| mjr | 45:c42166b2878c | 74 | // 0x01 -> send processed pixels (default is raw pixels) |
| mjr | 45:c42166b2878c | 75 | // 0x02 -> low res scan (default is high res scan) |
| mjr | 45:c42166b2878c | 76 | // |
| mjr | 45:c42166b2878c | 77 | // If processed mode is selected, the sensor should apply any pixel |
| mjr | 45:c42166b2878c | 78 | // processing it normally does when taking a plunger position reading, |
| mjr | 45:c42166b2878c | 79 | // such as exposure correction, noise reduction, etc. In raw mode, we |
| mjr | 45:c42166b2878c | 80 | // simply send the pixels as read from the sensor. Both modes are useful |
| mjr | 45:c42166b2878c | 81 | // in setting up the physical sensor. |
| mjr | 45:c42166b2878c | 82 | virtual void sendExposureReport(class USBJoystick &js, uint8_t mode) { } |
| mjr | 35:e959ffba78fd | 83 | }; |
| mjr | 35:e959ffba78fd | 84 | |
| mjr | 35:e959ffba78fd | 85 | #endif /* PLUNGER_H */ |
