From b0789477d270564cfd64f04a4d18d2b205b631da Mon Sep 17 00:00:00 2001 From: rob tillaart Date: Mon, 27 Dec 2021 20:23:58 +0100 Subject: [PATCH] 0.1.6 Radar --- libraries/Radar/.arduino-ci.yml | 10 +++-- .../.github/workflows/arduino_test_runner.yml | 10 +++-- libraries/Radar/LICENSE | 2 +- .../Radar/examples/radarDemo/radarDemo.ino | 1 - libraries/Radar/keywords.txt | 4 +- libraries/Radar/library.json | 7 ++-- libraries/Radar/library.properties | 2 +- libraries/Radar/radar.cpp | 41 ++++++++++--------- libraries/Radar/radar.h | 18 ++++---- libraries/Radar/readme.md | 35 ++++++++++++---- libraries/Radar/test/unit_test_001.cpp | 7 ++-- 11 files changed, 82 insertions(+), 55 deletions(-) diff --git a/libraries/Radar/.arduino-ci.yml b/libraries/Radar/.arduino-ci.yml index ff5659b9..cecf5850 100644 --- a/libraries/Radar/.arduino-ci.yml +++ b/libraries/Radar/.arduino-ci.yml @@ -2,6 +2,10 @@ compile: # Choosing to run compilation tests on 2 different Arduino platforms platforms: - uno - - leonardo - - due - - zero + # - due + # - zero + # - leonardo + - m4 + - esp32 + # - esp8266 + # - mega2560 diff --git a/libraries/Radar/.github/workflows/arduino_test_runner.yml b/libraries/Radar/.github/workflows/arduino_test_runner.yml index 476456bb..096b975b 100644 --- a/libraries/Radar/.github/workflows/arduino_test_runner.yml +++ b/libraries/Radar/.github/workflows/arduino_test_runner.yml @@ -4,10 +4,14 @@ name: Arduino CI on: [push, pull_request] jobs: - arduino_ci: + runTest: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: Arduino-CI/action@master - # Arduino-CI/action@v0.1.1 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + - run: | + gem install arduino_ci + arduino_ci.rb diff --git a/libraries/Radar/LICENSE b/libraries/Radar/LICENSE index 39d07e31..c9bd779a 100644 --- a/libraries/Radar/LICENSE +++ b/libraries/Radar/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2013-2021 Rob Tillaart +Copyright (c) 2013-2022 Rob Tillaart Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/libraries/Radar/examples/radarDemo/radarDemo.ino b/libraries/Radar/examples/radarDemo/radarDemo.ino index 8a8281e7..8f72e348 100644 --- a/libraries/Radar/examples/radarDemo/radarDemo.ino +++ b/libraries/Radar/examples/radarDemo/radarDemo.ino @@ -1,7 +1,6 @@ // // FILE: radarDemo.ino // AUTHOR: Rob Tillaart -// VERSION: 0.1.1 // PURPOSE: demo of the radar library // DATE: 29-03-2015 // URL: https://github.com/RobTillaart/RADAR diff --git a/libraries/Radar/keywords.txt b/libraries/Radar/keywords.txt index 4d7b7fff..f73c863b 100644 --- a/libraries/Radar/keywords.txt +++ b/libraries/Radar/keywords.txt @@ -1,7 +1,7 @@ -# Syntax Coloring Map for runningAngle +# Syntax Colouring Map for runningAngle -# Datatypes (KEYWORD1) +# Data types (KEYWORD1) runningAngle KEYWORD1 AngleType KEYWORD1 diff --git a/libraries/Radar/library.json b/libraries/Radar/library.json index eec6ccb3..ebf05f2f 100644 --- a/libraries/Radar/library.json +++ b/libraries/Radar/library.json @@ -1,6 +1,6 @@ { "name": "RADAR", - "keywords": "Pan,tilt,radar,ping", + "keywords": "Pan,tilt,radar,ping,position", "description": "Arduino library for a pan tilt radar. Experimental", "authors": [ @@ -15,8 +15,9 @@ "type": "git", "url": "https://github.com/RobTillaart/RADAR" }, - "version": "0.1.5", + "version": "0.1.6", "license": "MIT", "frameworks": "arduino", - "platforms": "*" + "platforms": "*", + "headers": "radar.h" } diff --git a/libraries/Radar/library.properties b/libraries/Radar/library.properties index df7a1ea2..376093d4 100644 --- a/libraries/Radar/library.properties +++ b/libraries/Radar/library.properties @@ -1,5 +1,5 @@ name=RADAR -version=0.1.5 +version=0.1.6 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for a pan tilt radar. diff --git a/libraries/Radar/radar.cpp b/libraries/Radar/radar.cpp index 7d39109d..ef043c39 100644 --- a/libraries/Radar/radar.cpp +++ b/libraries/Radar/radar.cpp @@ -1,16 +1,18 @@ // // FILE: radar.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.5 +// VERSION: 0.1.6 // PURPOSE: Arduino library for a pan tilt 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.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" @@ -60,7 +62,7 @@ int16_t RADAR::getPan() uint32_t movement = round(duration * _panPerSecond * 0.001); 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; return _prevPan - movement; } @@ -87,8 +89,8 @@ int16_t RADAR::getTilt() uint32_t movement = round(duration * _tiltPerSecond * 0.001); if (abs(_tilt - _prevTilt) <= movement) return _tilt; - // estimate TILT by linear interpolation - if (_tilt > _prevTilt) return _prevTilt + movement; + // estimate TILT by linear interpolation + if (_tilt > _prevTilt) return _prevTilt + movement; return _prevTilt - movement; } @@ -100,29 +102,29 @@ void RADAR::gotoPanTilt(const int16_t pan, const int16_t tilt) } -bool RADAR::setPosition(const uint8_t n, const int16_t pan, const int16_t tilt) +bool RADAR::setPosition(const uint8_t index, const int16_t pan, const int16_t tilt) { - if (n >= RADAR_POSITIONS) return false; - _panArray[n] = pan; - _tiltArray[n] = tilt; + if (index >= RADAR_POSITIONS) return false; + _panArray[index] = pan; + _tiltArray[index] = tilt; return true; } -bool RADAR::getPosition(const uint8_t n, int16_t & pan, int16_t & tilt) +bool RADAR::getPosition(const uint8_t index, int16_t & pan, int16_t & tilt) { - if (n >= RADAR_POSITIONS) return false; - pan = _panArray[n]; - tilt = _tiltArray[n]; + if (index >= RADAR_POSITIONS) return false; + pan = _panArray[index]; + tilt = _tiltArray[index]; return true; } -bool RADAR::gotoPosition(const uint8_t n) +bool RADAR::gotoPosition(const uint8_t index) { - if (n >= RADAR_POSITIONS) return false; - gotoPan(_panArray[n]); - gotoTilt(_tiltArray[n]); + if (index >= RADAR_POSITIONS) return false; + gotoPan(_panArray[index]); + gotoTilt(_tiltArray[index]); return true; } @@ -157,7 +159,8 @@ uint32_t RADAR::ping(const int16_t pan, const int16_t tilt) } // PRIVATE -// TODO distill private parts (getPan and getTilt share a lot +// TODO distil private parts (getPan and getTilt share a lot // -- END OF FILE -- + diff --git a/libraries/Radar/radar.h b/libraries/Radar/radar.h index f754b9ab..46dbb48d 100644 --- a/libraries/Radar/radar.h +++ b/libraries/Radar/radar.h @@ -2,7 +2,7 @@ // // FILE: radar.h // AUTHOR: Rob Tillaart -// VERSION: see RADAR_LIB_VERSION +// VERSION: 0.1.6 // PURPOSE: Arduino library for a pan tilt radar. // URL: https://github.com/RobTillaart/RADAR @@ -10,7 +10,7 @@ #include "Arduino.h" -#define RADAR_LIB_VERSION (F("0.1.5")) +#define RADAR_LIB_VERSION (F("0.1.6")) // TODO # positions in a begin() or constructor? @@ -39,9 +39,9 @@ public: // memory positions - store / recall? uint8_t getMaxPositions() { return RADAR_POSITIONS; }; - bool setPosition(const uint8_t idx, const int16_t pan, const int16_t tilt); - bool getPosition(const uint8_t idx, int16_t & pan, int16_t & tilt); - bool gotoPosition(const uint8_t idx); + 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(); @@ -53,21 +53,21 @@ public: // TODO NIY uint32_t ping(); uint32_t ping(const int16_t pan, const int16_t tilt); - + private: int16_t _pinPan; int16_t _pinTilt; - + int16_t _prevPan; int16_t _pan; int16_t _homePan; uint32_t _lastPanTime; - + int16_t _prevTilt; int16_t _tilt; int16_t _homeTilt; uint32_t _lastTiltTime; - + int16_t _panArray[RADAR_POSITIONS]; int16_t _tiltArray[RADAR_POSITIONS]; diff --git a/libraries/Radar/readme.md b/libraries/Radar/readme.md index 17be05c9..ae34ca27 100644 --- a/libraries/Radar/readme.md +++ b/libraries/Radar/readme.md @@ -1,8 +1,11 @@ [![Arduino CI](https://github.com/RobTillaart/Radar/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci) +[![Arduino-lint](https://github.com/RobTillaart/RADAR/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/RADAR/actions/workflows/arduino-lint.yml) +[![JSON check](https://github.com/RobTillaart/RADAR/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/RADAR/actions/workflows/jsoncheck.yml) [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/Radar/blob/master/LICENSE) [![GitHub release](https://img.shields.io/github/release/RobTillaart/Radar.svg?maxAge=3600)](https://github.com/RobTillaart/Radar/releases) + # Radar Arduino library for a pan tilt radar based upon 2 servo's. @@ -11,22 +14,25 @@ Arduino library for a pan tilt radar based upon 2 servo's. ## Warning **WARNING: not extensively tested** -There are stil a lot of things to be tested. +There are still a lot of things to be tested. The example code is now working to show the concept. ## Description -radar is a concept library not elaborated yet that implements a Ping))) based Radar -with the use of two pan/tilt servo's. It was written after a question on the forum but -never finished or tested it. Still, it has some interesting concepts wrt determine -the position of pan/tilt while in progress. +Radar is a concept library (not elaborated) that implements a Ping))) based Radar +with the use of two pan and tilt servo's. +It was written after a question on the Arduino forum but never finished or tested it. +Still, it has some interesting concepts with respect to how to determine the position +of pan/tilt while the movements are in progress. The idea is that one knows how fast the pan and tilt servos are working in degrees per second. From that number and the start moment one can determine approximately its position. Given its position while moving is interesting for radar purposes as one can determine e.g. -in which direction a ping is given and 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 ## Interface @@ -57,9 +63,9 @@ Note: no valid range checking or negative value check. ### memory positions - store / recall? - **uint8_t getMaxPositions()** -- **bool setPosition(const uint8_t idx, const int16_t pan, const int16_t tilt)** -- **bool getPosition(const uint8_t idx, int16_t & pan, int16_t & tilt)** -- **bool gotoPosition(const uint8_t idx)** +- **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()** @@ -76,3 +82,14 @@ Note: no valid range checking or negative value check. See examples +## Future + +- improve documentation. +- test more (e.g. continuous servo versus 180 servo). +- add sketches. +- remember lastPing (angle pan tilt). +- check TODO's in code. +- single servo radar (Pan only) as derived class. +- dynamic allocation of position arrays. + + diff --git a/libraries/Radar/test/unit_test_001.cpp b/libraries/Radar/test/unit_test_001.cpp index aa4996c9..ac4d4a92 100644 --- a/libraries/Radar/test/unit_test_001.cpp +++ b/libraries/Radar/test/unit_test_001.cpp @@ -33,11 +33,12 @@ #include -#include "radar.h" +#include "radar.h" unittest_setup() { + fprintf(stderr, "RADAR_LIB_VERSION: %s\n", (char *) RADAR_LIB_VERSION); } @@ -51,7 +52,7 @@ unittest(test_new_operator) assertEqualINF(exp(800)); assertEqualINF(0.0/0.0); assertEqualINF(42); - + assertEqualNAN(INFINITY - INFINITY); assertEqualNAN(0.0/0.0); assertEqualNAN(42); @@ -61,8 +62,6 @@ unittest(test_new_operator) unittest(test_constructor) { - fprintf(stderr, "VERSION: %s\n", RADAR_LIB_VERSION); - RADAR radar(10, 11); assertEqual(10, radar.getMaxPositions());