STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
main.cpp File Reference
#include <Arduino.h>
#include <ESP32Encoder.h>
#include <cstdio>
#include <cstring>
#include "EthernetHandler.h"
Include dependency graph for main.cpp:

Go to the source code of this file.

Functions

void motorCoast ()
void motorDrive (float u)
void autoPolarityCal ()
void setup ()
void loop ()

Variables

ESP32Encoder enc
const int ENA = 25
const int IN1 = 23
const int IN2 = 5
const int ENCA = 19
const int ENCB = 21
float Kp = 0.0015f
const int CPR_4X_MOTOR
const float GEAR_RATIO = 210.0f
const float CPR_OUT = CPR_4X_MOTOR * GEAR_RATIO
const int PWM_CH = 0
const int PWM_FREQ = 8000
const int PWM_BITS = 8
const int PWM_MAX = (1 << PWM_BITS) - 1
const int PWM_MIN = 45
volatile int dir_sign = +1
long target = 1000
uint32_t toggle_t0 = 0
uint32_t print_t0 = 0

Function Documentation

◆ autoPolarityCal()

void autoPolarityCal ( )

Definition at line 72 of file main.cpp.

References delay(), digitalWrite(), dir_sign, enc, HIGH, IN1, IN2, LOW, motorCoast(), PWM_CH, and Serial.

Referenced by setup().

◆ loop()

void loop ( )

◆ motorCoast()

void motorCoast ( )

Definition at line 42 of file main.cpp.

References digitalWrite(), IN1, IN2, LOW, and PWM_CH.

Referenced by autoPolarityCal(), motorDrive(), and setup().

◆ motorDrive()

void motorDrive ( float u)

Definition at line 48 of file main.cpp.

References digitalWrite(), HIGH, IN1, IN2, LOW, motorCoast(), PWM_CH, PWM_MAX, and PWM_MIN.

Referenced by loop().

◆ setup()

Variable Documentation

◆ CPR_4X_MOTOR

const int CPR_4X_MOTOR
Initial value:
=
64

Definition at line 24 of file main.cpp.

◆ CPR_OUT

const float CPR_OUT = CPR_4X_MOTOR * GEAR_RATIO

Definition at line 27 of file main.cpp.

Referenced by loop().

◆ dir_sign

volatile int dir_sign = +1

Definition at line 37 of file main.cpp.

Referenced by autoPolarityCal(), and loop().

◆ ENA

const int ENA = 25

Definition at line 14 of file main.cpp.

Referenced by setup().

◆ enc

ESP32Encoder enc

Definition at line 11 of file main.cpp.

Referenced by autoPolarityCal(), loop(), and setup().

◆ ENCA

const int ENCA = 19

Definition at line 19 of file main.cpp.

Referenced by setup().

◆ ENCB

const int ENCB = 21

Definition at line 20 of file main.cpp.

Referenced by setup().

◆ GEAR_RATIO

const float GEAR_RATIO = 210.0f

Definition at line 26 of file main.cpp.

◆ IN1

const int IN1 = 23

Definition at line 15 of file main.cpp.

Referenced by autoPolarityCal(), motorCoast(), motorDrive(), and setup().

◆ IN2

const int IN2 = 5

Definition at line 16 of file main.cpp.

Referenced by autoPolarityCal(), motorCoast(), motorDrive(), and setup().

◆ Kp

float Kp = 0.0015f

Definition at line 23 of file main.cpp.

Referenced by loop().

◆ print_t0

uint32_t print_t0 = 0

Definition at line 40 of file main.cpp.

Referenced by loop().

◆ PWM_BITS

const int PWM_BITS = 8

Definition at line 32 of file main.cpp.

Referenced by setup().

◆ PWM_CH

const int PWM_CH = 0

Definition at line 30 of file main.cpp.

Referenced by autoPolarityCal(), loop(), motorCoast(), motorDrive(), and setup().

◆ PWM_FREQ

const int PWM_FREQ = 8000

Definition at line 31 of file main.cpp.

Referenced by setup().

◆ PWM_MAX

const int PWM_MAX = (1 << PWM_BITS) - 1

Definition at line 33 of file main.cpp.

Referenced by motorDrive().

◆ PWM_MIN

const int PWM_MIN = 45

Definition at line 34 of file main.cpp.

Referenced by motorDrive().

◆ target

◆ toggle_t0

uint32_t toggle_t0 = 0

Definition at line 39 of file main.cpp.

Referenced by loop().