一、概述
二、机器人平台设计之arduino基础
三、机器人平台设计之电机驱动
1.硬件_电机与电机驱动板
2.电机基本控制实现
int DIRA = 4;
int PWMA = 5;
void setup() {
pinMode(DIRA,OUTPUT);
pinMode(PWMA,OUTPUT);
}
void loop() {
digitalWrite(DIRA,HIGH);
analogWrite(PWMA,100);
delay(3000);
digitalWrite(DIRA,HIGH);
analogWrite(PWMA,0);
delay(3000);
digitalWrite(DIRA,LOW);
analogWrite(PWMA,100);
delay(3000);
digitalWrite(DIRA,LOW);
analogWrite(PWMA,0);
delay(3000);
}
电机测速01_理论
4.电机测速02_实现
int motor_A = 21;
int motor_B = 20;
volatile int count = 0;
void count_A(){
if(digitalRead(motor_A) == HIGH){
if(digitalRead(motor_B) == HIGH){
count++;
} else {
count--;
}
} else {
if(digitalRead(motor_B) == LOW){
count++;
} else {
count--;
}
}
}
void count_B(){
if(digitalRead(motor_B) == HIGH){
if(digitalRead(motor_A) == LOW){
count++;
} else {
count--;
}
} else {
if(digitalRead(motor_A) == HIGH){
count++;
} else {
count--;
}
}
}
void setup() {
Serial.begin(57600);
pinMode(motor_A,INPUT);
pinMode(motor_B,INPUT);
attachInterrupt(2,count_A,CHANGE);
attachInterrupt(3,count_B,CHANGE);
}
void loop() {
delay(2000);
Serial.println(count);
}
int reducation = 90;
int pulse = 11;
int per_round = pulse * reducation * 4;
long start_time = millis();
long interval_time = 50;
double current_vel;
void get_current_vel(){
long right_now = millis();
long past_time = right_now - start_time;
if(past_time >= interval_time){
noInterrupts();
current_vel = (double)count / per_round / past_time * 1000 * 60;
count = 0;
start_time = right_now;
interrupts();
Serial.println(current_vel);
}
}
void loop() {
delay(10);
get_current_vel();
}
5.电机调速01_PID控制理论
6.电机调速02_PID控制实现
#include <PID_v1.h>
int DIRA = 4;
int PWMA = 5;
int motor_A = 21;
int motor_B = 20;
volatile int count = 0;
void count_A(){
if(digitalRead(motor_A) == HIGH){
if(digitalRead(motor_B) == HIGH){
count++;
} else {
count--;
}
} else {
if(digitalRead(motor_B) == LOW){
count++;
} else {
count--;
}
}
}
void count_B(){
if(digitalRead(motor_B) == HIGH){
if(digitalRead(motor_A) == LOW){
count++;
} else {
count--;
}
} else {
if(digitalRead(motor_A) == HIGH){
count++;
} else {
count--;
}
}
}
int reducation = 90;
int pulse = 11;
int per_round = pulse * reducation * 4;
long start_time = millis();
long interval_time = 50;
double current_vel;
void get_current_vel(){
long right_now = millis();
long past_time = right_now - start_time;
if(past_time >= interval_time){
noInterrupts();
current_vel = (double)count / per_round / past_time * 1000 * 60;
count = 0;
start_time = right_now;
interrupts();
Serial.println(current_vel);
}
}
double pwm;
double target = 80;
double kp=1.5, ki=3.0, kd=0.1;
PID pid(¤t_vel,&pwm,&target,kp,ki,kd,DIRECT);
void update_vel(){
get_current_vel();
pid.Compute();
digitalWrite(DIRA,HIGH);
analogWrite(PWMA,pwm);
}
void setup() {
Serial.begin(57600);
pinMode(18,INPUT);
pinMode(19,INPUT);
pinMode(DIRA,OUTPUT);
pinMode(PWMA,OUTPUT);
attachInterrupt(2,count_A,CHANGE);
attachInterrupt(3,count_B,CHANGE);
pid.SetMode(AUTOMATIC);
}
void loop() {
delay(10);
update_vel();
}
四、机器人平台设计之传感器
1.传感器_激光雷达简介
2.传感器_雷达使用
3.传感器_相机简介
4.传感器_相机使用
5.传感器_集成
|