博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
悬挂运动控制系统 源代码 (05年电赛)
阅读量:6977 次
发布时间:2019-06-27

本文共 4366 字,大约阅读时间需要 14 分钟。

题目连接:05年电赛 悬挂运动控制系统 源代码

系统: 2块STM32   A为上位机 液晶显示 语言提示 摄像头 + NRF 发送目标路径,  所有步进电机等由STM32 B控制。

下位机 main.c

 

#include "main.h"#include "math.h"#include 
void DrawCircle(){ int x , y; Move2XY(15, 50); for(x = 15; x <= 65; ++x) { y = sqrt( 625 - (x - 40)*(x - 40) ) + 50; Move2XY(x, y); } for(x = 65; x >= 15; --x) { y = 50 - sqrt( 625 - (x - 40)*(x - 40) ); Move2XY(x, y); }}void DrawL(){ int i; for(i = 0; i < 100; ++i) { Move2XY(0, i); } for(i = 0; i < 80; ++ i) { Move2XY(i,99); }}void DrawPoly(){ int i; for(i = 0; i < 100; ++i) { Move2XY(0, i); } for(i = 0; i < 80; ++ i) { Move2XY(i,99); } for(i = 0; i < 100; ++i) { Move2XY(79, 100 - i); } for(i = 0; i < 80; ++ i) { Move2XY(80 - i,0); }}int main(void){ int i; SystemInit(); GPIO_INIT(); COM1Init(115200); DrawPoly(); //DrawL(); // while(1) { DrawCircle(); }}

 

控制引擎

 

#include "Contral.h"#include "delay.h"#include "math.h"#include "usart.h"#include "stdio.h"double LeftArm = 115.974, RightArm = 149.164;int    NowX = 0, NowY = 0;int    StepTim = 10;int STEP[4] = {0x0011, 0x0014, 0x0044, 0x0041};int LSTEPID = 0, RSTEPID = 0;void GPIO_INIT(void){  	GPIO_InitTypeDef GPIO_InitStructure;  	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD , ENABLE);    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA , ENABLE);  	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_2 | GPIO_Pin_4 | GPIO_Pin_6;  	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;  	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;  	GPIO_Init(GPIOD, &GPIO_InitStructure);	    GPIO_Init(GPIOA, &GPIO_InitStructure);}void LeftStepRun(int CTR, int Delay1_4){    int i = 0;    if(CTR > 0)    {        CTR += LSTEPID;        for(i = LSTEPID; i < CTR; ++i, ++LSTEPID)        {            GPIO_Write(GPIOD, STEP[i % 4]);            delay_ms(Delay1_4);        }        if(LSTEPID > 10000) LSTEPID = 0;    }        //back    if(CTR < 0)    {       CTR = -CTR + LSTEPID;       for(i = LSTEPID; i < CTR; ++i, ++LSTEPID)       {           GPIO_Write(GPIOD, STEP[(4 - (i % 4)) % 4]);           delay_ms(Delay1_4);       }       if(LSTEPID > 10000) LSTEPID = 0;    }  }void RightStepRun(int CTR, int Delay1_4){    int i = 0;        //foward    if(CTR > 0)    {        CTR += RSTEPID;        for(i = RSTEPID; i < CTR; ++i, ++RSTEPID)        {            GPIO_Write(GPIOA, STEP[i % 4]);            delay_ms(Delay1_4);        }        if(RSTEPID > 10000) RSTEPID = 0;    }        //back    if(CTR < 0)    {       CTR = -CTR + RSTEPID;       for(i = RSTEPID; i < CTR; ++i, ++RSTEPID)       {           GPIO_Write(GPIOA, STEP[(4 - (i % 4)) % 4]);           delay_ms(Delay1_4);       }       if(RSTEPID > 10000) RSTEPID = 0;    }  }void Step2XY(int x, int y){    int i, j;    int signL = 1, signR = 1;    double tempLeftArm = 0, tempRightArm = 0;    double LStepCtr = 0, RStepCtr = 0;        tempLeftArm = sqrt((x + 15)*(x + 15) + (115 - y)*(115 - y));    LStepCtr = (tempLeftArm - LeftArm) / 0.05813;           tempRightArm = sqrt((95 - x)*(95 - x) + (115 - y)*(115 - y));    RStepCtr = (tempRightArm - RightArm) / 0.05813;    //     printf("LStepCtr = %lf  RStepCtr = %lf !!",LStepCtr,RStepCtr );//     LeftStepRun(LStepCtr, 10);//     RightStepRun(RStepCtr, 10);//     printf("x = %d,, y = %d,,LStepCtr = %lf RStepCtr = %lf \n", x, y, LStepCtr, RStepCtr);    i = 0; j = 0;    if(LStepCtr < 0) LStepCtr = -LStepCtr, signL = -1;    if(RStepCtr < 0) RStepCtr = -RStepCtr, signR = -1;    while(i < LStepCtr || j < RStepCtr)    {        if(i < LStepCtr) LeftStepRun(signL, StepTim);        if(j < RStepCtr) RightStepRun(signR, StepTim);        i++;        j++;    }        i = LStepCtr;    j = RStepCtr;    if(j != 0)RightArm = tempRightArm;    if(i != 0)LeftArm = tempLeftArm;}int _abs(int a){    if(a > 0)  return a;    else return -a;}int _max(int a, int b){    if(a > b) return a;    else return b;}void Move2XY(int x, int y){    int tempx, tempy, i;    int xError = x - NowX, yError = y - NowY;    int MaxError = _max(_abs(xError), _abs(yError));        double xSon = xError*1.0 / MaxError, ySon = yError*1.0 / MaxError;        for(i = 0; i <= MaxError; ++i)    {        tempx = NowX + xSon * i;        tempy = NowY + ySon * i;        Step2XY(tempx, tempy);    }      NowX = x, NowY = y;}

 

 

转载地址:http://khupl.baihongyu.com/

你可能感兴趣的文章
XML 标签 首字母转换为大写
查看>>
Hystrix 超时配置重写
查看>>
kvm cpu的亲和性绑定配置
查看>>
基于Servlet+JDBC+Bootstrap+MySQL+AJAX权限管理系统项目实战教程
查看>>
美团选择电影票
查看>>
WordPress标签
查看>>
Cookie/Session机制详解
查看>>
php函数get_magic_quotes_gpc详解
查看>>
GAMIT安装备忘
查看>>
资质申报 - 系统集成企业资质等级评定条件(2012年修定版)
查看>>
Oracle Study之--Oracle等待事件(3)
查看>>
PHP引擎php.ini 和fastcti优化
查看>>
在Linux下如何安装配置SVN服务
查看>>
军哥lnmp一键安装包nginx支持pathinfo配置
查看>>
Android问题汇总
查看>>
Linux基础(二)--基础的命令ls和date的详细用法
查看>>
谭浩强《C++程序设计》书后习题 第十三章-第十四章
查看>>
正则表达式测试工具 Regex Tester 的使用方法
查看>>
解决Mysql:unrecognized service错误的方法(CentOS)附:修改用户名密码
查看>>
no no no.不要使用kill -9.
查看>>