Hi,
I am using Arduino EsP32 to balance a ball on plate, I am trying to use ESP32 with both Core 0 and core 1, the problem is that WDT is triggering.
the code is here:
#include <SCServo.h>
#include <math.h>
#include "fis_header.h"
#include <PID_v1.h>
#include <Pixy2.h>
//For Serial 1
#define TX1_pin 26
#define RX1_pin 27
//For Serial 2
#define RXD2 16
#define TXD2 17
Pixy2 pixy;
SCSCL sc;
int S1M = 300;
int S2M = 300;
int S3M = 300;
int input = 0;
float angles[3];
TaskHandle_t Task1, Task2, Task3;
SemaphoreHandle_t baton;
int counter = 0;
float Roll_i;
float Pitch_i;
int X, Y, blocks, t = 0;
float ErY;
void blink(byte pin, int duration) {
digitalWrite(pin, HIGH);
delay(duration);
digitalWrite(pin, LOW);
delay(duration);
}
double SetpointX, InputX, OutputX;
double SetpointY, InputY, OutputY;
double KpX = 3.7589, KiX = 01.24, KdX = 1.58;
double KpY = 3.7589, KiY = 01.24, KdY = 1.58;
PID myPID(&InputX, &OutputX, &SetpointX, KpX, KiX, KdX, DIRECT);
PID myPID1(&InputY, &OutputY, &SetpointY, KpY, KiY, KdY, DIRECT);
float usecLst = 0, errLst = 0, posLst = 0, pos = 0, errX = 0, dErr = 0;
unsigned long usec, dT;
double k = 0;
int x = 0; //positon x axis
int y = 0; //position y axis
int z = 0;
int Xmax = 234;
int Ymax = 200;
int Roll;
int Pitch;
//----------------------Attachements coordinates-----------------------
//Base attachements coordinates
float b[][3] = {{4, -2.0, -2.0},
{0, 4.89, -4.89},
{0.0, 0.0, 0.0}
};
//Plate attachements coordinates
float p[][3] = {{4.5, -2.25, -2.25},
{0.0, 5.51, -5.51},
{0.0, 0.0, 0.0}
};
//----------------- CONSTANTS NEEDED FOR COMPUTATION OBTAINED FROM DESIGN STAGE IN MATLAB ----------------------------
float s = 6; //length of connection links
float a = 3; //length of servo horn
float h0 = 6.6895; //"home" height of the platform relative to the base
float errLstX = 0, errLstY = 0, posX = 0, posY = 0, errY = 0, dErrX = 0, dErrY = 0;
void codeForTask3( void * parameter )
{
for (;;) {
delay(50);
}
}
void codeForTask1( void * parameter )
{
for (;;) {
S1M = map((angles[0] * 57.29) + 50 , 0, 300, 0, 1022);
S2M = map((angles[1] * 57.29) + 50 , 0, 300, 0, 1022);
S3M = map((angles[2] * 57.29) + 50 , 0, 300, 0, 1022);
S1M = S1M - 5;
S2M = S2M - 80;
S3M = S3M - 5;
if (S1M > 425)
S1M = 425;
if (S2M > 350)
S2M = 350;
if (S3M > 425)
S3M = 425;
if (S1M < 150)
S1M = 150;
if (S2M < 150)
S2M = 150;
if (S3M < 150)
S3M = 150;
//---------------------------------------- Move Servos ----------------------------------------------------------------
sc.WritePos(3, S1M, 0);
sc.WritePos(2, S2M, 0);
sc.WritePos(1, S3M, 0);
//delay(50);
// Serial.println("Task 1: ");
}
}
void codeForTask2( void * parameter )
{
for (;;) {
int j;
// grab blocks!
pixy.ccc.getBlocks();
if (pixy.ccc.numBlocks)
{
for (j = 0; j < pixy.ccc.numBlocks; j++)
{
X = pixy.ccc.blocks[j].m_x; //Getting Ball Coordinate X
Y = pixy.ccc.blocks[j].m_x; //Getting Ball Coordinate Y
}
}
//From pixels to cm
InputX = X * 0.168;
InputY = Y * 0.154;
myPID.Compute();
myPID1.Compute();
Roll = OutputX;
Pitch = OutputY;
Roll_i = Roll * 0.017;
Pitch_i = Pitch * 0.017; //20 * sin(k)*0.017; // ((20 * cos(k)) / (1 + sin(k) * sin(k)))*0.017; //20 * sin(k)*0.017; ////// //; //Pitch
float phi = Roll_i;//;20
float theta = Pitch_i;//;
float psi = 0;
//compute rotation matrix for the planned euler sequence
float R[][3] = {{ cos(psi)*cos(theta), (-sin(psi)*cos(phi)) + (cos(psi)*sin(theta)*sin(phi)), ( sin(psi)*sin(phi)) + (cos(psi)*sin(theta)*cos(phi)) },
{sin(psi)*cos(theta), ( cos(psi)*cos(phi)) + (sin(psi)*sin(theta)*sin(phi)), (-cos(psi)*sin(phi)) + (sin(psi)*sin(theta)*cos(phi)) },
{ -sin(theta), cos(theta)*sin(phi), cos(theta)*cos(phi) }
};
//
//
// Serial.print("\nR = \n");
// printvector(R);
//compute the translation vector
float T[] = {x, y, (z + h0)};
//Serial.print("\nT = \n");
//printvector(&T[0], 3);
//compute the vector q = T + R*p for the location of the connections in the base frame
int i;
float q[3][3];
for (i = 0; i < 3; i++)
{
q[0][i] = (T[0]) + R[0][0] * p[0][i] + R[0][1] * p[1][i] + R[0][2] * p[2][i] ;
q[1][i] = (T[1]) + R[1][0] * p[0][i] + R[1][1] * p[1][i] + R[1][2] * p[2][i];
q[2][i] = (T[2]) + R[2][0] * p[0][i] + R[2][1] * p[1][i] + R[2][2] * p[2][i];
}
// Serial.print("\nq = \n");
// printvector(q);
//compute the necessary leg lengths (the distance from b to q) and save it as l for each servo. Take the norm to do it.
float l[3];
for (i = 0; i < 3; i++)
{
l[i] = sqrt(((q[0][i] - b[0][i]) * (q[0][i] - b[0][i])) + ((q[1][i] - b[1][i]) * (q[1][i] - b[1][i])) + ((q[2][i] - b[2][i]) * (q[2][i] - b[2][i])));
}
//Serial.print("\nl = \n");
// printvector(&l[0], 3);
//use trigonometry and the other constants you know to extract the angle of each servo
// float A[3]={cos(a11),cos(12),cos(13)};
for (i = 0; i < 3; i++)
{
angles[i] = acos(((l[i] * l[i]) - 27) / (l[i] * 6));
// angles[i] = 3.14 - asin(0.04 / l[i]) - acos(((l[i] * l[i]) - 27) / (l[i] * 6));
}
//Serial.println(" Task 2: ");
Serial.println(" Task 2: ");
}
}
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(9600);
// initialize digital pin LED_BUILTIN as an output.
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2); //For the camera
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
Serial1.begin(1000000, SERIAL_8N1, RX1_pin, TX1_pin);
sc.pSerial = &Serial1;
pixy.init();
pixy.setLamp(1, 0);
SetpointX = 19; //cm //85 + (50 * cos(k)) / (1 + sin(k) * sin(k));//
SetpointY = 15;//cm // 55 + (50 * sin(k) * cos(k)) / (1 + sin(k) * sin(k));//
myPID.SetMode(AUTOMATIC);
myPID.SetOutputLimits(-8, 8);
myPID1.SetMode(AUTOMATIC);
myPID1.SetOutputLimits(-8, 8);
myPID1.SetSampleTime(20);
myPID.SetSampleTime(20);
xTaskCreatePinnedToCore(
codeForTask1,
"led1Task",
1000,
NULL,
2,
&Task1,
0);
delay(500); // needed to start-up task1
xTaskCreatePinnedToCore(
codeForTask2,
"led2Task",
1000,
NULL,
3,
&Task2,
1);
delay(500); // needed to start-up task1
xTaskCreatePinnedToCore(
codeForTask3,
"led3Task",
1000,
NULL,
1,
&Task3,
0);
}
void loop() {
// Serial.println(InputX);
delay(1);
}
and here are the decoding errors:
*Decoding stack results* 0x4008b54c: **invoke_abort** at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/**panic.c** line **155** 0x4008b779: **abort** at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/**panic.c** line **170** 0x400d77eb: **task_wdt_isr** at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/esp32/**task_wdt.c** line **174** 0x40081127: **millis** at C:\Users\Oussama HADOUNE\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.3-rc3\cores\esp32\**esp32-hal-misc.c** line **139** 0x400d1da7: **SCSerial::readSCS(unsigned char*, int)** at C:\Users\Oussama HADOUNE\Documents\Arduino\libraries\SCServo-master\**SCSerial.cpp** line **47** 0x400ec876: **SCS::checkHead()** at C:\Users\Oussama HADOUNE\Documents\Arduino\libraries\SCServo-master\**SCS.cpp** line **264** 0x400d18de: **SCS::Ack(unsigned char)** at C:\Users\Oussama HADOUNE\Documents\Arduino\libraries\SCServo-master\**SCS.cpp** line **284** 0x400d1951: **SCS::genWrite(unsigned char, unsigned char, unsigned char*, unsigned char)** at C:\Users\Oussama HADOUNE\Documents\Arduino\libraries\SCServo-master\**SCS.cpp** line **98** 0x400d1a01: **SCSCL::WritePos(unsigned char, unsigned short, unsigned short, unsigned short)** at C:\Users\Oussama HADOUNE\Documents\Arduino\libraries\SCServo-master\**SCSCL.cpp** line **30** 0x400d1796: **codeForTask1(void*)** at C:\Users\Oussama HADOUNE\Documents\Arduino\test_Dual_Cores/**test_Dual_Cores.ino** line **153** 0x4008a099: **vPortTaskWrapper** at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/**port.c** line **143**

