0.1.7 RADAR

This commit is contained in:
rob tillaart 2022-11-23 13:53:23 +01:00
parent f51785194d
commit f121659f29
9 changed files with 152 additions and 88 deletions

View File

@ -1,5 +1,21 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile: compile:
# Choosing to run compilation tests on 2 different Arduino platforms # Choosing to run compilation tests on 2 different Arduino platforms
# selected only those that work
platforms: platforms:
- uno - uno
# - due # - due
@ -7,5 +23,6 @@ compile:
# - leonardo # - leonardo
- m4 - m4
- esp32 - esp32
# - esp8266 - esp8266
# - mega2560 # - mega2560
- rpipico

View File

@ -0,0 +1,42 @@
# Change Log Radar
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.7] - 2022-11-23
- add changelog.md
- add RP2040 to build-CI
- fix keywords.txt
- minor edit readme.md
- minor edit unit test
## [0.1.6] - 2021-12-27
- update library.json
- update readme.md
- update license
- minor edits
## [0.1.5] - 2021-05-27
- fix Arduino-lint
## [0.1.4] - 2021-01-07
- Arduino-CI, unit-test
## [0.1.3] - 2020-07-06
- refactor
- clean up
- documentation
## [0.1.2] - 2017-07-16
- refactor & review
## [0.1.01] - 2015-03-06
- updated some code, still not functional
## [0.1.00] - 2013-09-30 (oldest version found ?)
- outline the idea

View File

@ -1,9 +1,8 @@
# Syntax Colouring Map for runningAngle # Syntax Colouring Map for RADAR
# Data types (KEYWORD1) # Data types (KEYWORD1)
runningAngle KEYWORD1 RADAR KEYWORD1
AngleType KEYWORD1
# Methods and Functions (KEYWORD2) # Methods and Functions (KEYWORD2)

View File

@ -15,7 +15,7 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/RADAR" "url": "https://github.com/RobTillaart/RADAR"
}, },
"version": "0.1.6", "version": "0.1.7",
"license": "MIT", "license": "MIT",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "*", "platforms": "*",

View File

@ -1,5 +1,5 @@
name=RADAR name=RADAR
version=0.1.6 version=0.1.7
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for a pan tilt radar. sentence=Arduino library for a pan tilt radar.

View File

@ -1,18 +1,10 @@
// //
// FILE: radar.cpp // FILE: radar.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.6 // VERSION: 0.1.7
// PURPOSE: Arduino library for a pan tilt radar. // PURPOSE: Arduino library for a pan tilt radar.
// URL: https://github.com/RobTillaart/RADAR // URL: https://github.com/RobTillaart/RADAR
//
// HISTORY
// 0.1.00 2013-09-30 (?) outline
// 0.1.01 2015-03-06 updated some code, still not functional
// 0.1.2 2017-07-16 refactor & review
// 0.1.3 2020-07-06 refactor, clean up and some documentation
// 0.1.4 2021-01-07 Arduino-CI, unit-test
// 0.1.5 2021-05-27 fix Arduino-lint
// 0.1.6 2021-12-27 Update library.json, readme, license, minor edits
#include "radar.h" #include "radar.h"
@ -20,7 +12,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// //
// CONSTRUCTOR // CONSTRUCTOR
// //
RADAR::RADAR(const uint8_t pinPan, const uint8_t pinTilt) RADAR::RADAR(const uint8_t pinPan, const uint8_t pinTilt)
{ {
@ -41,7 +33,10 @@ RADAR::RADAR(const uint8_t pinPan, const uint8_t pinTilt)
} }
// PUBLIC ////////////////////////////////////////////////////////////
//
// PUBLIC
//
void RADAR::gotoPan(const int16_t pan) void RADAR::gotoPan(const int16_t pan)
{ {
if (pan == _pan) return; if (pan == _pan) return;
@ -54,15 +49,15 @@ void RADAR::gotoPan(const int16_t pan)
int16_t RADAR::getPan() int16_t RADAR::getPan()
{ {
// ESTIMATE current position on time it takes to go from previous to new // ESTIMATE current position on time it takes to go from previous to new
if (_pan == _prevPan) return _pan; if (_pan == _prevPan) return _pan;
// if (enough time passed to move to new position) return new position // if (enough time passed to move to new position) return new position
uint32_t duration = millis() - _lastPanTime; uint32_t duration = millis() - _lastPanTime;
uint32_t movement = round(duration * _panPerSecond * 0.001); uint32_t movement = round(duration * _panPerSecond * 0.001);
if ( abs(_pan - _prevPan) <= movement) return _pan; if ( abs(_pan - _prevPan) <= movement) return _pan;
// else estimate PAN by linear interpolation // else estimate PAN by linear interpolation
if (_pan > _prevPan) return _prevPan + movement; if (_pan > _prevPan) return _prevPan + movement;
return _prevPan - movement; return _prevPan - movement;
} }
@ -74,22 +69,22 @@ void RADAR::gotoTilt(const int16_t tilt)
_prevTilt = getTilt(); _prevTilt = getTilt();
_tilt = tilt; _tilt = tilt;
analogWrite(_pinTilt, _tilt); // 0..180 analogWrite(_pinTilt, _tilt); // 0..180
_lastTiltTime = millis(); _lastTiltTime = millis();
} }
int16_t RADAR::getTilt() int16_t RADAR::getTilt()
{ {
// ESTIMATE current position on time it takes to go from previous to new // ESTIMATE current position on time it takes to go from previous to new
if (_tilt == _prevTilt) return _tilt; if (_tilt == _prevTilt) return _tilt;
// if (enough time passed to move to new position) return new position // if (enough time passed to move to new position) return new position
uint32_t duration = millis() - _lastTiltTime; uint32_t duration = millis() - _lastTiltTime;
uint32_t movement = round(duration * _tiltPerSecond * 0.001); uint32_t movement = round(duration * _tiltPerSecond * 0.001);
if (abs(_tilt - _prevTilt) <= movement) return _tilt; if (abs(_tilt - _prevTilt) <= movement) return _tilt;
// estimate TILT by linear interpolation // estimate TILT by linear interpolation
if (_tilt > _prevTilt) return _prevTilt + movement; if (_tilt > _prevTilt) return _prevTilt + movement;
return _prevTilt - movement; return _prevTilt - movement;
} }
@ -145,7 +140,7 @@ void RADAR::gotoHomePosition()
uint32_t RADAR::ping() uint32_t RADAR::ping()
{ {
// TODO ping code here - playground or teckel's improved ping))) // TODO ping code here - playground or teckel's improved ping))) ?
return 0; return 0;
} }
@ -157,10 +152,16 @@ uint32_t RADAR::ping(const int16_t pan, const int16_t tilt)
while (isMoving()); while (isMoving());
return ping(); return ping();
} }
// PRIVATE
////////////////////////////////////////////////////////////
//
// PRIVATE
//
// TODO distil private parts (getPan and getTilt share a lot // TODO distil private parts (getPan and getTilt share a lot
// -- END OF FILE --
// -- END OF FILE --

View File

@ -2,7 +2,7 @@
// //
// FILE: radar.h // FILE: radar.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.1.6 // VERSION: 0.1.7
// PURPOSE: Arduino library for a pan tilt radar. // PURPOSE: Arduino library for a pan tilt radar.
// URL: https://github.com/RobTillaart/RADAR // URL: https://github.com/RobTillaart/RADAR
@ -10,10 +10,10 @@
#include "Arduino.h" #include "Arduino.h"
#define RADAR_LIB_VERSION (F("0.1.6")) #define RADAR_LIB_VERSION (F("0.1.7"))
// TODO # positions in a begin() or constructor? // TODO # positions in a begin() or constructor?
#ifndef RADAR_POSITIONS #ifndef RADAR_POSITIONS
#define RADAR_POSITIONS 10 #define RADAR_POSITIONS 10
#endif #endif
@ -22,57 +22,63 @@
class RADAR class RADAR
{ {
public: public:
RADAR(const uint8_t pinPan, const uint8_t pinTilt); RADAR(const uint8_t pinPan, const uint8_t pinTilt);
// no valid range checking or negative value check.
void setPanPerSecond(float pps) { _panPerSecond = pps; };
float getPanPerSecond() { return _panPerSecond; };
void setTiltPerSecond(float tps) { _tiltPerSecond = tps; };
float getTiltPerSecond() { return _tiltPerSecond; };
// basic moves // no valid range checking or negative value check.
void gotoPan(const int16_t pan); void setPanPerSecond(float pps) { _panPerSecond = pps; };
int16_t getPan(); float getPanPerSecond() { return _panPerSecond; };
void gotoTilt(const int16_t tilt); void setTiltPerSecond(float tps) { _tiltPerSecond = tps; };
int16_t getTilt(); float getTiltPerSecond() { return _tiltPerSecond; };
void gotoPanTilt(const int16_t pan, const int16_t tilt);
// memory positions - store / recall?
uint8_t getMaxPositions() { return RADAR_POSITIONS; };
bool setPosition(const uint8_t index, const int16_t pan, const int16_t tilt);
bool getPosition(const uint8_t index, int16_t & pan, int16_t & tilt);
bool gotoPosition(const uint8_t index);
void setHomePosition(const int16_t pan, const int16_t tilt);
void gotoHomePosition();
// feedback on positions. // basic moves
bool isMoving() { return isPanMoving() || isTiltMoving(); }; void gotoPan(const int16_t pan);
bool isPanMoving() { return getPan() != _pan; }; int16_t getPan();
bool isTiltMoving() { return getTilt() != _tilt; }; void gotoTilt(const int16_t tilt);
int16_t getTilt();
void gotoPanTilt(const int16_t pan, const int16_t tilt);
// memory positions - store / recall?
uint8_t getMaxPositions() { return RADAR_POSITIONS; };
bool setPosition(const uint8_t index, const int16_t pan, const int16_t tilt);
bool getPosition(const uint8_t index, int16_t & pan, int16_t & tilt);
bool gotoPosition(const uint8_t index);
void setHomePosition(const int16_t pan, const int16_t tilt);
void gotoHomePosition();
// feedback on positions.
bool isMoving() { return isPanMoving() || isTiltMoving(); };
bool isPanMoving() { return getPan() != _pan; };
bool isTiltMoving() { return getTilt() != _tilt; };
// TODO NIY
uint32_t ping();
uint32_t ping(const int16_t pan, const int16_t tilt);
// TODO NIY
uint32_t ping();
uint32_t ping(const int16_t pan, const int16_t tilt);
private: private:
int16_t _pinPan; int16_t _pinPan;
int16_t _pinTilt; int16_t _pinTilt;
int16_t _prevPan; int16_t _prevPan;
int16_t _pan; int16_t _pan;
int16_t _homePan; int16_t _homePan;
uint32_t _lastPanTime; uint32_t _lastPanTime;
int16_t _prevTilt; int16_t _prevTilt;
int16_t _tilt; int16_t _tilt;
int16_t _homeTilt; int16_t _homeTilt;
uint32_t _lastTiltTime; uint32_t _lastTiltTime;
int16_t _panArray[RADAR_POSITIONS]; int16_t _panArray[RADAR_POSITIONS];
int16_t _tiltArray[RADAR_POSITIONS]; int16_t _tiltArray[RADAR_POSITIONS];
float _panPerSecond = 15; float _panPerSecond = 15;
float _tiltPerSecond = 15; float _tiltPerSecond = 15;
}; };

View File

@ -32,14 +32,11 @@ From that number and the start moment one can determine approximately its positi
Given its position while moving is interesting for radar purposes as one can determine e.g. Given its position while moving is interesting for radar purposes as one can determine e.g.
in which direction a ping is given and therefore which distance belongs to which pair of angles. in which direction a ping is given and therefore which distance belongs to which pair of angles.
Note: no active development Note: no active development.
## Interface ## Interface
TODO elaborate
### Constructor and config ### Constructor and config
- **RADAR(pan, tilt)** define pan / tilt pins of the radar. These should be PWM pins. - **RADAR(pan, tilt)** define pan / tilt pins of the radar. These should be PWM pins.
@ -60,7 +57,7 @@ Note: no valid range checking or negative value check.
- **void gotoPanTilt(const int16_t pan, const int16_t tilt)** - **void gotoPanTilt(const int16_t pan, const int16_t tilt)**
### memory positions - store / recall? ### memory positions - store / recall
- **uint8_t getMaxPositions()** - **uint8_t getMaxPositions()**
- **bool setPosition(const uint8_t index, const int16_t pan, const int16_t tilt)** - **bool setPosition(const uint8_t index, const int16_t pan, const int16_t tilt)**
@ -70,7 +67,7 @@ Note: no valid range checking or negative value check.
- **void gotoHomePosition()** - **void gotoHomePosition()**
### feedback on positions. ### feedback on position
- **bool isMoving()** - **bool isMoving()**
- **bool isPanMoving()** - **bool isPanMoving()**
@ -84,12 +81,21 @@ See examples
## Future ## Future
#### must
- build the thing when time permits!
- improve documentation. - improve documentation.
#### should
- test more (e.g. continuous servo versus 180 servo). - test more (e.g. continuous servo versus 180 servo).
- add sketches. - add sketches.
- remember lastPing (angle pan tilt). - remember lastPing (angle pan tilt).
- check TODO's in code. - check TODO's in code.
- move code from .h to .cpp
#### could
- single servo radar (Pan only) as derived class. - single servo radar (Pan only) as derived class.
- dynamic allocation of position arrays. - dynamic allocation of position arrays.
- store positions in EEPROM/FRAM for reboot?

View File

@ -46,18 +46,11 @@ unittest_teardown()
{ {
} }
/*
unittest(test_new_operator)
{
assertEqualINF(exp(800));
assertEqualINF(0.0/0.0);
assertEqualINF(42);
assertEqualNAN(INFINITY - INFINITY); unittest(test_constants)
assertEqualNAN(0.0/0.0); {
assertEqualNAN(42); assertEqual(10, RADAR_POSITIONS);
} }
*/
unittest(test_constructor) unittest(test_constructor)