Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test joint encoder #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions esp/Joint/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
67 changes: 67 additions & 0 deletions esp/Joint/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Continuous Integration (CI) is the practice, in software
# engineering, of merging all developer working copies with a shared mainline
# several times a day < https://docs.platformio.org/page/ci/index.html >
#
# Documentation:
#
# * Travis CI Embedded Builds with PlatformIO
# < https://docs.travis-ci.com/user/integration/platformio/ >
#
# * PlatformIO integration with Travis CI
# < https://docs.platformio.org/page/ci/travis.html >
#
# * User Guide for `platformio ci` command
# < https://docs.platformio.org/page/userguide/cmd_ci.html >
#
#
# Please choose one of the following templates (proposed below) and uncomment
# it (remove "# " before each line) or use own configuration according to the
# Travis CI documentation (see above).
#


#
# Template #1: General project. Test it using existing `platformio.ini`.
#

# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio run


#
# Template #2: The project is intended to be used as a library with examples.
#

# language: python
# python:
# - "2.7"
#
# sudo: false
# cache:
# directories:
# - "~/.platformio"
#
# env:
# - PLATFORMIO_CI_SRC=path/to/test/file.c
# - PLATFORMIO_CI_SRC=examples/file.ino
# - PLATFORMIO_CI_SRC=path/to/test/directory
#
# install:
# - pip install -U platformio
# - platformio update
#
# script:
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N
10 changes: 10 additions & 0 deletions esp/Joint/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
10 changes: 10 additions & 0 deletions esp/Joint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# matty
Conection joint encoder to esp board:

black - GND

red - 3V3

white - IO5

![Conection joint encoder - esp board](../../images/encoder-esp.jpg)
39 changes: 39 additions & 0 deletions esp/Joint/include/README
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions esp/Joint/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
; 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:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
upload_port = COM8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like specification of upload_port makes some troubles - in my case I need /dev/ttyUSB0 ... but when I used the Communication (?) project this was commented out and autodetect (?) worked fine

; board_build.partitions = min_spiffs.csv
monitor_speed = 115200
34 changes: 34 additions & 0 deletions esp/Joint/src/as5600.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "as5600.h"

volatile uint32_t pulseStart = 0;
volatile uint32_t pulseEnd = 0;
volatile uint32_t pulseWidth = 0;
volatile uint32_t pulsePeriod = 0;

void IRAM_ATTR interruptAS5600() {
uint32_t x = micros();
bool e = digitalRead(AS5600_GPIO);
if (e == 1) {
pulsePeriod = x - pulseStart;
pulseStart = x;
} else {
pulseEnd = x;
pulseWidth = pulseEnd - pulseStart;
}
}

AS5600::AS5600(float zero) {
this->zero = (zero + 0.5f) * 100;
}

void AS5600::init() {
pinMode(AS5600_GPIO, INPUT);
attachInterrupt(AS5600_GPIO, interruptAS5600, CHANGE);
}

int AS5600::angle() {
int y = (pulseWidth * 4095 / AS5600_GAIN - AS5600_OFFS) * 36000 / 4095 - zero;
return y;
}


20 changes: 20 additions & 0 deletions esp/Joint/src/as5600.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef AS5600_H
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this your file or some official library? If your, can you please add extra comment what "AS5600" is? I guess some hall sensor(?) and the class provides info about conversion to degrees? I would maybe mention it with angle() function too as other may expect radians ;). Thanks

#define AS5600_H

#include <Arduino.h>

#define AS5600_GPIO 5
#define AS5600_ZERO 200
#define AS5600_GAIN 4131
#define AS5600_OFFS 127

class AS5600 {
public:
AS5600(float zero = 180.0f);
void init();
int angle();
private:
int zero;
};

#endif
53 changes: 53 additions & 0 deletions esp/Joint/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <Arduino.h>
#include "as5600.h"

AS5600 as5600(0);

/*
Conection joint encoder - esp board
black - GND
red - 3V3
white - IO5
*/

/*
bool cap_ISR_cb(mcpwm_unit_t mcpwm, mcpwm_capture_channel_id_t cap_channel, const cap_event_data_t *edata,void *user_data){ //this function need to be in that format to be recognized as cap_isr_cb_t type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this code commented out?

uint32_t x = (uint32_t) edata->cap_value; //same as mcpwm_capture_signal_get_value()
mcpwm_capture_on_edge_t e = edata->cap_edge;
if (e & MCPWM_POS_EDGE) {
pulseStart = x;
}
if (e & MCPWM_NEG_EDGE) {
pulseEnd = x;
pulseWidth = pulseEnd - pulseStart;
}
return 0; //Whether a task switch is needed after the callback function returns, this is usually due to the callback wakes up some high priority task.
}
*/

/**
* @brief Initialize capture submodule
*
* @param mcpwm_num set MCPWM unit(0-1)
* @param cap_edge set capture edge, BIT(0) - negative edge, BIT(1) - positive edge
* @param cap_sig capture pin, which needs to be enabled
* @param num_of_pulse count time between rising/falling edge between 2 *(pulses mentioned), counter uses APB_CLK
*
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
*/

//esp_err_t mcpwm_capture_enable(mcpwm_unit_t mcpwm_num, mcpwm_capture_signal_t cap_sig, mcpwm_capture_on_edge_t cap_edge, uint32_t num_of_pulse);

void setup() {
Serial.begin(115200);
as5600.init();
}

void loop() {
int x = pulseIn(AS5600_GPIO, 1);
int z = as5600.angle();
Serial.printf("Width: %5d Angle: %3d.%02d\n\r", x, z/100, abs(z%100));
delay(100);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add EOLN?

11 changes: 11 additions & 0 deletions esp/Joint/test/README
Original file line number Diff line number Diff line change
@@ -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
Binary file added images/encoder-esp.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.