Skip to content

Commit

Permalink
beta: use ADC for stream (instead of sin)
Browse files Browse the repository at this point in the history
  • Loading branch information
ussserrr committed Dec 17, 2018
1 parent 58ffa3d commit 06f2598
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
17 changes: 10 additions & 7 deletions main/commandmanager.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,22 @@ void _stream_task(void *data) {
unsigned char stream_buf[STREAM_BUF_SIZE];
stream_buf[0] = STREAM_PREFIX;

double x = 0.0;
double const dx = 0.1;
// double x = 0.0;
// double const dx = 0.1;

ESP_LOGI(TAG, "Stream task started");

while (1) {
if (stream_run) {

if (x > (2.0 * M_PI))
x = 0.0;
stream_values[0] = (float)sin(x); // Process Variable
stream_values[1] = (float)cos(x); // Controller Output
x = x + dx;
// if (x > (2.0 * M_PI))
// x = 0.0;
// stream_values[0] = (float)sin(x); // Process Variable
// stream_values[1] = (float)cos(x); // Controller Output
// x = x + dx;

stream_values[0] = adc1_get_raw(ADC1_CHANNEL_0);
stream_values[1] = adc1_get_raw(ADC1_CHANNEL_1);

memcpy(&stream_buf[1], stream_values, 2*sizeof(float));

Expand Down
2 changes: 2 additions & 0 deletions main/commandmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "driver/adc.h"

#include "lwip/sockets.h"

#include "esp_log.h"
Expand Down
8 changes: 8 additions & 0 deletions main/pid_controller_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include "esp_event_loop.h"
#include "nvs_flash.h"

// #include "driver/gpio.h"
// #include "driver/adc.h"

#include "lwip/err.h"
#include "lwip/sockets.h"
#include "lwip/sys.h"
Expand Down Expand Up @@ -239,6 +242,11 @@ void app_main() {
ESP_LOGI(TAG, "Connected to AP");


adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(ADC1_CHANNEL_0, ADC_ATTEN_DB_0);
adc1_config_channel_atten(ADC1_CHANNEL_1, ADC_ATTEN_DB_0);


xTaskCreate(udp_server_task, "udp_server_task", 4096, NULL, 5, NULL);
xTaskCreate(_stream_task, "_stream_task", 4096, NULL, 4, NULL);
}

0 comments on commit 06f2598

Please sign in to comment.