Skip to content

Instantly share code, notes, and snippets.

@sbasami
sbasami / DRV8320_UVW_PWM.ino
Created December 19, 2021 11:44
Teensy4.0とDRV8320HでBLDCの強制転流を行うプログラム
#define INH_U 6
#define INH_V 7
#define INH_W 8
#define INL_U 9
#define INL_V 10
#define INL_W 11
#define ENABLE 13
#define delay_time 1
#define duty_high 50
@sbasami
sbasami / KISS_ESC.ino
Last active January 28, 2024 18:29
Teensy4.1でKISS ESCとDSHOT通信するプログラム
#include <Arduino.h>
#include "DSHOT.h"
#include "ESCCMD.h"
#define ESCPID_USB_UART_SPEED 115200 //シリアル通信の速度
#define ESCPID_NB_ESC 1 //ESCの数
const float LOGGING_CYCLE = 0.01; //ログ周期[s]
IntervalTimer Timer; //10msの割り込み
@sbasami
sbasami / SBUS.ino
Created August 14, 2020 11:58
TeensyでSBUSを受信するためのプログラム
void setup() {
Serial.begin(115200); // Terminal
Serial1.begin(100000, SERIAL_8E2); // S-BUS
}
void loop() {
static int state = 0; //受信状態を格納する変数
static int cnt = 0; //カウント変数
static byte buff[25]; //受信データ用バッファ
@sbasami
sbasami / DC-motor-IPD-control-ver2.ino
Created March 25, 2020 09:17
エンコーダ分解能を考慮してTeensy LCでIPD制御を行うプログラム
//PWM出力に関しての詳細はhttps://www.pjrc.com/teensy/td_pulse.html
//エンコーダに関しての詳細はhttps://www.pjrc.com/teensy/td_libs_Encoder.html
//タイマー割込みに関しての詳細はhttps://www.pjrc.com/teensy/td_timing_IntervalTimer.html
//Teensyの標準ヘッダファイル
#include <Encoder.h>
//定数の宣言
#define GEAR (32*33*35*38) / (15*14*13*10)//モータのギア比
#define PULSE 12.0 //エンコーダのパルス数
@sbasami
sbasami / DC-motor-IPD-control.ino
Created March 25, 2020 09:14
Teensy LCでIPD制御を行うプログラム
//PWM出力に関しての詳細はhttps://www.pjrc.com/teensy/td_pulse.html
//エンコーダに関しての詳細はhttps://www.pjrc.com/teensy/td_libs_Encoder.html
//タイマー割込みに関しての詳細はhttps://www.pjrc.com/teensy/td_timing_IntervalTimer.html
//Teensyの標準ヘッダファイル
#include <Encoder.h>
//定数の宣言
#define GEAR (32*33*35*38) / (15*14*13*10)//モータのギア比
#define PULSE 12.0 //エンコーダのパルス数
@sbasami
sbasami / DC-motor-IPD-control-simulation.m
Last active March 25, 2020 09:18
MATLABでDCモータのIPD制御シミュレーションを行うプログラム
clear all;
clc;
%% シミュレーション用のモデル作成
dt=0.001; %シミュレーション周期[s]
Tc=0.001; %マイコン制御周期[s]
FinishTime=1.2; %シミュレーションの終了時間[s]
% 359.2
% ------------
@sbasami
sbasami / DC-motor-model-identification.m
Last active March 25, 2020 09:05
MATLABでDCモータのモデル同定を行うプログラム
clear all;
clc;
%エクセルファイルから入出力データの取り込み
FR.u = xlsread('DCmotor_FR_500Hz.xlsx',1,'B1:B15714');
FR.y = xlsread('DCmotor_FR_500Hz.xlsx',1,'D1:D15714');
FRdata = iddata(FR.y,FR.u,0.002); %IDDATA オブジェクトの作成
FRdata.InputName = '電圧 [V]'; %入力データの名前
FRdata.OutputName = '角速度 [rad/s]';%出力データの名前
@sbasami
sbasami / DC-motor-frequency-response.ino
Last active March 25, 2020 09:03
Teensy LCでDCモータの周波数応答を測定するプログラム
//PWM出力に関しての詳細はhttps://www.pjrc.com/teensy/td_pulse.html
//エンコーダに関しての詳細はhttps://www.pjrc.com/teensy/td_libs_Encoder.html
//タイマー割込みに関しての詳細はhttps://www.pjrc.com/teensy/td_timing_IntervalTimer.html
//Teensyの標準ヘッダファイル
#include <Encoder.h>
//定数の宣言
#define GEAR (32*33*35*38) / (15*14*13*10)//モータのギア比
#define PULSE 12.0 //エンコーダのパルス数