四旋翼无人机从0到1的实现(十五)无人机外设驱动→Receiver

Author:家有仙妻谢掌柜
Date:2021/2/18

今年会更新一个系列,小四轴无人机从功能设计→思维导图→原理图设计→PCBLayout→焊接PCB→程序代码的编写→整机调试一系列,以此记录自己的成长历程!
这个小四轴无人机是大学时期学习制作的,加上现在工作学习对嵌入式的理解更加深入,因此想要重新梳理一下小四轴,之后在此基础上实现大四轴的飞控设计,这些都将在工作之余完成!

//小四轴无人机设计,接收机用的是NRF51822
#include "nrf51822.h"

/*******************************************************************************
 * fuction	nrf51822_get_data
 * brief	获取遥控器的数据
 * param	无
 * return	无
 *******************************************************************************/  
void nrf51822_get_data(void)
{
	if(RF_DATA_SUCCES == true)
	{
		RF_DATA_SUCCES = false;
		if(RF_DATA[0]==0x66)
		{
			/* 要控器的油门值,初始为171-853,减去171后变为0-680---- */
			//		RF_DATA[1]   RF_DATA[2]
			//		temp_throttle = RF_DATA[1];
			//		temp_throttle = temp_throttle*256 
			//		temp_throttle += RF_DATA[2];
			temp_throttle = (uint16_t)((( uint16_t)RF_DATA[1]<<8)|RF_DATA[2])-171.0f;
			throttle = Curve_Ctrl(temp_throttle);          //	float Curve_Ctrl(float Curve_X)
			if(throttle<=0) 		throttle = 0;
			if(throttle>=1000) 	throttle = 1000;	
			/* ,得到期望的ROLL舵值 */   
			temp_Expect.roll = (uint16_t)((( uint16_t)RF_DATA[3]<<8)|RF_DATA[4])-512.0f;
			/* ,得到期望的pitch舵值 */
			temp_Expect.pitch = (uint16_t)((( uint16_t)RF_DATA[5]<<8)|RF_DATA[6])-512.0f;
			/* ,得到期望的ROLL的角度,pitch的角度 */  
			temp_Expect.pitch = temp_Expect.pitch/8.0f;
			temp_Expect.roll = -temp_Expect.roll/8.0f;
			/* ,得到期望的yaw舵值 */   
			temp_Expect.yaw = (uint16_t)((( uint16_t)RF_DATA[7]<<8)|RF_DATA[8])-512.0f;
			/* pitch roll防斜边处理 弱化处理 */
			float expect_len = temp_Expect.roll*temp_Expect.roll+temp_Expect.pitch*temp_Expect.pitch;
			Expect.roll = temp_Expect.roll*fabs(temp_Expect.roll)/sqrtf(expect_len+1.0f);
			Expect.pitch = temp_Expect.pitch*fabs(temp_Expect.pitch)/sqrtf(expect_len+1.0f);
			/* pitch roll做死区处理,防止误动作 */
			Expect.roll = applyDeadband(Expect.roll,5.0f);
			Expect.pitch = applyDeadband(Expect.pitch,5.0f);
			/* yaw 弱化处理 */
			float expect_len_raw = temp_Expect.yaw*fabs(temp_Expect.yaw)/350.0f;
			//	Expect.yaw = float constrain_float(float amt,float low,float high )
			/* yaw 比大小,取值 */
			Expect.yaw =  constrain_float(expect_len_raw,-330.0f,330.0f);
			/* yaw做死区处理,防止误动作 */
			Expect.yaw = applyDeadband(Expect.yaw,35.0f);  // 取35.0f的目的是为了退油门摇杆时防止左右偏差,产生航向角的误动作
			/* 为了做按键处理 */
			if(start_input_once_flag == false)
			{
				start_input_once_flag = true;
				last_rfdata_9  = RF_DATA[9];
				last_rfdata_10 = RF_DATA[10];
			}
			/* 如果不等于则按键按下 ,做飞行状态处理 */
			if(RF_DATA[9] != last_rfdata_9)//如果不等于则按键按下
			{                 
				if(Fly_Mode == FLYMODE_FLP)
				{
					Fly_Mode = FLYMODE_6AXIE;
				}
				else
					Fly_Mode = FLYMODE_FLP;
				last_rfdata_9 = RF_DATA[9];
			}
			if(RF_DATA[10] != last_rfdata_10)
			{
				if(Fly_State == FlyStop)
				{
					Fly_State = FlyIdle;
				}
				else
					Fly_State = FlyStop;
				last_rfdata_10 = RF_DATA[10];
			}
			//thr_lowest_flag   停机模式FlyStop   怠速模式FlyIdle  油门值throttle 
			if(Fly_State == FlyIdle && throttle<30.0f && thr_lowest_flag == false)
			thr_lowest_flag = true;
			if(Fly_State == FlyStop) thr_lowest_flag = false;
			if(Fly_State == FlyIdle && thr_lowest_flag == true && throttle>=30.0f)
			Fly_State = FlyStart;

			/* 判断是否为翻跟头模式 */
			if(Fly_Mode == FLYMODE_FLP)
			{
				/* 判断是否为前后翻 */
				if(fabs(Expect.pitch)>15)
				{
					/* 判断是否为前翻 */
					if(Expect.pitch>15)
						filp_dir = 1;	
					else if(Expect.pitch<-15)
						filp_dir = 2;
					filp_state = 0;
				}
				/* 判断是否为左右翻 */
				else if(fabs(Expect.roll)>15)
				{
					/* 判断是否为右翻 */
					if(Expect.roll>15)
						filp_dir = 3;
					else if(Expect.roll<-15)
						filp_dir = 4;
					filp_state = 0;
				}
				Expect.roll = 0;
				Expect.pitch = 0;
			}
		}
	}
}
#ifndef _NRF51822_H__
#define _NRF51822_H__

#include "board_define.h"
#include "var_global.h"
void nrf51822_get_data(void);
//extern uint8_t RF_DATA[13];
#endif
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
nrf51822中文参考手册,nRF51822 是一款集成nRF51x系列无线收发器的超低功耗的片上系统 (Soc) , 包含一个32位ARM Cortex-M0 CPU , flash 存储器和模拟、数字外设。NORDIC SEMICONDUCTOR nRF51822 Product Specification v1.3 Liability disclaimer Nordic Semiconductor ASa reserves the right to make changes without further notice to the product to improve reliability, function or design. Nordic Semiconductor asa does not assume any liability arising out of the application or use of any product or circuits described herein ife support applications Nordic Semiconductor's products are not designed for use in life support appliances, devices, or systems where malfunction of these products can reasonably be expected to result in personal injury. Nordic Semiconductor ASa customers using or selling these products for use in such applications do so at their own risk and agree to fully indemnify Nordic Semiconductor ASA for any damages resulting from such improper use or sale Contact details Foryournearestdistributorpleasevisitwww.nordicsemi.com Information regarding product updates, downloads, and technical support can be accessed through your My Page account on our home page Main office: Otto Nielsens veg 12 Mailing address: Nordic Semiconductor 7052 Trondheim P.O. Box 2336 Norway 7004 Trondhe Phone:+4772898900 Norway 4772898989 画N远 NS-EN ISO 9001 CERTIFICATEDFIRM RoHS and reach statement Nordic semiconductor's products meet the requirements of Directive 2002/95/EC of the European Parliament and of the Council on the restriction of Hazardous Substances(roHS)and the requirements of the reach regulation(EC 1907/2006)on Registration, Evaluation, Authorization and Restriction of Chemicals. The SvHC(Substances of Very High Concern) candidate list is continually being updated Complete hazardous substance reports material composition reports and latest version of nordics reach statementcanbefoundonourwebsitewww.nordicsemicom Page 2 of 67 NORDIC SEMICONDUCTOR nRF51822 Product Specification v1.3 Datasheet status Status Description Objective Pro

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值