mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.1 AngleConvertor
This commit is contained in:
parent
1b628ab9bf
commit
c18b6e9995
@ -6,7 +6,7 @@ jobs:
|
|||||||
lint:
|
lint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: arduino/arduino-lint-action@v1
|
- uses: arduino/arduino-lint-action@v1
|
||||||
with:
|
with:
|
||||||
library-manager: update
|
library-manager: update
|
||||||
|
@ -8,7 +8,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: ruby/setup-ruby@v1
|
- uses: ruby/setup-ruby@v1
|
||||||
with:
|
with:
|
||||||
ruby-version: 2.6
|
ruby-version: 2.6
|
||||||
|
@ -10,7 +10,7 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: json-syntax-check
|
- name: json-syntax-check
|
||||||
uses: limitusus/json-syntax-check@v1
|
uses: limitusus/json-syntax-check@v1
|
||||||
with:
|
with:
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
//
|
//
|
||||||
// FILE: AngleConvertor.h
|
// FILE: AngleConvertor.h
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.0
|
// VERSION: 0.1.1
|
||||||
// DATE: 2022-12-01
|
// DATE: 2022-12-01
|
||||||
// PURPOSE: angle conversion class
|
// PURPOSE: angle conversion class
|
||||||
// URL: https://github.com/RobTillaart/AngleConvertor
|
// URL: https://github.com/RobTillaart/AngleConvertor
|
||||||
@ -11,7 +11,7 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
|
||||||
#define ANGLECONVERTOR_LIB_VERSION (F("0.1.0"))
|
#define ANGLECONVERTOR_LIB_VERSION (F("0.1.1"))
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
@ -71,8 +71,24 @@ public:
|
|||||||
float getTurn() { return _v * (0.5 / M_PI); };
|
float getTurn() { return _v * (0.5 / M_PI); };
|
||||||
|
|
||||||
|
|
||||||
|
// WINDROSE
|
||||||
|
//
|
||||||
|
char * windrose()
|
||||||
|
{
|
||||||
|
return windrose(_v * (180.0 / M_PI));
|
||||||
|
}
|
||||||
|
|
||||||
|
char * windrose(float degrees)
|
||||||
|
{
|
||||||
|
uint8_t idx = (degrees + 11.25) * 0.044444444444444; // 1.0 / 22.5
|
||||||
|
return _wr2[idx];
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float _v; // internal use radians.
|
float _v; // internal use radians.
|
||||||
|
char _wr2[17][4] = {
|
||||||
|
"N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW", "N"};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## [0.1.1] - 2023-01-23
|
||||||
|
- update GitHub actions
|
||||||
|
- update license 2023
|
||||||
|
- update readme
|
||||||
|
- add windrose() (2x)
|
||||||
|
- add example
|
||||||
|
|
||||||
|
|
||||||
## [0.1.0] - 2022-12-01
|
## [0.1.0] - 2022-12-01
|
||||||
- initial version
|
- initial version
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2022-2022 Rob Tillaart
|
Copyright (c) 2022-2023 Rob Tillaart
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -43,7 +43,9 @@ AngleConvertor is an Arduino class to convert an angle from and to less known fo
|
|||||||
| Turn | 1 |
|
| Turn | 1 |
|
||||||
|
|
||||||
|
|
||||||
#### Related to
|
#### Related
|
||||||
|
|
||||||
|
- https://github.com/RobTillaart/AngleConvertor
|
||||||
- https://github.com/RobTillaart/AverageAngle
|
- https://github.com/RobTillaart/AverageAngle
|
||||||
- https://github.com/RobTillaart/Angle
|
- https://github.com/RobTillaart/Angle
|
||||||
- https://github.com/RobTillaart/runningAngle
|
- https://github.com/RobTillaart/runningAngle
|
||||||
@ -51,12 +53,17 @@ AngleConvertor is an Arduino class to convert an angle from and to less known fo
|
|||||||
|
|
||||||
## Interface
|
## Interface
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#include "AngleConvertor.h"
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
#### Constructor
|
#### Constructor
|
||||||
|
|
||||||
- **AngleConvertor()** create an AngleConvertor, default value is zero.
|
- **AngleConvertor()** create an AngleConvertor, default value is zero.
|
||||||
|
|
||||||
|
|
||||||
#### setters
|
#### Setters
|
||||||
|
|
||||||
- **void setDegrees(float value = 0)**
|
- **void setDegrees(float value = 0)**
|
||||||
- **void setRadians(float value = 0)**
|
- **void setRadians(float value = 0)**
|
||||||
@ -80,7 +87,7 @@ AngleConvertor is an Arduino class to convert an angle from and to less known fo
|
|||||||
- **void setTurn(float value = 0)**
|
- **void setTurn(float value = 0)**
|
||||||
|
|
||||||
|
|
||||||
#### getters
|
#### Getters
|
||||||
|
|
||||||
- **float getDegrees()**
|
- **float getDegrees()**
|
||||||
- **float getRadians()**
|
- **float getRadians()**
|
||||||
@ -103,6 +110,18 @@ AngleConvertor is an Arduino class to convert an angle from and to less known fo
|
|||||||
- **float getSign()**
|
- **float getSign()**
|
||||||
- **float getTurn()**
|
- **float getTurn()**
|
||||||
|
|
||||||
|
#### WindRose
|
||||||
|
|
||||||
|
|
||||||
|
From: https://forum.arduino.cc/t/function-optimization-wind-direction-open-for-ideas/92493/10
|
||||||
|
|
||||||
|
Converts an angle in degrees to a char array like "WSW".
|
||||||
|
0 and 360 degrees is considered North.
|
||||||
|
|
||||||
|
- **char \* windrose()** converter version.
|
||||||
|
- **char \* windrose(float degrees)** stand alone version.
|
||||||
|
degrees should be between 0 and 360, as function does no normalization.
|
||||||
|
|
||||||
|
|
||||||
## Operation
|
## Operation
|
||||||
|
|
||||||
@ -111,16 +130,17 @@ See examples.
|
|||||||
|
|
||||||
## Future
|
## Future
|
||||||
|
|
||||||
#### must
|
#### Must
|
||||||
|
|
||||||
- improve documentation
|
- improve documentation
|
||||||
|
|
||||||
#### should
|
#### Should
|
||||||
|
|
||||||
|
|
||||||
#### could
|
#### Could
|
||||||
|
|
||||||
- add dedicated functions == faster (on request only).
|
- add dedicated functions == faster (on request only).
|
||||||
- add more conversions
|
- add more conversions
|
||||||
- integrate with **Angle class** ?
|
- integrate with **Angle class** ?
|
||||||
- printing can be a lot of work
|
- printing can be a lot of work
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,55 @@
|
|||||||
|
//
|
||||||
|
// FILE: AngleConverter_windrose.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;
|
||||||
|
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println(__FILE__);
|
||||||
|
Serial.print("lib version: ");
|
||||||
|
Serial.println(ANGLECONVERTOR_LIB_VERSION);
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
|
||||||
|
for (int angle = 0; angle <= 360; angle += 5)
|
||||||
|
{
|
||||||
|
Serial.print(angle);
|
||||||
|
Serial.print("\t");
|
||||||
|
Serial.print(conv.windrose(angle));
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
Serial.println();
|
||||||
|
delay(100);
|
||||||
|
|
||||||
|
start = micros();
|
||||||
|
conv.setDegrees(127.876);
|
||||||
|
char * p = conv.windrose();
|
||||||
|
stop = micros();
|
||||||
|
|
||||||
|
Serial.print("WINDROSE TIME: \t");
|
||||||
|
Serial.println(stop - start);
|
||||||
|
Serial.print("WINDROSE DIR: \t");
|
||||||
|
Serial.println(p);
|
||||||
|
|
||||||
|
Serial.println("\nDone...");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -- END OF FILE --
|
@ -53,6 +53,10 @@ getSextant KEYWORD2
|
|||||||
getSign KEYWORD2
|
getSign KEYWORD2
|
||||||
getTurn KEYWORD2
|
getTurn KEYWORD2
|
||||||
|
|
||||||
|
# Windrose
|
||||||
|
|
||||||
|
windrose KEYWORD2
|
||||||
|
|
||||||
|
|
||||||
# Constants (LITERAL1)
|
# Constants (LITERAL1)
|
||||||
ANGLECONVERTOR_LIB_VERSION LITERAL1
|
ANGLECONVERTOR_LIB_VERSION LITERAL1
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "AngleConvertor",
|
"name": "AngleConvertor",
|
||||||
"keywords": "Angle,convert,degrees,radians",
|
"keywords": "Angle,convert,degrees,radians,windrose",
|
||||||
"description": "Library to convert between different less known angle formats.",
|
"description": "Library to convert between different less known angle formats.",
|
||||||
"authors":
|
"authors":
|
||||||
[
|
[
|
||||||
@ -15,7 +15,7 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/RobTillaart/AngleConvertor.git"
|
"url": "https://github.com/RobTillaart/AngleConvertor.git"
|
||||||
},
|
},
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"platforms": "*",
|
"platforms": "*",
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
name=AngleConvertor
|
name=AngleConvertor
|
||||||
version=0.1.0
|
version=0.1.1
|
||||||
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=Library to convert between different less known angle formats.
|
sentence=Library to convert between different less known angle formats.
|
||||||
paragraph=
|
paragraph=degrees,radians,gradians,windrose
|
||||||
category=Data Processing
|
category=Data Processing
|
||||||
url=https://github.com/RobTillaart/AngleConvertor
|
url=https://github.com/RobTillaart/AngleConvertor
|
||||||
architectures=*
|
architectures=*
|
||||||
|
@ -42,6 +42,7 @@ unittest_setup()
|
|||||||
fprintf(stderr, "ANGLECONVERTOR_LIB_VERSION: %s\n", (char *) ANGLECONVERTOR_LIB_VERSION);
|
fprintf(stderr, "ANGLECONVERTOR_LIB_VERSION: %s\n", (char *) ANGLECONVERTOR_LIB_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unittest_teardown()
|
unittest_teardown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -115,4 +116,6 @@ unittest(test_conversions)
|
|||||||
|
|
||||||
unittest_main()
|
unittest_main()
|
||||||
|
|
||||||
|
|
||||||
// -- END OF FILE --
|
// -- END OF FILE --
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user