Skip to content
Snippets Groups Projects
Commit 3ff0cb77 authored by RicardoEA's avatar RicardoEA
Browse files

Elimino carpetas y archivos innecesarias

parent 58648f98
No related branches found
No related tags found
No related merge requests found
#ifndef CONTROL_H
#define CONTROL_H
#include <stdint.h>
#include "esp_err.h"
#include "motors.h"
#include "encoders.h"
#include "hwTimer.h"
#include "math_vector_operations.h"
#define NMOTORS 3
#define MOTOR_PINS {25,26, 27,28, 29,30}
#define MOTOR_ENC {39,37, 38,36, 34,35}
#define MOTOR_PWM_SUBUNIT_IO {MCPWM0A, MCPWM0B, MCPWM1A, MCPWM1B, MCPWM2A, MCPWM2B}
#define MOTOR_PWM_SUBUNIT_TIMER {MCPWM_TIMER_0, MCPWM_TIMER_1, MCPWM_TIMER_2}
#define MOTOR_PWM_UNIT MCPWM_UNIT_0
#define OMNI_PID_NRO_TIMER 0
#define OMNI_ODOM_NRO_TIMER 2
#define OMNI_PID_CTRL_TIMER 0.05 // in seconds
#define OMNI_ODOM_CTRL_TIMER 0.5 // in seconds
#define MAX_OUTPUT 100.0
#define WHEEL_DIAMETER 0.038 // in meters
#define WHEEL_RADIUS WHEEL_DIAMETER/2// in meters
#define ROBOT_RADIUS 0.0675 // in meters
#define ENC_CPR 3 //counts per revolution
#define MOTOR_REDUCTION 50
#define TICS_PER_REVOLUTION ENC_CPR*MOTOR_REDUCTION
#define RAD_PER_TICK 2*PI/TICS_PER_REVOLUTION
#define M_PER_SEC_TO_TICS_PER_SEC 1/(RAD_PER_TICK*WHEEL_RADIUS)
#define MAX_SPEED_POWER 90 // power % at which MAX_SPEED_TICS is obtained
#define MAX_SPEED_TICS 1080 //tics/s at MAX_SPEED_POWER
#define MAX_SPEED_RAD MAX_SPEED_TICS*RAD_PER_TICK // rad/s
#define MAX_SPEED_LIN MAX_SPEED_RAD*WHEEL_DIAMETER / 2 // m/s
#define TICS_TO_RAD_S RAD_PER_TICK/OMNI_ODOM_CTRL_TIMER
#define KP 0.01
#define KI 0.05
#define KD 0.0
#define KF MAX_SPEED_POWER/MAX_SPEED_TICS
typedef struct {
motor_h_t *driver;
encoder_h_t *encoder;
int32_t vel_counter;
int32_t odom_counter;
float target_v;
float accum_error;
float prev_error;
float output;
} servo_t;
typedef struct {
float x;
float x_dot;
float y;
float y_dot;
float phi;
float phi_dot;
} odom_t;
static servo_t motors[NMOTORS];
static odom_t odometry;
esp_err_t omni_init();
esp_err_t omni_set_enable(bool start);
esp_err_t omni_drive(float x_dot ,float y_dot ,float w_dot ,float phi);
#endif /* CONTROL_H */
\ No newline at end of file
#ifndef ENCODER_H
#define ENCODER_H
#include <stdint.h>
#include "esp_err.h"
#define CONFIG_ENCODER_THREAD_STACK_SIZE 8192
#define CONFIG_ENCODER_THREAD_PRIORITY 20
#define CONFIG_ENCODER_CPU 0
typedef void (*encoder_callback_t)(int, int8_t, uint32_t);
typedef struct {
int8_t A; ///< A pin
int8_t B; ///< B pin
uint8_t state; ///< Current state's machine state
int32_t counter; ///< Current counter value
encoder_callback_t callback; ///< Callback function
int callback_id; ///< Callback id
uint8_t deferred; ///< Deferred callback?
} encoder_h_t;
typedef struct {
encoder_h_t *h;
int8_t dir;
uint32_t counter;
} encoder_deferred_data_t;
esp_err_t encoder_setup(int8_t a, int8_t b, encoder_h_t **h);
esp_err_t encoder_unsetup(encoder_h_t *h);
esp_err_t encoder_read(encoder_h_t *h, int32_t *val);
esp_err_t encoder_write(encoder_h_t *h, int32_t val);
esp_err_t encoder_register_callback(encoder_h_t *h, encoder_callback_t callback, int id, uint8_t deferred);
#endif /* ENCODER_H */
\ No newline at end of file
#ifndef TIMER_H
#define TIMER_H
#include "driver/timer.h"
#include <stdint.h>
#include "esp_err.h"
#define CONFIG_HWTIMER_THREAD_STACK_SIZE 8192
#define CONFIG_HWTIMER_THREAD_PRIORITY 10
#define CPU_LAST_TIMER 3
#define CPU_FIRST_TIMER 0
typedef struct{
int8_t unit;
} tmr_alarm_t;
typedef struct {
uint8_t setup;
void (*callback)(void *);
timer_isr_handle_t isrh;
} tmr_t;
typedef void(*tmr_isr_t)(void *);
/**
* @brief Configures a timer. After timer is configured you must start timer using
* tmr_start function. No sanity checks are done (use only in driver develop).
*
* @param unit Hardware timer, from 0 to 3.
* @param micros Period of timer, in microseconds.
* @param callback Callback function to call every micros period.
* @param deferred If 0, the callback are executed in the isr. If 1, the callback
* is deferred and is called outside the interrupt. Non deferred
* callbacks must reside in IRAM.
*
* @return 0 if success, -1 if error (memory error)
*
*/
int tmr_ll_setup(uint8_t unit, uint32_t micros, void(*callback)(void *));
/**
* @brief Removes a timer and the resources that uses.
* tmr_start function. No sanity checks are done (use only in driver develop).
*
* @param unit Hardware timer, from 0 to 3.
*/
void tmr_ll_unsetup(uint8_t unit);
/**
* @brief Start a previous configured timer. No sanity checks are done (use only in driver develop).
*
* @param unit Hardware timer, from 0 to 3.
*/
void tmr_ll_start(uint8_t unit);
/**
* @brief Stop a previous configured timer. No sanity checks are done (use only in driver develop).
*
* @param unit Hardware timer, from 0 to 3.
*/
void tmr_ll_stop(uint8_t unit);
/**
* @brief Configures a timer. After timer is configured you must start timer using
* tmr_start function.
*
* @param unit Hardware timer, from 0 to 3.
* @param micros Period of timer, in microseconds.
* @param callback Callback function to call every micros period.
* @param deferred If 0, the callback are executed in the isr. If 1, the callback
* is deferred and is called outside the interrupt. Non deferred
* callbacks must reside in IRAM.
*
* @return
* - NULL success
* - Pointer to driver_error_t if some error occurs.
*
* TIMER_ERR_INVALID_UNIT
* TIMER_ERR_INVALID_PERIOD
* SPI_ERR_DEVICE_IS_NOT_SELECTED
* SPI_ERR_NOT_ENOUGH_MEMORY
*/
esp_err_t tmr_setup(int8_t unit, uint32_t micros, void(*callback)(void *));
/**
* @brief Removes a timer and the resources that uses.
* tmr_start function. No sanity checks are done (use only in driver develop).
*
* @param unit Hardware timer, from 0 to 3.
*
* @return
* - NULL success
* - Pointer to driver_error_t if some error occurs.
*
* TIMER_ERR_INVALID_UNIT
*/
esp_err_t tmr_unsetup(int8_t unit);
/**
* @brief Start a previous configured timer.
*
* @param unit Hardware timer, from 0 to 3.
*
* @return
* - NULL success
* - Pointer to driver_error_t if some error occurs.
*
* TIMER_ERR_IS_NOT_SETUP
*/
esp_err_t tmr_start(int8_t unit);
/**
* @brief Stop a previous configured timer.
*
* @param unit Hardware timer, from 0 to 3.
*
* @return
* - NULL success
* - Pointer to driver_error_t if some error occurs.
*
* TIMER_ERR_IS_NOT_SETUP
*/
esp_err_t tmr_stop(int8_t unit);
void get_group_idx(int8_t unit, int *groupn, int *idx);
#endif /* TIMER_H */
#ifndef VECTOR_MATH_H
#define VECTOR_MATH_H
#include "math.h"
#define PI 3.1415926535897932384626433832795
#define PIdiv180 (PI/180.0)
#define SQR(x) (x*x)
#define SGN(x) (x<0?-1:1)
#define ABS(x) (x<0?-x:x)
#define NULL_VECTOR F3dVector(0.0f,0.0f,0.0f)
/////////////////////////////////
//Note: All angles in degrees //
/////////////////////////////////
typedef struct {
float x,y,z;
} sF3dVector_t;
typedef struct {
float x1,y1,z1,x2,y2,z2,x3,y3,z3;
} sF3dMatrix_t;
float getLength(sF3dVector_t* v);
void normalize(sF3dVector_t* v);
/**
* v = v + v2
**/
void sum (sF3dVector_t* v, sF3dVector_t v2);
/**
* v = v - v2
**/
void difference (sF3dVector_t* v, sF3dVector_t v2);
/**
* v = v*r
**/
void float_mul (sF3dVector_t* v, float r);
/**
* v = v/r
**/
void float_div (sF3dVector_t* v, float r);
/**
* ret dot product
**/
float dotProduct (sF3dVector_t* v, sF3dVector_t v2);
/**
* ret v = vectorial product
**/
void crossProduct (sF3dVector_t* v, sF3dVector_t v2);
/**
* v = M*v
**/
void vector_mul (sF3dMatrix_t m, sF3dVector_t* v);
#endif /* VECTOR_MATH_H */
\ No newline at end of file
/*
Program: Motor Library
File: Motor.h
*/
#ifndef DRV8833_h
#define DRV8833_h
#include <stdint.h>
#include "esp_err.h"
#include "driver/mcpwm.h"
typedef struct {
int intSpeed;
int8_t pin1;
int8_t pin2;
char info; // bit0: isrunning, bit1: braked
double defaultDuty;
mcpwm_unit_t mcpwm_unit;
mcpwm_io_signals_t mcpwm_a;
mcpwm_io_signals_t mcpwm_b;
mcpwm_timer_t mcpwm_timer;
} motor_h_t;
esp_err_t motor_install(int8_t a, int8_t b, mcpwm_unit_t pwm_u, mcpwm_io_signals_t pwm1, mcpwm_io_signals_t pwm2, mcpwm_timer_t t, motor_h_t **m);
esp_err_t motor_set_speed(motor_h_t *m, int intIn);
esp_err_t motor_stop(motor_h_t *m);
esp_err_t motor_start(motor_h_t *m);
#endif /* DRV8833_h */
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment