Skip to content

Commit

Permalink
add pindef
Browse files Browse the repository at this point in the history
  • Loading branch information
Watanabe1101 committed Nov 6, 2023
1 parent a61d529 commit 36035dd
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/PID.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
#ifndef PID_H
#define PID_H

Expand Down
6 changes: 6 additions & 0 deletions src/dataTask.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once
#include <Arduino.h>

class dataLog{

}
16 changes: 9 additions & 7 deletions src/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ pcnt_unit_t encoder::next_pcnt_unit = PCNT_UNIT_0;

encoder::encoder() {
pcnt_unit = next_pcnt_unit;
next_pcnt_unit = static_cast<pcnt_unit_t>(static_cast<int>(next_pcnt_unit) + 1);
next_pcnt_unit =
static_cast<pcnt_unit_t>(static_cast<int>(next_pcnt_unit) + 1);
}

void encoder::begin(int pinA, int pinB) {
Expand All @@ -40,10 +41,11 @@ void encoder::begin(int pinA, int pinB) {
.channel = PCNT_CHANNEL_0,
};
pcnt_config_t pcnt_config_B = {
.pulse_gpio_num = pinB, // ↓A相用のconfigで設定したのと入れ替える
.ctrl_gpio_num = pinA, // ↑A相用のconfigで設定したのと入れ替える
.lctrl_mode = PCNT_MODE_REVERSE, // ↓A相用のconfigで設定したのと入れ替える
.hctrl_mode = PCNT_MODE_KEEP, // ↑A相用のconfigで設定したのと入れ替える
.pulse_gpio_num = pinB, // ↓A相用のconfigで設定したのと入れ替える
.ctrl_gpio_num = pinA, // ↑A相用のconfigで設定したのと入れ替える
.lctrl_mode =
PCNT_MODE_REVERSE, // ↓A相用のconfigで設定したのと入れ替える
.hctrl_mode = PCNT_MODE_KEEP, // ↑A相用のconfigで設定したのと入れ替える
.pos_mode = PCNT_COUNT_INC,
.neg_mode = PCNT_COUNT_DEC,
.counter_h_lim = INT16_MAX,
Expand All @@ -55,8 +57,8 @@ void encoder::begin(int pinA, int pinB) {
pcnt_unit_config(&pcnt_config_A);
pcnt_counter_pause(pcnt_unit);
pcnt_counter_clear(pcnt_unit);
pcnt_filter_disable(pcnt_unit); // フィルターを無効化
pcnt_counter_resume(pcnt_unit); // カウント開始
pcnt_filter_disable(pcnt_unit); // フィルターを無効化
pcnt_counter_resume(pcnt_unit); // カウント開始
pcnt_event_enable(pcnt_unit, PCNT_EVT_H_LIM); // イベントを有効化
pcnt_event_enable(pcnt_unit, PCNT_EVT_L_LIM); // イベントを有効化
pcnt_isr_register(caller, this, 0,
Expand Down
20 changes: 20 additions & 0 deletions src/gimbalpin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
namespace PIN {
const uint8_t R_ENC_A = 4; // ロール方向のエンコーダーのピン
const uint8_t R_ENCB = 16;
const uint8_t R_PWM_CW = 19;
const uint8_t R_PWM_CCW = 18;
const uint8_t P_ENC_A = 21; // ピッチ方向のエンコーダーのピン
const uint8_t P_ENCB = 22;
const uint8_t P_PWM_CW = 2;
const uint8_t P_PWM_CCW = 13;
const uint8_t MISO = 33;
const uint8_t MOSI = 26;
const uint8_t CLK = 25;
const uint8_t ICMCS = 27;
const uint8_t FLASHCS = 23;
const uint8_t RTD_TX = 32;
const uint8_t RTD_RX = 36;
const uint8_t CAM_TX = 14;
const uint8_t CAM_RX = 39;
} // namespace PIN
16 changes: 9 additions & 7 deletions src/motordriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,35 @@
#include "PWMwrapper.h"

class MotorDriver {
private:
private:
PWMWrapper cwpwm;
PWMWrapper ccwpwm;

public:
public:
MotorDriver(uint32_t f = 312500, uint8_t res = 8)
: cwpwm(f, res), ccwpwm(f, res) {}
void begin(uint8_t cwpin, uint8_t ccwpin);
void setRotation(double voltage);
void brake();
};
};
void MotorDriver::begin(uint8_t cwpin, uint8_t ccwpin) {
cwpwm.begin(cwpin);
ccwpwm.begin(ccwpin);
}

void MotorDriver::setRotation(double voltage) {
if (voltage > 5) voltage = 5;
else if (voltage < -5) voltage = -5;
if (voltage > 5)
voltage = 5;
else if (voltage < -5)
voltage = -5;
if (voltage > 0) {
cwpwm.setVoltage(voltage);
ccwpwm.setVoltage(0);
} else if (voltage < 0) {
cwpwm.setVoltage(0);
ccwpwm.setVoltage(-voltage);
}
}
}
}

void MotorDriver::brake() {
cwpwm.setVoltage(5);
Expand Down
13 changes: 8 additions & 5 deletions src/systemid.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ class COUNTER {
int16_t getcount();
};
void COUNTER::begin(int pinA, int pinB) {
pcnt_config_A.pulse_gpio_num = pinA; // 入力ピン(A)
pcnt_config_A.ctrl_gpio_num = pinB; // 制御ピン(B)
pcnt_config_A.pulse_gpio_num = pinA; // 入力ピン(A)
pcnt_config_A.ctrl_gpio_num = pinB; // 制御ピン(B)
pcnt_config_A.lctrl_mode = PCNT_MODE_KEEP; // 制御ピンがlowのときの振る舞い
pcnt_config_A.hctrl_mode = PCNT_MODE_REVERSE;
pcnt_config_A.channel = PCNT_CHANNEL_0;
pcnt_config_A.unit = PCNT_UNIT_0;
pcnt_config_A.pos_mode = PCNT_COUNT_INC; // 入力ピンが立ち上がり時の振る舞い
pcnt_config_A.pos_mode =
PCNT_COUNT_INC; // 入力ピンが立ち上がり時の振る舞い
pcnt_config_A.neg_mode = PCNT_COUNT_DEC;
pcnt_config_A.counter_h_lim = INT16_MAX;
pcnt_config_A.counter_l_lim = INT16_MIN;
Expand All @@ -54,7 +55,8 @@ void COUNTER::begin(int pinA, int pinB) {
pcnt_config_B.hctrl_mode = PCNT_MODE_KEEP;
pcnt_config_B.channel = PCNT_CHANNEL_1;
pcnt_config_B.unit = PCNT_UNIT_0;
pcnt_config_B.pos_mode = PCNT_COUNT_INC; // 入力ピンが立ち上がり時の振る舞い
pcnt_config_B.pos_mode =
PCNT_COUNT_INC; // 入力ピンが立ち上がり時の振る舞い
pcnt_config_B.neg_mode = PCNT_COUNT_DEC;
pcnt_config_B.counter_h_lim = INT16_MAX;
pcnt_config_B.counter_l_lim = INT16_MIN;
Expand Down Expand Up @@ -154,7 +156,8 @@ void Systemid::loop() {
}

float Systemid::calculate_omega() {
omega = (count - last_count) * 2 * PI / (float)(sampling_time * PULSE * GEAR);
omega =
(count - last_count) * 2 * PI / (float)(sampling_time * PULSE * GEAR);
last_count = count;
return omega;
}

0 comments on commit 36035dd

Please sign in to comment.