0.1.0 moduloMap

This commit is contained in:
rob tillaart 2022-10-21 12:17:48 +02:00
parent 93deb0313a
commit 003a7a9483
16 changed files with 467 additions and 0 deletions

View File

@ -0,0 +1,27 @@
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,13 @@
# Change Log moduloMap
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-10-15
- initial version (experimental)

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,62 @@
[![Arduino CI](https://github.com/RobTillaart/moduloMap/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/moduloMap/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/moduloMap/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/moduloMap/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/moduloMap/actions/workflows/jsoncheck.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/moduloMap/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/moduloMap.svg?maxAge=3600)](https://github.com/RobTillaart/moduloMap/releases)
# moduloMap
Arduino library for the moduloMap class.
## Description
The moduloMap is an experimental library that optimizes modular mapping.
What is modular mapping?
Imagine the mapping of all real numbers on a subset in a modular way.
E.g. map all the real numbers to \[7; 13> that is module 6, with numbers 7..13 do not change as they are already in the range.
6 is mapped on 12, 5 on 11, 4 on 10, .. 1 on 7, 0 on 12 -1 on 11 etc.
Imagine a line rolled around a circle.
Better known example is the modular mapping of angles.
This can be on 0-360 degrees or 0-2PI radians or -180-180 degrees
or even -90..270 degrees.
Other name might be circular mapping.
## Version
0.1.0 is initial version, the reference implementation.
## Interface
- **moduloMap()** constructor.
- **void begin(float minimum, float maximum)**
- **float map(float value)**
## Operation
The examples show the basic working of the functions.
## Future
- elaborate documentation
- optimize performance
- add examples
- move code to .cpp file
- add changelog.md
- add performance test
- are there other than circular modulos
- triangular, fractal?
- add link to related libraries
- angles + fastmap?
- elaborate API.

View File

@ -0,0 +1,53 @@
//
// FILE: moduloMap_demo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// URL: https://github.com/RobTillaart/moduloMap
#include "Arduino.h"
#include "moduloMap.h"
MODMAP mm;
void setup()
{
Serial.begin(115200);
while (!Serial);
Serial.println(__FILE__);
Serial.print("MODMAP_LIB_VERSION: ");
Serial.println(MODMAP_LIB_VERSION);
mm.begin(PI, 2 * PI);
for (int i = 0; i < 20; i++)
{
Serial.print(i);
Serial.print('\t');
Serial.print(mm.map(i), 5);
Serial.println();
}
Serial.println();
for (int i = 0; i < 20; i++)
{
uint32_t r = random(1000000);
Serial.print(r);
Serial.print('\t');
Serial.print(mm.map(r), 5);
Serial.println();
}
Serial.println();
Serial.println("\ndone...");
}
void loop()
{
}
// -- END OF FILE --

View File

@ -0,0 +1,59 @@
//
// FILE: moduloMap_demo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// URL: https://github.com/RobTillaart/moduloMap
#include "Arduino.h"
#include "moduloMap.h"
MODMAP mm;
uint32_t start, stop;
volatile float f;
void setup()
{
Serial.begin(115200);
while (!Serial);
Serial.println(__FILE__);
Serial.print("MODMAP_LIB_VERSION: ");
Serial.println(MODMAP_LIB_VERSION);
delay(100);
start = micros();
mm.begin(PI, 2 * PI);
stop = micros();
Serial.print("begin() call:\t");
Serial.println(stop - start);
delay(100);
start = micros();
for (int i = 0; i < 1000; i++)
{
f = mm.map(i);
}
stop = micros();
Serial.print("1000 map() calls:\t");
Serial.println(stop - start);
delay(100);
Serial.println();
Serial.println("\ndone...");
}
void loop()
{
}
// -- END OF FILE --

View File

@ -0,0 +1,12 @@
IDE: 1.8.19
board: UNO
...\moduloMap_performance.ino
MODMAP_LIB_VERSION: 0.1.0
begin() call: 8
1000 map() calls: 44120

View File

@ -0,0 +1,15 @@
# Syntax Colouring Map For moduloMap
# Data types (KEYWORD1)
moduloMap KEYWORD1
# Methods and Functions (KEYWORD2)
begin KEYWORD2
map KEYWORD2
# Constants (LITERAL1)
MODMAP_LIB_VERSION LITERAL1

View File

@ -0,0 +1,23 @@
{
"name": "moduloMap",
"keywords": "fmod, map, circular mapping",
"description": "Arduino library for the moduloMap class.",
"authors":
[
{
"name": "Rob Tillaart",
"email": "Rob.Tillaart@gmail.com",
"maintainer": true
}
],
"repository":
{
"type": "git",
"url": "https://github.com/RobTillaart/moduloMap.git"
},
"version": "0.1.0",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",
"headers": "moduloMap.h"
}

View File

@ -0,0 +1,11 @@
name=moduloMap
version=0.1.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for modulo mapping
paragraph=
category=Data Processing
url=https://github.com/RobTillaart/moduloMap
architectures=*
includes=moduloMap.h
depends=

View File

@ -0,0 +1,59 @@
#pragma once
//
// FILE: moduloMap.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: Arduino library for modulo mapping
// DATE: 2022-10-15
// URL: https://github.com/RobTillaart/moduloMap
#include "Arduino.h"
#define MODMAP_LIB_VERSION (F("0.1.0"))
class MODMAP
{
public:
MODMAP()
{
}
void begin(float minimum, float maximum)
{
_minimum = minimum;
_maximum = maximum;
_range = maximum - _minimum;
}
float map(float value)
{
if ((_minimum <= value) && (value < _maximum)) return value;
float mm = fmod((value - _minimum), _range) + _minimum;
if (mm < _minimum) mm += _range;
return mm;
}
/* for debugging
float reference(float value)
{
if ((_minimum <= value) && (value < _maximum)) return value;
float mm = fmod((value - minimum), _range) + _minimum;
if (mm < _minimum) mm += _range;
return mm;
}
*/
private:
float _minimum = 0;
float _maximum = 1;
float _range = 1;
};
// --- END OF FILE ---

View File

@ -0,0 +1,60 @@
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// DATE: 2022-10-20
// PURPOSE: unit tests for Arduino library for modulo mapping
// https://github.com/RobTillaart/moduloMap
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
//
// supported assertions
// ----------------------------
// assertEqual(expected, actual)
// assertNotEqual(expected, actual)
// assertLess(expected, actual)
// assertMore(expected, actual)
// assertLessOrEqual(expected, actual)
// assertMoreOrEqual(expected, actual)
// assertTrue(actual)
// assertFalse(actual)
// assertNull(actual)
#include <ArduinoUnitTests.h>
#include "Arduino.h"
#include "moduloMap.h"
unittest_setup()
{
fprintf(stderr, "MODMAP_LIB_VERSION: %s\n", (char *) MODMAP_LIB_VERSION);
}
unittest_teardown()
{
}
unittest(test_constants)
{
assertEqual(1, 1);
}
unittest(test_map)
{
// to elaborate
MODMAP mm;
mm.begin(0, 1);
float x = mm.map(25.3);
assertEqualFloat(0.3, x, 0.001);
}
unittest_main()
// -- END OF FILE --