想要更多项目私wo!!!
一、电路设计
硬件组成:
- Arduini Nan
- ESP8266
- MPU6050 模块
- 有刷电机
- 螺旋桨
- 电池包
- Si2302场效应管
- 无人机架
ESP8266模块
为了与无人机通信,我们需要蓝牙或WIFI连接,所以我们使用ESP8266 Wi-Fi模块,因为它有内置的Wi-Fi,我们可以使用它进行通信。
ESP8266开源、互动、可编程、低成本、简单、智能、最低成本的Wi-Fi硬件。
至于无人机的飞行范围。测试已经得到了范围大约是70米,使用三星手机充当WiFi热点和远程控制器。
MPU6050
MPU6050 IMU,一个低成本的设备,包含陀螺仪和加速计。
我们将使用MPU-6050和ESP8266模块来做一个无人机。
二、效果图
文章来源:https://www.toymoban.com/news/detail-529690.html
文章来源地址https://www.toymoban.com/news/detail-529690.html
三、部分代码
#include<Wire.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
WiFiUDP UDP;
char packet[4];
//IPAddress local_IP(192, 168, 203, 158);
//IPAddress gateway(192, 168, 1, 158);
//IPAddress subnet(255, 255, 0, 0);
//_________________________________________//
int ESCout_1 ,ESCout_2 ,ESCout_3 ,ESCout_4;
int input_PITCH = 50;
int input_ROLL = 50;
int input_YAW = 50;
volatile int input_THROTTLE = 0;
int Mode = 0;
boolean wall_car_init = false;
boolean set_motor_const_speed = false;
int8_t target_axis=0;
int8_t target_dirr=0;
boolean wheal_state = false;
uint8_t pwm_stops;
int arr[] = {20,10,20,10};
volatile int order[] = {0,0,0,0}; //volatile key
int temp_arr[] = {0,0,0,0};
int pulldown_time_temp[] = {0,0,0,0,0};
int pulldown_time[] = {0,0,0,0,0};
volatile int pulldown_time_temp_loop[] = {0,0,0,0,0}; //volatile key
uint8_t pin[] = {14,12,13,15};
int i,j,temp_i,temp;
boolean orderState1,orderState2,orderState3,orderState4,Timer_Init;
int16_t gyro_x, gyro_y, gyro_z, acc_x, acc_y, acc_z, temperature, acc_total_vector;
float angle_pitch, angle_roll,angle_yaw,prev_roll,prev_pitch,prev_yaw;
boolean set_gyro_angles;
float angle_roll_acc, angle_pitch_acc;
float angle_pitch_output, angle_roll_output, angle_yaw_output;
long Time, timePrev;
float elapsedTime,P_factor;
float acceleration_x,acceleration_y,acceleration_z;
long gyro_x_cal, gyro_y_cal, gyro_z_cal;
float pitch_PID,roll_PID,yaw_PID;
float roll_error, roll_previous_error, pitch_error, pitch_previous_error, yaw_error, yaw_previous_error;
float roll_pid_p, roll_pid_d, roll_pid_i, pitch_pid_p, pitch_pid_i, pitch_pid_d, yaw_pid_p, yaw_pid_i, yaw_pid_d;
float roll_desired_angle, pitch_desired_angle, yaw_desired_angle;
double twoX_kp=5; //5
double twoX_ki=0.003; //0.003
double twoX_kd=1.4; //1.4
double yaw_kp=8; //5
double yaw_ki=0; //0.005
double yaw_kd=4; //2.8
void ICACHE_RAM_ATTR PWM_callback() {
switch (pwm_stops){
case 0:
pulldown_time_temp[0] = pulldown_time_temp_loop[0];
pulldown_time_temp[1] = pulldown_time_temp_loop[1];
pulldown_time_temp[2] = pulldown_time_temp_loop[2];
pulldown_time_temp[3] = pulldown_time_temp_loop[3];
pulldown_time_temp[4] = pulldown_time_temp_loop[4];
pwm_stops = 1;
if(input_THROTTLE!=0){GPOS = (1 << 14);GPOS = (1 << 12);GPOS = (1 << 15);GPOS = (1 << 13);}
timer1_write(80*pulldown_time_temp[0]);
break;
case 1:
pwm_stops = 2;
GPOC = (1 << pin[order[0]]);
timer1_write(80*pulldown_time_temp[1]);
break;
case 2:
pwm_stops = 3;
GPOC = (1 << pin[order[1]]);
timer1_write(80*pulldown_time_temp[2]);
break;
case 3:
pwm_stops = 4;
GPOC = (1 << pin[order[2]]);
timer1_write(80*pulldown_time_temp[3]);
break;
case 4:
pwm_stops = 0;
GPOC = (1 << pin[order[3]]);
timer1_write(80*pulldown_time_temp[4]);
break;
}
}
到了这里,关于Arduino无人机四轴飞行器(esp8266)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!