juechafun/01-项目/2604-编程软件/提示词-需求说明-改造main.md

612 lines
8.6 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
#领域/未知
#复盘/0 #临时/备忘 #状态/待处理
20260507-备忘-主题名-文件内容
## 一句话描述
[________]
---
[主要涉及文件]
mainwindow.cpp
[需求说明]
我已经更新 gen_main.c 为最新测试 main.c 内容
下面是我发现的问题:
1. RobotInit(); 不应该出现在 start_task 中
2. NYT_USER_UCOS();
    while(1);的位置没有在 int main() 的最后
[核心需求]
## 最终组合的 main.c
[初始代码]
void start_task(void) {
    [自定义代码]
}
int main() {
    [优先运行代码]
    NYT_USER_UCOS();
    while(1);
}
## 右侧预览显示
void start_task(void) {
    [自定义代码]
}
[注意事项]
1. 在修改代码时不要一次性进行太多颠覆性修改,要引导我来逐步分析和实现
2. gen_main.c 中的内容是最新生成的 main.c
[补充说明]
下方代码仅供测试是否正常组合的参考,实际应用会灵活修改
## 初始代码
```c
#include "main.h"
#include "2020zhjn.h"
#include "Servo.h"
int s2_k=200;//1号舵机张开
int s2_b=120;//1号舵机闭合
int s_color=0;//颜色识别变量1
int beep_t=8; //非十字模块路口鸣叫时间
int beep_t1=4;//过十字模块路口鸣叫时间
int SD1=60;//非十字拼装块直线速度
int SD2=45;//非十字拼装块转弯速度
int SD3=55;//非十字拼路口冲出速度
/*高低速轨迹函数*/
void H_LOW(int H_L)//1为高速  0为低速
{
 if(H_L==0)DRIVE_CROSS(7,2,-4,-7,-10);//低速走轨迹函数
 else DRIVE_CROSS(8,6,1,-2,-4);//高速走轨迹函数
}
int flog=0;
int fga=0;
int fdou=0;
/*多任务系统参数设置*/
void *User_Task1_Handle=NULL;
void *User_Task2_Handle=NULL;
void *User_Task3_Handle=NULL;
void *User_Task4_Handle=NULL;
void *User_Task5_Handle=NULL;
void USERTASK1();
void USERTASK2();
void USERTASK3();
void USERTASK4();
void USERTASK5();
int red_blue_all=8,gray_green_all=4;//木块总数量
int red_blue=0,gray_green=0;//识别到的木块数
/****垃圾分拣任务舵机角度设置,
以下参数必调,否则无法完成任务****/
int s9_zuo=53,s9_you=182,s9_fuwei=116;
int s10_xia=173,s10_zhong=125,s10_fang=75;
int s8_xia=70,s8_zhong=125,s8_fang=165;
/********************************
以下函数为小车抖动(电机)函数,理解后也可自行修改
****************************************/
void q_h_dou(int n)//前后抖次数
{
    int speed=70;
    int i;
    for(i=0;i<n;i++)
    {
        M_T(50,speed,speed);
        M_T(70,-speed,-speed);
    }
    msleep(800);
}
void servo9_dou(int n)//9号舵机抖
{
    int speed=70;
    int i;
    for(i=0;i<n;i++)
    {
        S_K(9,s9_zuo,500);S_K(9,s9_you,800);
        S_K(9,s9_fuwei,500);
        //M_T(70,-speed,-speed);
    }
    OSTimeDly(1000);
}
/********************************
以下函数为颜色识别函数,理解后也可自行修改
红蓝识别函数ReadColor(1) 返回值1为红色 2为蓝色
灰绿识别函数ReadColor(2) 返回值3为灰色 4为绿色
其他颜色可自行修改函数
****************************************/
int Read_Color(u8 mode)//
{
    u8 iii=0;
    int I_R1,I_G1,I_B1,I_C1;
    int I_R2,I_G2,I_B2,I_C2;
    int I_R3,I_G3,I_B3,I_C3;
    int I_R4,I_G4,I_B4,I_C4;
    //红色木块采集RGB值数据
    I_R1 = Read_Addr(900);
    I_G1 = Read_Addr(901);
    I_B1 = Read_Addr(902);
    I_C1 = Read_Addr(903);
    //蓝色木块采集RGB值数据
    I_R2 = Read_Addr(904);
    I_G2 = Read_Addr(905);
    I_B2 = Read_Addr(906);
    I_C2 = Read_Addr(907);
    //灰色木块采集RGB值数据
    I_R3 = Read_Addr(908);
    I_G3 = Read_Addr(909);
    I_B3 = Read_Addr(910);
    I_C3 = Read_Addr(911);
    //绿色木块采集RGB值数据
    I_R4 = Read_Addr(912);
    I_G4 = Read_Addr(913);
    I_B4 = Read_Addr(914);
    I_C4 = Read_Addr(915);
    //木块容差调整默认为50可通过主机修改
    RED_V  = Read_Addr(916);//红色模块容差调整
    BLUE_V = Read_Addr(917);//蓝色模块容差调整
    HUI_V  = Read_Addr(918);//灰色模块容差调整
    GRE_V  = Read_Addr(919);//绿色模块容差调整
    OSIntEnter();
    TCS34725_GetRawData_USART(RGB);//颜色数据获取
    OSIntExit();
    while((((RGB[0]>3900)||(RGB[1]>3900)||(RGB[2]>3900)||(RGB[3]>3900))&&(iii<20)))
    {
        iii++;
        OSIntEnter();
        TCS34725_GetRawData_USART(RGB);
        OSIntExit();
    }
    //以上代码无需修改 ////////////////////////
    //RGB[0]:实际读取R值
    //RGB[1]:实际读取G值
    //RGB[2]:实际读取B值
    //RGB[3]:实际读取C值
    if(mode==1)//红蓝识别模式
    {
        if(
          (RGB[0]>(I_R1-100))&&(RGB[0]<(I_R1+100))
        &&(RGB[3]>(I_C1-50 ))&&(RGB[3]<(I_C1+50))
        )return 1;//红色
       else if(
          (RGB[2]>(I_B2-100))&&(RGB[2]<(I_B2+100))
        &&(RGB[3]>(I_C2-50))&&(RGB[3]<(I_C2+50))
        )return 2;//蓝色
        else return 0;
    }
    else if(mode==2)//灰绿识别模式
    {
        if(
          (RGB[0]>(I_R3-50))&&(RGB[0]<(I_R3+50))
        &&(RGB[1]>(I_G3-50))&&(RGB[1]<(I_G3+50))
        &&(RGB[3]>(I_C3-50))&&(RGB[3]<(I_C3+50))
        )return 3;//灰色
        else if(
          (RGB[0]>(I_R4-50))&&(RGB[0]<(I_R4+50))
        &&(RGB[1]>(I_G4-50))&&(RGB[1]<(I_G4+50))
        &&(RGB[3]>(I_C4-50))&&(RGB[3]<(I_C4+50))
        )return 4;//绿色
        else return 0;
    }
    //可自定义其他模式
}
/********************************
以下函数为颜色识别函数,理解后也可自行修改
其他颜色木块识别函数ReadColor_other
返回值1为颜色1 2为颜色2
其他颜色可自行修改函数
****************************************/
int Read_Color_other(void)
{
    u8 iii=0;
    int I_R1,I_G1,I_B1,I_C1;
    int I_R2,I_G2,I_B2,I_C2;
    int I_R3,I_G3,I_B3,I_C3;
    int I_R4,I_G4,I_B4,I_C4;
    //色块1 RGBC采集数据值
    I_R1 = Read_Addr(922);
    I_G1 = Read_Addr(923);
    I_B1 = Read_Addr(924);
    I_C1 = Read_Addr(925);
    //色块2 RGBC采集数据值
    I_R2 = Read_Addr(926);
    I_G2 = Read_Addr(927);
    I_B2 = Read_Addr(928);
    I_C2 = Read_Addr(929);
    //色块1、色块2 容差调整
    Color1_V = Read_Addr(930);
    Color2_V = Read_Addr(931);
    OSIntEnter();
    TCS34725_GetRawData_USART(RGB);//颜色数据获取
    OSIntExit();
    while((((RGB[0]>3900)||(RGB[1]>3900)||(RGB[2]>3900)||(RGB[3]>3900))&&(iii<20)))
    {
        iii++;
        OSIntEnter();
        TCS34725_GetRawData_USART(RGB);//颜色数据获取
        OSIntExit();
    }
    //以上代码无需修改 ////////////////////////
    if(
      (RGB[0]>(I_R1-50))&&(RGB[0]<(I_R1+50))
    &&(RGB[1]>(I_G1-50))&&(RGB[1]<(I_G1+50))
    &&(RGB[2]>(I_B1-50))&&(RGB[2]<(I_B1+50))
    &&(RGB[3]>(I_C1-50))&&(RGB[3]<(I_C1+50))
    )return 1;//色块1
    else if(
      (RGB[0]>(I_R2-50))&&(RGB[0]<(I_R2+50))
    &&(RGB[1]>(I_G2-50))&&(RGB[1]<(I_G2+50))
    &&(RGB[2]>(I_B2-50))&&(RGB[2]<(I_B2+50))
    &&(RGB[3]>(I_C2-50))&&(RGB[3]<(I_C2+50))
    )return 2;//色块2
    else return 0;
}
/********************************
以下函数为舵机抖动函数,理解后也可自行修改
****************************************/
void duoji_dou(int n)//前后抖次数
{
    int speed=70;
    int i;
    S_K(10,s10_fang,0);S_K(8,s8_fang,600);
    for(i=0;i<n;i++)
    {
      S_K(10,s10_fang+10,0);S_K(8,s8_fang-10,0);delay_ms(20);
      S_K(10,s10_fang,0);S_K(8,s8_fang,0);delay_ms(20);
    }
    delay_ms(500);
}
```
## 优先运行代码
```c
SuDu_motor_Exp1();Com2_Init(115200); //串口初始化
//Com1_Init(115200);
    // DRIVE(7,2,-4,-7,-10);
     H_LOW(1);//默认高速轨迹
    //  DRIVE_CROSS(8,6,1,-2,-4);
      ZHJN_init();//内部代码初始化
     //address_data();
     setTraceIIC(1,4,3);//setTraceIIC(2,4,3);
    Color_tcs34725_Init();
    SPI_OLED_LED_HIGH();
    if(Read_Addr(5)==0||Read_Addr(5)==-1)
    {
       Write_Addr(899,100);Write_Addr(898,100);
       Write_Addr(5,1);
    }
    IIC_servos(9,s9_fuwei);//msleep(200);
    /*舵机测试默认显示值*/
```