cotrol on of

This commit is contained in:
2020-08-23 14:44:44 -05:00
parent 890a26ac06
commit 94fd4b0606
8 changed files with 245 additions and 9 deletions

9
.gitignore vendored
View File

@@ -1,4 +1,5 @@
.pioenvs .pio
.piolibdeps .vscode/.browse.c_cpp.db*
.clang_complete .vscode/c_cpp_properties.json
.gcc-flags.json .vscode/launch.json
.vscode/ipch

View File

@@ -1,6 +1,6 @@
# Continuous Integration (CI) is the practice, in software # Continuous Integration (CI) is the practice, in software
# engineering, of merging all developer working copies with a shared mainline # engineering, of merging all developer working copies with a shared mainline
# several times a day < http://docs.platformio.org/page/ci/index.html > # several times a day < https://docs.platformio.org/page/ci/index.html >
# #
# Documentation: # Documentation:
# #
@@ -8,13 +8,13 @@
# < https://docs.travis-ci.com/user/integration/platformio/ > # < https://docs.travis-ci.com/user/integration/platformio/ >
# #
# * PlatformIO integration with Travis CI # * PlatformIO integration with Travis CI
# < http://docs.platformio.org/page/ci/travis.html > # < https://docs.platformio.org/page/ci/travis.html >
# #
# * User Guide for `platformio ci` command # * User Guide for `platformio ci` command
# < http://docs.platformio.org/page/userguide/cmd_ci.html > # < https://docs.platformio.org/page/userguide/cmd_ci.html >
# #
# #
# Please choice one of the following templates (proposed below) and uncomment # Please choose one of the following templates (proposed below) and uncomment
# it (remove "# " before each line) or use own configuration according to the # it (remove "# " before each line) or use own configuration according to the
# Travis CI documentation (see above). # Travis CI documentation (see above).
# #
@@ -42,7 +42,7 @@
# #
# Template #2: The project is intended to by used as a library with examples # Template #2: The project is intended to be used as a library with examples.
# #
# language: python # language: python

7
.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}

39
include/README Normal file
View 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
lib/README Normal file
View 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

15
platformio.ini Normal file
View File

@@ -0,0 +1,15 @@
; 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:mhetesp32devkit]
platform = espressif32
board = mhetesp32devkit
framework = arduino
monitor_speed = 115200

117
src/main.cpp Normal file
View File

@@ -0,0 +1,117 @@
#include <Arduino.h>
#include <Wire.h>
#include <MPU6050_tockn.h>
TaskHandle_t TareaProcesador1;
void loop1(void *pvParameters);
volatile int left_motor, throttle_left_motor, throttle_counter_left_motor, throttle_left_motor_memory;
volatile int right_motor, throttle_right_motor, throttle_counter_right_motor, throttle_right_motor_memory;
volatile int dir = 0;
bool FWD = HIGH;
bool BWD = LOW;
#define STEP_1 13
#define DIR_1 25
#define STEP_2 33
#define DIR_2 14
MPU6050 mpu6050(Wire);
float ax, ay, az;
long timer = 0;
void setup()
{
pinMode(23, OUTPUT);
pinMode(STEP_1, OUTPUT);
pinMode(STEP_2, OUTPUT);
pinMode(DIR_1, OUTPUT);
pinMode(DIR_2, OUTPUT);
digitalWrite(DIR_1, LOW);
digitalWrite(DIR_2, LOW);
Wire.begin();
Serial.begin(115200);
Wire.begin();
xTaskCreatePinnedToCore(loop1, "Tarea1", 10000, NULL, 1, &TareaProcesador1, 0);
delay(2000); // Pause for 2 seconds
mpu6050.begin();
mpu6050.calcGyroOffsets(false);
}
void loop()
{
mpu6050.update();
if (millis() - timer > 10)
{
// ax = mpu6050.getAngleX();
ay = mpu6050.getAngleY();
//az = mpu6050.getAngleZ();
/* Serial.print(ax), Serial.print(",");
Serial.print(ay), Serial.print(",");
Serial.println(az);*/
if (ay > 4)
{
dir = -1;
}
else if (ay < -4)
{
dir = 1;
}
else
{
dir = 0;
}
throttle_left_motor = 6 * dir;
throttle_right_motor = 6 * dir;
timer = millis();
}
}
void loop1(void *pvParameters)
{
for (;;)
{
throttle_counter_left_motor++; //Increase the throttle_counter_left_motor variable by 1 every time this routine is executed
if (throttle_counter_left_motor > throttle_left_motor_memory)
{ //If the number of loops is larger then the throttle_left_motor_memory variable
throttle_counter_left_motor = 0; //Reset the throttle_counter_left_motor variable
throttle_left_motor_memory = throttle_left_motor; //Load the next throttle_left_motor variable
if (throttle_left_motor_memory < 0)
{ //If the throttle_left_motor_memory is negative
digitalWrite(DIR_1, BWD); //Set output 3 low to reverse the direction of the stepper controller
throttle_left_motor_memory *= -1; //Invert the throttle_left_motor_memory variable
}
else
digitalWrite(DIR_1, FWD); //Set output 3 high for a forward direction of the stepper motor
}
else if (throttle_counter_left_motor == 1)
digitalWrite(STEP_1, HIGH); //Set output 2 high to create a pulse for the stepper controller
else if (throttle_counter_left_motor == 2)
digitalWrite(STEP_1, LOW); //Set output 2 low because the pulse only has to last for 20us
//right motor pulse calculations
throttle_counter_right_motor++; //Increase the throttle_counter_right_motor variable by 1 every time the routine is executed
if (throttle_counter_right_motor > throttle_right_motor_memory)
{ //If the number of loops is larger then the throttle_right_motor_memory variable
throttle_counter_right_motor = 0; //Reset the throttle_counter_right_motor variable
throttle_right_motor_memory = throttle_right_motor; //Load the next throttle_right_motor variable
if (throttle_right_motor_memory < 0)
{ //If the throttle_right_motor_memory is negative
digitalWrite(DIR_2, BWD); //Set output 5 low to reverse the direction of the stepper controller
throttle_right_motor_memory *= -1; //Invert the throttle_right_motor_memory variable
}
else
digitalWrite(DIR_2, FWD);
; //Set output 5 high for a forward direction of the stepper motor
}
else if (throttle_counter_right_motor == 1)
digitalWrite(STEP_2, HIGH); //Set output 4 high to create a pulse for the stepper controller
else if (throttle_counter_right_motor == 2)
digitalWrite(STEP_2, LOW);
delay(1);
}
}

11
test/README Normal file
View File

@@ -0,0 +1,11 @@
This directory is intended for PIO Unit Testing 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 PIO Unit Testing:
- https://docs.platformio.org/page/plus/unit-testing.html