-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencoder.h
More file actions
90 lines (78 loc) · 1.84 KB
/
encoder.h
File metadata and controls
90 lines (78 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#pragma once
#include <stdio.h>
#include <unistd.h>
#include <inttypes.h>
#include <math.h>
#include "rcl/time.h"
#include "esp_timer.h"
#include <driver/gpio.h>
#include <driver/ledc.h>
#include "driver/i2c.h"
#ifdef ESP_PLATFORM
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#endif
#include <nav_msgs/msg/odometry.h>
#include <std_msgs/msg/header.h>
#include <rcl/rcl.h>
#include <rcl/error_handling.h>
#include <rclc/rclc.h>
#include <rclc/executor.h>
#include "motor_driver.h"
typedef struct {
int PIN_A;
int PIN_B;
int RESOLUTION;
int PULSES_PER_REV;
int FRAME_TIME_MS;
float WHEEL_DIAMETER;
float WHEEL_BASE;
} encoder_setup_t;
// typedefs struct for encoder state
typedef struct {
int left;
int left_last;
int right;
int right_last;
} encoder_state_t;
// typedefs struct for encoder count
typedef struct {
int left;
int right;
} encoder_count_t;
// typedefs struct for encoder direction
typedef struct {
int left;
int right;
} encoder_direction_t;
// typedefs struct speed
typedef struct {
float left;
float right;
} encoder_speed_t;
// typedefs struct for encoder linear velocity (m/s) and angular velocity (rad/s)
typedef struct {
float linear;
float angular;
} encoder_velocity_t;
// typedefs struct for encoder position (m) with x, y, theta (rad) and last position
typedef struct {
float x;
float y;
float theta;
float x_last;
float y_last;
float theta_last;
} encoder_position_t;
// define extern variables for motor driver
extern motor_setup_t motor_setup;
// define function prototypes with pointer arguments
void IRAM_ATTR encoder_left_isr_handler();
void IRAM_ATTR encoder_right_isr_handler();
void InitEncoder(encoder_setup_t encoder_setup);
void encoder_count_reset();
void encoder_direction_();
void encoder_speed_();
void encoder_velocity_();
void encoder_position_();
void GetEncoder();