Skip to content

Commit

Permalink
lose instruct,stop motor
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyouwulv1314 committed Jul 3, 2014
1 parent 60a3740 commit c87e93c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Src/algorithm/my_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ void get_remote_control_desired(_Control_Loop_t * loop)/*{{{*/
//if(gpwmen && !(DRChannelMiddleLock(DRDataPointerDone[Yaw])))//没必要,没有偏航控制时 rc_yaw=0;
if(gpwmen)//加油门起来后,直接用当前角度作为 desired.yaw.这样才能锁航
{
//如果rc_yaw不为0,应调整 desired yaw.注意rc_yaw是角速度,所以inputscale.yaw要保护时间dt在里面,所以yaw 方向的inputscale比其他两个方向的小很多。
loop->desired.yaw += rc_yaw * loop->inputscale.yaw;
//期望的角度也应该限制在 -180 ~ +180 之间
if(loop->desired.yaw > 180)
loop->desired.yaw -=360;
else if(loop->desired.yaw < -180)
Expand Down
8 changes: 8 additions & 0 deletions Src/driver/my_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "IICtools.h"
#include "my_sensor.h"

#define CheckRecvInstrctCntThreshold TIM2Freq/2

void TIM_Interrupt_Config(void)/*{{{*/
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
Expand Down Expand Up @@ -158,6 +160,12 @@ void TIM2_IRQHandler(void)/*{{{*/
LED_B_Set(LED_On)
}
#endif
g_check_recv_instruct_cnt ++;
if(g_check_recv_instruct_cnt == CheckRecvInstrctCntThreshold)
{
g_check_recv_instruct_cnt = 0;
flag_recv_instruct = false;
}
//delay ms service
gDelayCounter ++;
if(gDelayCounter == Delay1msTresh)
Expand Down
3 changes: 3 additions & 0 deletions Src/global.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ volatile uint8_t gpwmen = 0;
volatile uint8_t gbutton = 0;
volatile uint8_t gbuttonedge = NoneEdge;

bool flag_recv_instruct=false;
int g_check_recv_instruct_cnt = 0;

2 changes: 2 additions & 0 deletions Src/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,6 @@ extern volatile uint8_t gpwmen;
extern volatile uint8_t gbutton;
extern volatile uint8_t gbuttonedge;

extern bool flag_recv_instruct;
extern int g_check_recv_instruct_cnt;
#endif /*__GLOBAL__H__*/
11 changes: 11 additions & 0 deletions Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ void periph_init(void)/*{{{*/
}/*}}}*/
void RC_Process(void)
{
static int not_recv_instruct_cnt=0;
#ifdef Test_Tune_PID
float tf;
static int tune_denoise_cnt=0;
Expand Down Expand Up @@ -319,6 +320,16 @@ void RC_Process(void)
//motor enable
{
gpwmen = 1;
if(false == flag_recv_instruct)
{
//flag_recv_instruct = true;
if(not_recv_instruct_cnt < 1000)
not_recv_instruct_cnt++;
}
else
not_recv_instruct_cnt = 0;
if(not_recv_instruct_cnt > 200)
gpwmen =0;
gLEDCounterR = LED_Hang;
LED_R_Set(LED_On);

Expand Down
4 changes: 3 additions & 1 deletion Src/others/DataReceiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void DRReceiver(uint8_t data)
uint8_t step;
uint8_t i;
uint16_t* temp;
uint16_t tempdata;
uint16_t tempdata;//tempdata才16位,所以要求传进来的数据不超过65535.

if(DRProcess < DRNumOfCheckChar)
{
Expand All @@ -46,6 +46,8 @@ void DRReceiver(uint8_t data)
for(i = 0;i < DRNumOfDataInPackage;i ++)
DRDataPointerProcess[i] = DRDataNull;
DRProcess = DRnull;
flag_recv_instruct=true;
g_check_recv_instruct_cnt=0;
DRUserProcedureAfterReceiveOnce;
}else
{
Expand Down

0 comments on commit c87e93c

Please sign in to comment.