0.1.0 AngleConvertor

This commit is contained in:
rob tillaart 2022-12-07 20:19:21 +01:00
parent 5b2bc91a61
commit b10003de0e
15 changed files with 706 additions and 0 deletions

View File

@ -0,0 +1,28 @@
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:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
# - due
# - zero
# - leonardo
- m4
- esp32
- esp8266
# - mega2560
- rpipico

View File

@ -0,0 +1,4 @@
# These are supported funding model platforms
github: RobTillaart

View File

@ -0,0 +1,13 @@
name: Arduino-lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
compliance: strict

View File

@ -0,0 +1,17 @@
---
name: Arduino CI
on: [push, pull_request]
jobs:
runTest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb

View File

@ -0,0 +1,18 @@
name: JSON check
on:
push:
paths:
- '**.json'
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:
pattern: "\\.json$"

View File

@ -0,0 +1,80 @@
#pragma once
//
// FILE: AngleConvertor.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// DATE: 2022-12-01
// PURPOSE: angle conversion class
// URL: https://github.com/RobTillaart/AngleCOnvertor
#include "Arduino.h"
#define ANGLECONVERTOR_LIB_VERSION (F("0.1.0"))
/////////////////////////////////////////////////////////////
//
// ANGLE CONVERTER CLASS
//
class AngleConvertor
{
public:
AngleConvertor() { _v = 0; };
// SETTERS
void setDegrees(float value = 0) { _v = value * (M_PI / 180.0); };
void setRadians(float value = 0) { _v = value; };
void setGradians(float value = 0) { _v = value * (M_PI / 200.0); };
void setAngularMil(float value = 0) { _v = value * (M_PI / 3200.0); };
void setBinaryRadians(float value = 0) { _v = value * (M_PI / 128.0); };
void setCentiTurn(float value = 0) { _v = value * (M_PI / 50.0); };
void setDiameterPart(float value = 0) { _v = value * (M_PI / 60.0); };
void setHexacontade(float value = 0) { _v = value * (M_PI / 30.0); };
void setHourAngle(float value = 0) { _v = value * (M_PI / 12.0); };
void setMilliTurn(float value = 0) { _v = value * (M_PI / 500.0); };
void setMinuteTime(float value = 0) { _v = value * (M_PI / 720.0); };
void setOctant(float value = 0) { _v = value * (M_PI / 4.0); };
void setPechus(float value = 0) { _v = value * (M_PI / 90.0); }; // assumes 2°
void setPoints(float value = 0) { _v = value * (M_PI / 16.0); };
void setQuadrant(float value = 0) { _v = value * (M_PI / 2.0); };
void setQuarterPoint(float value = 0) { _v = value * (M_PI / 64.0); };
void setSecondsTime(float value = 0) { _v = value * (M_PI / 43200); };
void setSextant(float value = 0) { _v = value * (M_PI / 3.0); };
void setSign(float value = 0) { _v = value * (M_PI / 6.0); };
void setTurn(float value = 0) { _v = value * (M_PI / 0.5); };
// GETTERS
float getDegrees() { return _v * (180.0 / M_PI); };
float getRadians() { return _v; };
float getGradians() { return _v * (200.0 / M_PI); };
float getAngularMil() { return _v * (3200.0 / M_PI); };
float getBinaryRadians() { return _v * (128.0 / M_PI); };
float getCentiTurn() { return _v * (50.0 / M_PI); };
float getDiameterPart() { return _v * (60.0 / M_PI); };
float getHexacontade() { return _v * (30.0 / M_PI); };
float getHourAngle() { return _v * (12.0 / M_PI); };
float getMilliTurn() { return _v * (500.0 / M_PI); };
float getMinuteTime() { return _v * (720.0 / M_PI); };
float getOctant() { return _v * (4.0 / M_PI); };
float getPechus() { return _v * (90.0 / M_PI); }; // assumes 2°
float getPoints() { return _v * (16.0 / M_PI); };
float getQuadrant() { return _v * (2.0 / M_PI); };
float getQuarterPoint() { return _v * (64.0 / M_PI); };
float getSecondsTime() { return _v * (43200 / M_PI); };
float getSextant() { return _v * (3.0 / M_PI); };
float getSign() { return _v * (6.0 / M_PI); };
float getTurn() { return _v * (0.5 / M_PI); };
private:
float _v; // internal use radians.
};
// -- END OF FILE --

View File

@ -0,0 +1,12 @@
# Change Log Angle
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.0] - 2022-12-01
- initial version

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022-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
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,126 @@
[![Arduino CI](https://github.com/RobTillaart/AngleConvertor/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/AngleConvertor/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/AngleConvertor/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/AngleConvertor/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/AngleConvertor/actions/workflows/jsoncheck.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/AngleConvertor/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/AngleConvertor.svg?maxAge=3600)](https://github.com/RobTillaart/AngleConvertor/releases)
# AngleConvertor
Arduino library for converting angles (degrees/radians) to less known formats.
## Description
AngleConvertor is an Arduino class to convert an angle from and to less known formats.
#### Formats
| name | full circle |
|:----------------|--------------:|
| Degrees | 360 |
| Radians | 2 PI |
| Gradians | 400 |
| AngularMil | 6400 |
| BinaryRadians | 256 |
| CentiTurn | 100 |
| DiameterPart | 120 |
| Hexacontade | 60 |
| HourAngle | 24 |
| MilliTurn | 1000 |
| MinuteTime | 1440 |
| Octant | 8 |
| Pechus | 180 |
| Points | 32 |
| Quadrant | 4 |
| QuarterPoint | 128 |
| SecondsTime | 86400 |
| Sextant | 6 |
| Sign | 12 |
| Turn | 1 |
#### Related to
- https://github.com/RobTillaart/AverageAngle
- https://github.com/RobTillaart/Angle
- https://github.com/RobTillaart/runningAngle
## Interface
#### Constructor
- **AngleConvertor()** create an AngleConvertor, default value is zero.
#### setters
- **void setDegrees(float value = 0)**
- **void setRadians(float value = 0)**
- **void setGradians(float value = 0)**
- **void setAngularMil(float value = 0)**
- **void setBinaryRadians(float value = 0)**
- **void setCentiTurn(float value = 0)**
- **void setDiameterPart(float value = 0)**
- **void setHexacontade(float value = 0)**
- **void setHourAngle(float value = 0)**
- **void setMilliTurn(float value = 0)**
- **void setMinuteTime(float value = 0)**
- **void setOctant(float value = 0)**
- **void setPechus(float value = 0)**
- **void setPoints(float value = 0)**
- **void setQuadrant(float value = 0)**
- **void setQuarterPoint(float value = 0)**
- **void setSecondsTime(float value = 0)**
- **void setSextant(float value = 0)**
- **void setSign(float value = 0)**
- **void setTurn(float value = 0)**
#### getters
- **float getDegrees()**
- **float getRadians()**
- **float getGradians()**
- **float getAngularMil()**
- **float getBinaryRadians()**
- **float getCentiTurn()**
- **float getDiameterPart()**
- **float getHexacontade()**
- **float getHourAngle()**
- **float getMilliTurn()**
- **float getMinuteTime()**
- **float getOctant()**
- **float getPechus()**
- **float getPoints()**
- **float getQuadrant()**
- **float getQuarterPoint()**
- **float getSecondsTime()**
- **float getSextant()**
- **float getSign()**
- **float getTurn()**
## Operation
See examples.
## Future
#### must
- improve documentation
#### should
#### could
- add dedicated functions == faster (on request only).
- add more conversions
- integrate with **Angle class** ?
- printing can be a lot of work

View File

@ -0,0 +1,132 @@
//
// FILE: AngleConverter_demo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo sketch to test angleConvertor class
// DATE: 2022-12-01
// URL: https://github.com/RobTillaart/AngleConvertor
//
#include "AngleConvertor.h"
AngleConvertor conv;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("lib version: ");
Serial.println(ANGLECONVERTOR_LIB_VERSION);
Serial.println();
conv.setDegrees(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getDegrees(), 7);
conv.setRadians(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getRadians(), 7);
conv.setGradians(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getGradians(), 7);
conv.setAngularMil(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getAngularMil(), 7);
conv.setBinaryRadians(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getBinaryRadians(), 7);
conv.setCentiTurn(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getCentiTurn(), 7);
conv.setDiameterPart(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getDiameterPart(), 7);
conv.setHexacontade(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getHexacontade(), 7);
conv.setHourAngle(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getHourAngle(), 7);
conv.setMilliTurn(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getMilliTurn(), 7);
conv.setMinuteTime(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getMinuteTime(), 7);
conv.setOctant(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getOctant(), 7);
conv.setPechus(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getPechus(), 7);
conv.setPoints(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getPoints(), 7);
conv.setQuadrant(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getQuadrant(), 7);
conv.setQuarterPoint(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getQuarterPoint(), 7);
conv.setSecondsTime(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getSecondsTime(), 7);
conv.setSextant(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getSextant(), 7);
conv.setSign(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getSign(), 7);
conv.setTurn(1.0);
Serial.print(conv.getRadians(), 7);
Serial.print("\t");
Serial.println(conv.getTurn(), 7);
Serial.println("\nDone...");
}
void loop()
{
}
// -- END OF FILE --

View File

@ -0,0 +1,44 @@
//
// FILE: AngleConverter_performance.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo sketch to test angleConvertor class
// DATE: 2022-12-01
// URL: https://github.com/RobTillaart/AngleConvertor
//
#include "AngleConvertor.h"
AngleConvertor conv;
uint32_t start, stop;
volatile float x;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("lib version: ");
Serial.println(ANGLECONVERTOR_LIB_VERSION);
Serial.println();
delay(10);
start = micros();
conv.setDegrees(1.2345);
x = conv.getTurn();
stop = micros();
Serial.print("TIME: \t");
Serial.println(stop - start); // 2 steps
Serial.println("\nDone...");
}
void loop()
{
}
// -- END OF FILE --

View File

@ -0,0 +1,59 @@
# Syntax Colouring Map For AngleConvertor
# Data types (KEYWORD1)
AngleConvertor KEYWORD1
# Methods and Functions (KEYWORD2)
# setters
setDegrees KEYWORD2
setRadians KEYWORD2
setGradians KEYWORD2
setAngularMil KEYWORD2
setBinaryRadians KEYWORD2
setCentiTurn KEYWORD2
setDiameterPart KEYWORD2
setHexacontade KEYWORD2
setHourAngle KEYWORD2
setMilliTurn KEYWORD2
setMinuteTime KEYWORD2
setOctant KEYWORD2
setPechus KEYWORD2
setPoints KEYWORD2
setQuadrant KEYWORD2
setQuarterPoint KEYWORD2
setSecondsTime KEYWORD2
setSextant KEYWORD2
setSign KEYWORD2
setTurn KEYWORD2
# getters
getDegrees KEYWORD2
getRadians KEYWORD2
getGradians KEYWORD2
getAngularMil KEYWORD2
getBinaryRadians KEYWORD2
getCentiTurn KEYWORD2
getDiameterPart KEYWORD2
getHexacontade KEYWORD2
getHourAngle KEYWORD2
getMilliTurn KEYWORD2
getMinuteTime KEYWORD2
getOctant KEYWORD2
getPechus KEYWORD2
getPoints KEYWORD2
getQuadrant KEYWORD2
getQuarterPoint KEYWORD2
getSecondsTime KEYWORD2
getSextant KEYWORD2
getSign KEYWORD2
getTurn KEYWORD2
# Constants (LITERAL1)
ANGLECONVERTOR_LIB_VERSION LITERAL1

View File

@ -0,0 +1,23 @@
{
"name": "AngleConvertor",
"keywords": "Angle,convert,degrees,radians",
"description": "Library to convert between different less known angle formats.",
"authors":
[
{
"name": "Rob Tillaart",
"email": "Rob.Tillaart@gmail.com",
"maintainer": true
}
],
"repository":
{
"type": "git",
"url": "https://github.com/RobTillaart/AngleConvertor.git"
},
"version": "0.1.0",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",
"headers": "AngleConvertor.h"
}

View File

@ -0,0 +1,11 @@
name=AngleConvertor
version=0.1.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Library to convert between different less known angle formats.
paragraph=
category=Data Processing
url=https://github.com/RobTillaart/AngleConvertor
architectures=*
includes=AngleConvertor.h
depends=

View File

@ -0,0 +1,118 @@
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// DATE: 2022-12-03
// PURPOSE: unit tests for the Angle library
// https://github.com/RobTillaart/AngleConvertor
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
//
// supported assertions
// ----------------------------
// assertEqual(expected, actual); // a == b
// assertNotEqual(unwanted, actual); // a != b
// assertComparativeEquivalent(expected, actual); // abs(a - b) == 0 or (!(a > b) && !(a < b))
// assertComparativeNotEquivalent(unwanted, actual); // abs(a - b) > 0 or ((a > b) || (a < b))
// assertLess(upperBound, actual); // a < b
// assertMore(lowerBound, actual); // a > b
// assertLessOrEqual(upperBound, actual); // a <= b
// assertMoreOrEqual(lowerBound, actual); // a >= b
// assertTrue(actual);
// assertFalse(actual);
// assertNull(actual);
// // special cases for floats
// assertEqualFloat(expected, actual, epsilon); // fabs(a - b) <= epsilon
// assertNotEqualFloat(unwanted, actual, epsilon); // fabs(a - b) >= epsilon
// assertInfinity(actual); // isinf(a)
// assertNotInfinity(actual); // !isinf(a)
// assertNAN(arg); // isnan(a)
// assertNotNAN(arg); // !isnan(a)
#include <ArduinoUnitTests.h>
#include "Arduino.h"
#include "AngleConvertor.h"
unittest_setup()
{
fprintf(stderr, "ANGLECONVERTOR_LIB_VERSION: %s\n", (char *) ANGLECONVERTOR_LIB_VERSION);
}
unittest_teardown()
{
}
unittest(test_conversions)
{
AngleConvertor conv;
conv.setDegrees(1.0);
assertEqualFloat(1.0, conv. getDegrees(), 0.00001);
conv.setRadians(1.0);
assertEqualFloat(1.0, conv. getRadians(), 0.00001);
conv.setGradians(1.0);
assertEqualFloat(1.0, conv. getGradians(), 0.00001);
conv.setAngularMil(1.0);
assertEqualFloat(1.0, conv. getAngularMil(), 0.00001);
conv.setBinaryRadians(1.0);
assertEqualFloat(1.0, conv. getBinaryRadians(), 0.00001);
conv.setCentiTurn(1.0);
assertEqualFloat(1.0, conv. getCentiTurn(), 0.00001);
conv.setDiameterPart(1.0);
assertEqualFloat(1.0, conv. getDiameterPart(), 0.00001);
conv.setHexacontade(1.0);
assertEqualFloat(1.0, conv. getHexacontade(), 0.00001);
conv.setHourAngle(1.0);
assertEqualFloat(1.0, conv. getHourAngle(), 0.00001);
conv.setMilliTurn(1.0);
assertEqualFloat(1.0, conv. getMilliTurn(), 0.00001);
conv.setMinuteTime(1.0);
assertEqualFloat(1.0, conv. getMinuteTime(), 0.00001);
conv.setOctant(1.0);
assertEqualFloat(1.0, conv. getOctant(), 0.00001);
conv.setPechus(1.0);
assertEqualFloat(1.0, conv. getPechus(), 0.00001);
conv.setPoints(1.0);
assertEqualFloat(1.0, conv. getPoints(), 0.00001);
conv.setQuadrant(1.0);
assertEqualFloat(1.0, conv. getQuadrant(), 0.00001);
conv.setQuarterPoint(1.0);
assertEqualFloat(1.0, conv. getQuarterPoint(), 0.00001);
conv.setSecondsTime(1.0);
assertEqualFloat(1.0, conv. getSecondsTime(), 0.00001);
conv.setSextant(1.0);
assertEqualFloat(1.0, conv. getSextant(), 0.00001);
conv.setSign(1.0);
assertEqualFloat(1.0, conv. getSign(), 0.00001);
conv.setTurn(1.0);
assertEqualFloat(1.0, conv. getTurn(), 0.00001);
}
unittest_main()
// -- END OF FILE --