This project aims at hacking a remote controlled car by replacing the tx/rx and navigation systems. This project implements the pc side.
Dependencies: mbed-rtos mbed ssWi
For the related information, consult the wiki documentation at:
Import programrover_car
This project aims at hacking a remote controlled car by replacing the tx/rx and navigation systems. This project implements the car side.
joystick/joystick.hpp@0:1b4c3bbaf102, 2013-03-12 (annotated)
- Committer:
- mariob
- Date:
- Tue Mar 12 07:39:13 2013 +0000
- Revision:
- 0:1b4c3bbaf102
This project aims at hacking a remote controlled car by replacing the tx/rx and navigation systems. This project implements the pc side.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mariob | 0:1b4c3bbaf102 | 1 | #ifndef __JOYSTICK_HPP__ |
mariob | 0:1b4c3bbaf102 | 2 | #define __JOYSTICK_HPP__ |
mariob | 0:1b4c3bbaf102 | 3 | |
mariob | 0:1b4c3bbaf102 | 4 | #include <limits> |
mariob | 0:1b4c3bbaf102 | 5 | |
mariob | 0:1b4c3bbaf102 | 6 | #include "mbed.h" |
mariob | 0:1b4c3bbaf102 | 7 | #include "rtos.h" |
mariob | 0:1b4c3bbaf102 | 8 | |
mariob | 0:1b4c3bbaf102 | 9 | #define JOYSTICK_SX_X 1 |
mariob | 0:1b4c3bbaf102 | 10 | #define JOYSTICK_SX_Y 0 |
mariob | 0:1b4c3bbaf102 | 11 | #define JOYSTICK_DX_X 2 |
mariob | 0:1b4c3bbaf102 | 12 | #define JOYSTICK_DX_Y 3 |
mariob | 0:1b4c3bbaf102 | 13 | |
mariob | 0:1b4c3bbaf102 | 14 | class Joystick |
mariob | 0:1b4c3bbaf102 | 15 | { |
mariob | 0:1b4c3bbaf102 | 16 | |
mariob | 0:1b4c3bbaf102 | 17 | AnalogIn* channels[4]; |
mariob | 0:1b4c3bbaf102 | 18 | float values[4]; |
mariob | 0:1b4c3bbaf102 | 19 | Mutex mutexes[4]; |
mariob | 0:1b4c3bbaf102 | 20 | |
mariob | 0:1b4c3bbaf102 | 21 | struct RangeJoystichChannel { |
mariob | 0:1b4c3bbaf102 | 22 | float maxV; |
mariob | 0:1b4c3bbaf102 | 23 | float minV; |
mariob | 0:1b4c3bbaf102 | 24 | float center; |
mariob | 0:1b4c3bbaf102 | 25 | RangeJoystichChannel () { |
mariob | 0:1b4c3bbaf102 | 26 | maxV = std::numeric_limits<float>::min(); |
mariob | 0:1b4c3bbaf102 | 27 | minV = std::numeric_limits<float>::max(); |
mariob | 0:1b4c3bbaf102 | 28 | center = 0.0; |
mariob | 0:1b4c3bbaf102 | 29 | } |
mariob | 0:1b4c3bbaf102 | 30 | }; |
mariob | 0:1b4c3bbaf102 | 31 | |
mariob | 0:1b4c3bbaf102 | 32 | RangeJoystichChannel ranges[4]; |
mariob | 0:1b4c3bbaf102 | 33 | |
mariob | 0:1b4c3bbaf102 | 34 | void update(int channel); |
mariob | 0:1b4c3bbaf102 | 35 | |
mariob | 0:1b4c3bbaf102 | 36 | public: |
mariob | 0:1b4c3bbaf102 | 37 | |
mariob | 0:1b4c3bbaf102 | 38 | Joystick (PinName pinSX_X, PinName pinSX_Y, PinName pinDX_X, PinName pinDX_Y) { |
mariob | 0:1b4c3bbaf102 | 39 | channels[JOYSTICK_SX_X] = new AnalogIn(pinSX_X); |
mariob | 0:1b4c3bbaf102 | 40 | channels[JOYSTICK_SX_Y] = new AnalogIn(pinSX_Y); |
mariob | 0:1b4c3bbaf102 | 41 | channels[JOYSTICK_DX_X] = new AnalogIn(pinDX_X); |
mariob | 0:1b4c3bbaf102 | 42 | channels[JOYSTICK_DX_Y] = new AnalogIn(pinDX_Y); |
mariob | 0:1b4c3bbaf102 | 43 | } |
mariob | 0:1b4c3bbaf102 | 44 | |
mariob | 0:1b4c3bbaf102 | 45 | void tuneCentring (int nOfSamples, int channel); |
mariob | 0:1b4c3bbaf102 | 46 | void tuneChannel (int nOfSamples, int channel); |
mariob | 0:1b4c3bbaf102 | 47 | |
mariob | 0:1b4c3bbaf102 | 48 | void update(); |
mariob | 0:1b4c3bbaf102 | 49 | |
mariob | 0:1b4c3bbaf102 | 50 | float read(int channel); |
mariob | 0:1b4c3bbaf102 | 51 | |
mariob | 0:1b4c3bbaf102 | 52 | ~Joystick () { |
mariob | 0:1b4c3bbaf102 | 53 | delete channels[JOYSTICK_SX_X]; |
mariob | 0:1b4c3bbaf102 | 54 | delete channels[JOYSTICK_SX_Y]; |
mariob | 0:1b4c3bbaf102 | 55 | delete channels[JOYSTICK_DX_X]; |
mariob | 0:1b4c3bbaf102 | 56 | delete channels[JOYSTICK_DX_Y]; |
mariob | 0:1b4c3bbaf102 | 57 | } |
mariob | 0:1b4c3bbaf102 | 58 | }; |
mariob | 0:1b4c3bbaf102 | 59 | |
mariob | 0:1b4c3bbaf102 | 60 | |
mariob | 0:1b4c3bbaf102 | 61 | #endif //__JOYSTICK_HPP__ |