clean-up
BIN
SCH/datasheet/JGA25-370 draw2.webp
Normal file
|
After Width: | Height: | Size: 55 KiB |
BIN
SCH/datasheet/drv8871.pdf
Normal file
|
Before Width: | Height: | Size: 1005 KiB |
|
Before Width: | Height: | Size: 308 KiB |
|
Before Width: | Height: | Size: 247 KiB |
BIN
SCH/datasheet/hall-wires.jpg
Normal file
|
After Width: | Height: | Size: 84 KiB |
BIN
SCH/datasheet/jga25-370 draw.jpg
Normal file
|
After Width: | Height: | Size: 224 KiB |
BIN
SCH/datasheet/jga25-370 spec.jpg
Normal file
|
After Width: | Height: | Size: 230 KiB |
18
SCH/datasheet/jga25-spec.txt
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
DC12V 25GA370 Grote Koppel Speed Reductormotorgroep met Toerenteller Encoder
|
||||||
|
Specificatie:
|
||||||
|
Voltage: DC6V 12V 24V
|
||||||
|
Onbelast Toerental: 12RPM, 16RPM, 35RPM, 60RPM, 77RPM, 130RPM, 170RPM, 280RPM, 620RPM, 1360RPM
|
||||||
|
Fout: ± 5%
|
||||||
|
Motor Diameter: 24.5mm
|
||||||
|
Motor Lichaam Lengte: 40mm(ref)
|
||||||
|
Uitgaande As Diameter: 4mm(D-type)
|
||||||
|
Uitgaande As Lengte: ongeveer 9.5mm
|
||||||
|
Versnellingsbak Diameter: 25mm
|
||||||
|
Versnellingsbak Size Detal, zie de tabel
|
||||||
|
Bedradingen:
|
||||||
|
Rode Draad-positieve voeding van motor(+)(veranderen positieve en negatieve van motor de rotatie zal veranderen)
|
||||||
|
Witte Draad-negatieve voeding van motor(-)(veranderen positieve en negatieve van motor de rotatie zal veranderen))
|
||||||
|
Gele Draad-signaal feedback (motor een turn heeft 11 signalen)
|
||||||
|
Groene Draad-signaal feedback (motor een turn heeft 11 signalen)
|
||||||
|
Blauwe Draad-positieve van encoder voeding (+)(3.3-5V), kan niet worden verkeerde
|
||||||
|
Zwarte Draad-negatieve van encoder voeding (-)(3.3-5V), kan niet worden verkeerde
|
||||||
5
blinds/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
||||||
39
blinds/include/README
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
|
||||||
|
This directory is intended for project header files.
|
||||||
|
|
||||||
|
A header file is a file containing C declarations and macro definitions
|
||||||
|
to be shared between several project source files. You request the use of a
|
||||||
|
header file in your project source file (C, C++, etc) located in `src` folder
|
||||||
|
by including it, with the C preprocessing directive `#include'.
|
||||||
|
|
||||||
|
```src/main.c
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Including a header file produces the same results as copying the header file
|
||||||
|
into each source file that needs it. Such copying would be time-consuming
|
||||||
|
and error-prone. With a header file, the related declarations appear
|
||||||
|
in only one place. If they need to be changed, they can be changed in one
|
||||||
|
place, and programs that include the header file will automatically use the
|
||||||
|
new version when next recompiled. The header file eliminates the labor of
|
||||||
|
finding and changing all the copies as well as the risk that a failure to
|
||||||
|
find one copy will result in inconsistencies within a program.
|
||||||
|
|
||||||
|
In C, the usual convention is to give header files names that end with `.h'.
|
||||||
|
It is most portable to use only letters, digits, dashes, and underscores in
|
||||||
|
header file names, and at most one dot.
|
||||||
|
|
||||||
|
Read more about using header files in official GCC documentation:
|
||||||
|
|
||||||
|
* Include Syntax
|
||||||
|
* Include Operation
|
||||||
|
* Once-Only Headers
|
||||||
|
* Computed Includes
|
||||||
|
|
||||||
|
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||||
46
blinds/lib/README
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
This directory is intended for project specific (private) libraries.
|
||||||
|
PlatformIO will compile them to static libraries and link into executable file.
|
||||||
|
|
||||||
|
The source code of each library should be placed in a an own separate directory
|
||||||
|
("lib/your_library_name/[here are source files]").
|
||||||
|
|
||||||
|
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||||
|
|
||||||
|
|--lib
|
||||||
|
| |
|
||||||
|
| |--Bar
|
||||||
|
| | |--docs
|
||||||
|
| | |--examples
|
||||||
|
| | |--src
|
||||||
|
| | |- Bar.c
|
||||||
|
| | |- Bar.h
|
||||||
|
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||||
|
| |
|
||||||
|
| |--Foo
|
||||||
|
| | |- Foo.c
|
||||||
|
| | |- Foo.h
|
||||||
|
| |
|
||||||
|
| |- README --> THIS FILE
|
||||||
|
|
|
||||||
|
|- platformio.ini
|
||||||
|
|--src
|
||||||
|
|- main.c
|
||||||
|
|
||||||
|
and a contents of `src/main.c`:
|
||||||
|
```
|
||||||
|
#include <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
PlatformIO Library Dependency Finder will find automatically dependent
|
||||||
|
libraries scanning project source files.
|
||||||
|
|
||||||
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||||
22
blinds/platformio.ini
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:esp32-c3]
|
||||||
|
platform = espressif32
|
||||||
|
board = lolin_c3_mini
|
||||||
|
framework = arduino
|
||||||
|
monitor_speed = 115200
|
||||||
|
lib_deps =
|
||||||
|
#gyverlibs/AccelMotor@^1.3
|
||||||
|
#simplefoc/SimpleDCMotor@^1.0.1
|
||||||
|
lib_ldf_mode = deep+
|
||||||
|
build_flags =
|
||||||
|
-DCORE_DEBUG_LEVEL=3
|
||||||
|
-DNDEF_DEBUG=1
|
||||||
290
blinds/src/main.cpp
Normal file
@@ -0,0 +1,290 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Automatic Addison
|
||||||
|
* Website: https://automaticaddison.com
|
||||||
|
* Description: Calculate the angular velocity in radians/second of a DC motor
|
||||||
|
* with a built-in encoder (forward = positive; reverse = negative)
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Motor encoder output pulses per 360 degree revolution (measured manually)
|
||||||
|
#define ENC_COUNT_REV (500 * 11) //12rmp motor
|
||||||
|
|
||||||
|
// Encoder output to Arduino Interrupt pin. Tracks the pulse count.
|
||||||
|
#define ENC_IN_RIGHT_A 10
|
||||||
|
|
||||||
|
// Other encoder output to Arduino to keep track of wheel direction
|
||||||
|
// Tracks the direction of rotation.
|
||||||
|
#define ENC_IN_RIGHT_B 9
|
||||||
|
|
||||||
|
#define MOTOR_IN1 6
|
||||||
|
#define MOTOR_IN2 7
|
||||||
|
|
||||||
|
#define SPEED 92
|
||||||
|
|
||||||
|
#define POWERMETER 4
|
||||||
|
|
||||||
|
// True = Forward; False = Reverse
|
||||||
|
bool Direction_right = true;
|
||||||
|
|
||||||
|
// Keep track of the number of right wheel pulses
|
||||||
|
volatile long right_wheel_pulse_count = 0;
|
||||||
|
volatile long pulscountswap = 0;
|
||||||
|
volatile long absPulseCount = 0;
|
||||||
|
|
||||||
|
// One-second interval for measurements
|
||||||
|
int interval = 1000;
|
||||||
|
int swapdelay = 500;
|
||||||
|
|
||||||
|
// Counters for milliseconds during interval
|
||||||
|
long previousMillis = 0;
|
||||||
|
long currentMillis = 0;
|
||||||
|
|
||||||
|
// Variable for RPM measuerment
|
||||||
|
float rpm_right = 0;
|
||||||
|
|
||||||
|
// Variable for angular velocity measurement
|
||||||
|
float ang_velocity_right = 0;
|
||||||
|
float ang_velocity_right_deg = 0;
|
||||||
|
|
||||||
|
const float rpm_to_radians = 0.10471975512;
|
||||||
|
const float rad_to_deg = 57.29578;
|
||||||
|
bool dir = false;
|
||||||
|
bool motorruns = false;
|
||||||
|
|
||||||
|
void right_wheel_pulse();
|
||||||
|
|
||||||
|
|
||||||
|
// ***** function calls ******
|
||||||
|
float getVPP()
|
||||||
|
{
|
||||||
|
float result;
|
||||||
|
int readValue; // value read from the sensor
|
||||||
|
int maxValue = 0; // store max value here
|
||||||
|
int minValue = 4096; // store min value here ESP32 ADC resolution
|
||||||
|
|
||||||
|
uint32_t start_time = millis();
|
||||||
|
while((millis()-start_time) < 1000) //sample for 1 Sec
|
||||||
|
{
|
||||||
|
readValue = analogRead(POWERMETER);
|
||||||
|
// see if you have a new maxValue
|
||||||
|
if (readValue > maxValue)
|
||||||
|
{
|
||||||
|
/*record the maximum sensor value*/
|
||||||
|
maxValue = readValue;
|
||||||
|
}
|
||||||
|
if (readValue < minValue)
|
||||||
|
{
|
||||||
|
/*record the minimum sensor value*/
|
||||||
|
minValue = readValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Subtract min from max
|
||||||
|
result = ((maxValue - minValue) * 3.3)/4096.0; //ESP32 ADC resolution 4096
|
||||||
|
log_i("ADC: %0.0f", result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void run_stop()
|
||||||
|
{
|
||||||
|
digitalWrite(MOTOR_IN1, LOW);
|
||||||
|
digitalWrite(MOTOR_IN2, LOW);
|
||||||
|
analogWrite(MOTOR_IN1, 0);
|
||||||
|
analogWrite(MOTOR_IN2, 0);
|
||||||
|
motorruns = false;
|
||||||
|
log_i("stop");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void run_to()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void run_left(int speed = SPEED)
|
||||||
|
{
|
||||||
|
// run_stop();
|
||||||
|
// delay(swapdelay);
|
||||||
|
digitalWrite(MOTOR_IN1, LOW);
|
||||||
|
analogWrite(MOTOR_IN2, speed);
|
||||||
|
log_i("left");
|
||||||
|
motorruns = true;
|
||||||
|
dir = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void run_right(int speed = SPEED)
|
||||||
|
{
|
||||||
|
// run_stop();
|
||||||
|
// delay(swapdelay);
|
||||||
|
digitalWrite(MOTOR_IN2, LOW);
|
||||||
|
analogWrite(MOTOR_IN1, speed);
|
||||||
|
log_i("right");
|
||||||
|
motorruns = true;
|
||||||
|
dir = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool run_to_pos()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void swap_dir()
|
||||||
|
{
|
||||||
|
if(dir)
|
||||||
|
{
|
||||||
|
run_right();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
run_left();
|
||||||
|
}
|
||||||
|
log_i("swap");
|
||||||
|
}
|
||||||
|
|
||||||
|
long previouspulses = 0;
|
||||||
|
|
||||||
|
void calibratemotor()
|
||||||
|
{
|
||||||
|
delay(300);
|
||||||
|
|
||||||
|
bool stop = false;
|
||||||
|
run_right();
|
||||||
|
previouspulses = absPulseCount;
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
delay(100);
|
||||||
|
if(absPulseCount - previouspulses > 40)
|
||||||
|
{
|
||||||
|
log_i("absPulseCount (%i)- previouspulses(%i) = %i", absPulseCount, previouspulses, absPulseCount - previouspulses);
|
||||||
|
previouspulses = absPulseCount;
|
||||||
|
delay(50);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stop = true;
|
||||||
|
run_stop();
|
||||||
|
log_i("left done, %i", absPulseCount);
|
||||||
|
absPulseCount = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stop = false;
|
||||||
|
delay(1000);
|
||||||
|
run_left();
|
||||||
|
previouspulses = absPulseCount;
|
||||||
|
while(!stop)
|
||||||
|
{
|
||||||
|
delay(100);
|
||||||
|
if(absPulseCount - previouspulses < -30)
|
||||||
|
{
|
||||||
|
log_i("absPulseCount (%i)- previouspulses(%i) = %i", absPulseCount, previouspulses, absPulseCount - previouspulses);
|
||||||
|
previouspulses = absPulseCount;
|
||||||
|
delay(50);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
stop = true;
|
||||||
|
run_stop();
|
||||||
|
log_i("right done, %i", absPulseCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
// Open the serial port at 9600 bps
|
||||||
|
Serial.begin(115200);
|
||||||
|
delay(5000);
|
||||||
|
log_i("start sketch");
|
||||||
|
// Set pin states of the encoder
|
||||||
|
pinMode(ENC_IN_RIGHT_A , INPUT_PULLUP);
|
||||||
|
pinMode(ENC_IN_RIGHT_B , INPUT);
|
||||||
|
pinMode(MOTOR_IN1, OUTPUT);
|
||||||
|
pinMode(MOTOR_IN2, OUTPUT);
|
||||||
|
pinMode(POWERMETER, ANALOG);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Every time the pin goes high, this is a pulse
|
||||||
|
attachInterrupt(digitalPinToInterrupt(ENC_IN_RIGHT_A), right_wheel_pulse, RISING);
|
||||||
|
|
||||||
|
log_i("init done");
|
||||||
|
calibratemotor();
|
||||||
|
//run_left();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
long swaptime = 0;
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
// Record the time
|
||||||
|
currentMillis = millis();
|
||||||
|
|
||||||
|
// If one second has passed, print the number of pulses
|
||||||
|
if ((currentMillis - previousMillis > interval) && (motorruns = true))
|
||||||
|
{
|
||||||
|
|
||||||
|
previousMillis = currentMillis;
|
||||||
|
|
||||||
|
// Calculate revolutions per minute
|
||||||
|
rpm_right = (float)(right_wheel_pulse_count * 60 / ENC_COUNT_REV);
|
||||||
|
ang_velocity_right = rpm_right * rpm_to_radians;
|
||||||
|
ang_velocity_right_deg = ang_velocity_right * rad_to_deg;
|
||||||
|
|
||||||
|
log_i("Pulses/s: %i", right_wheel_pulse_count);
|
||||||
|
log_i("Speed: %0.0f", rpm_right);
|
||||||
|
log_i("RPM");
|
||||||
|
log_i("Angular Velocity: %0.00f", rpm_right);
|
||||||
|
log_i("rad per second \t %f deg per second", ang_velocity_right_deg);
|
||||||
|
log_i("powermeter %0.0f", getVPP());
|
||||||
|
log_i("absulote pulsecount = %i", absPulseCount);
|
||||||
|
|
||||||
|
right_wheel_pulse_count = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// if(pulscountswap > ENC_COUNT_REV/4)
|
||||||
|
// {
|
||||||
|
// swap_dir();
|
||||||
|
// pulscountswap = 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if(millis() - swaptime > 5000)
|
||||||
|
// {
|
||||||
|
// swaptime = millis();
|
||||||
|
// swap_dir();
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if(rpm_right < 1 && dir)
|
||||||
|
// {
|
||||||
|
// run_stop();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Increment the number of pulses by 1
|
||||||
|
void right_wheel_pulse() {
|
||||||
|
|
||||||
|
// Read the value for the encoder for the right wheel
|
||||||
|
int val = digitalRead(ENC_IN_RIGHT_B);
|
||||||
|
|
||||||
|
if(val == LOW) {
|
||||||
|
Direction_right = false; // Reverse
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Direction_right = true; // Forward
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Direction_right) {
|
||||||
|
right_wheel_pulse_count++;
|
||||||
|
pulscountswap ++;
|
||||||
|
absPulseCount ++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
right_wheel_pulse_count--;
|
||||||
|
pulscountswap ++;
|
||||||
|
absPulseCount --;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
11
blinds/test/README
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
This directory is intended for PlatformIO Test Runner and project tests.
|
||||||
|
|
||||||
|
Unit Testing is a software testing method by which individual units of
|
||||||
|
source code, sets of one or more MCU program modules together with associated
|
||||||
|
control data, usage procedures, and operating procedures, are tested to
|
||||||
|
determine whether they are fit for use. Unit testing finds problems early
|
||||||
|
in the development cycle.
|
||||||
|
|
||||||
|
More information about PlatformIO Unit Testing:
|
||||||
|
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
||||||