• <noframes id="6fok0"><bdo id="6fok0"><listing id="6fok0"></listing></bdo>
    <ruby id="6fok0"></ruby>

    <progress id="6fok0"></progress>
  • <progress id="6fok0"></progress>
    <ruby id="6fok0"><table id="6fok0"></table></ruby>
  • <progress id="6fok0"><u id="6fok0"><form id="6fok0"></form></u></progress>

    24小時(shí)聯(lián)系電話(huà):18217114652、13661815404

    中文

    您當前的位置:
    首頁(yè)>
    電子資訊>
    技術(shù)專(zhuān)題>
    在貓砂項目中稱(chēng)重模塊...

    技術(shù)專(zhuān)題

    在貓砂項目中稱(chēng)重模塊的調試過(guò)程


    主控芯片:STM32F103RCT6
    編程軟件:keil5;sourseinsight4
    串口調試工具:XCOM V2.5

    稱(chēng)重傳感器:HX711

    1.稱(chēng)重模塊的校準模式

    使用標準10kg砝碼進(jìn)行校準,每隔30ms采集一次ad值,一共采集20個(gè)數據,利用冒泡排序取數值大小中間的4個(gè)數據,取其平均值,帶入計算公式(1) ,得到其稱(chēng)重比例系數mWeightCoe,將其寫(xiě)入空閑的flash當中,多次使用砝碼驗證過(guò)后保存最佳值,最佳值會(huì )根據稱(chēng)重模塊各有不同。

    1)計算公式:
    C=A/(D-B)C=A/(D?B)

    實(shí)際重量

    初始ad

    稱(chēng)重系數

    校準ad

    weight( A )

    mZeroAdj( B )

    mWeightCoe( C )

    countD

    void adjust_weight(u16 weight){

    int i=0;

    u32 count=0,sum=0;

    float w = weight*1000;

    u32 countArray[20]={0};

    for(i=0; i<20;i++)

    {

    delay_ms(30);

    countArray[i] =HX711_Read_AD();

    }

    arrsort(countArray,20);//冒泡排序

    //去掉8個(gè)最大的和8個(gè)最小的

    for(i=8;i<12;i++){

    sum+=countArray[i];

    }

    myfree(countArray);

    count = sum/4;

    printf("count:%d\n",count);

    mWeightCoe = w/(count-mZeroAdj);

    printf("mWeightCoe:%f Read_Weight:%d\n",mWeightCoe,HX711_Read_Weight()); 

    STMFLASH_Write(INFO_FLASH_ADDR, (u16*)&mWeightCoe, 2);}

    2.稱(chēng)重模塊的工作模式

    由于本項目要求使用紅外傳感器HC_SR501來(lái)感應貓的進(jìn)入作為安全機制,而此模塊需要有1分鐘左右的初始化時(shí)間,因此在代碼中有一個(gè)屏蔽紅外的標志量以及一個(gè)800毫秒的延時(shí)。
    而稱(chēng)重部分考慮到貓作為一個(gè)活物所以判斷條件是以3稱(chēng)重都大于500g(不含貓砂)判斷貓的進(jìn)入,3稱(chēng)重小于500g(不含貓砂)判斷貓的離開(kāi),同時(shí)能稱(chēng)出貓的體重以及貓屎的重量。貓的體重由于考慮到貓的活動(dòng),所以利用方差選取相對平穩的體重作為貓的真實(shí)體重。

    void weight_task(void * p_arg){

    ////////重量(g///////

    int a_weight=0;

    int b_weight=0;

    int c_weight=0;

    int fangcha;

    OS_ERR err;

    //////int類(lèi)型重量///////

    u32 time_num= 0;

     

    while(1)

    {

    ///計時(shí)60s左右屏蔽人體紅外熱釋電初始化///

    if(time_num<=80)

    {

    time_num++;

    }

    if(time_num>80)

    {

    mDeviceStatus.infrareCatWork=1;

    }

     

    if(mDeviceStatus.workingStatus==WORKING_IDLE){

    c_weight = b_weight;

    b_weight = a_weight;

    a_weight = HX711_Read_Weight_2();

    if(a_weight<-800)

    {

    mDeviceStatus.potStatus=1;//盆在

    }else{

    mDeviceStatus.potStatus=0;//盆不在

    }

    if(mDeviceStatus.catWeightStatus ==WEIGHT_OUT &&

     (a_weight > mDeviceStatus.litterWeight + 500 && 

     b_weight > mDeviceStatus.litterWeight + 500&&

     c_weight > mDeviceStatus.litterWeight + 500))

    {

    mDeviceStatus.catWeightStatus=WEIGHT_IN;

    printf("貓進(jìn)入\n");

    mDeviceStatus.poopTime=0;

    OSTmrStart(&poop_time, &err);

    }

    if(mDeviceStatus.catWeightStatus==WEIGHT_IN){

    fangcha = pow(a_weight-b_weight,2)+pow(a_weight-c_weight,2)+pow(b_weight-c_weight,2);

    if(fangcha<50){

    Cat_In_Weight= b_weight - mDeviceStatus.litterWeight;

    printf("貓重:%d\n",Cat_In_Weight);

    }

    }

    if(mDeviceStatus.catWeightStatus==WEIGHT_IN &&

    (a_weight < mDeviceStatus.litterWeight + 500 &&

    b_weight < mDeviceStatus.litterWeight + 500&&

    c_weight < mDeviceStatus.litterWeight + 500)){

    mDeviceStatus.catWeightStatus = WEIGHT_OUT;

    if(a_weight>mDeviceStatus.litterWeight)

    mDeviceStatus.poopWeight = a_weight - mDeviceStatus.litterWeight;

    else

    mDeviceStatus.poopWeight=0;


    OSTmrStart(&cat_out_wait,&err);//去鏟屎

    OSTmrStop(&poop_time,OS_OPT_TMR_NONE,0,&err);

    printf("貓離開(kāi),如廁時(shí)長(cháng)%.1f 屎重:%d\n",mDeviceStatus.poopTime,mDeviceStatus.poopWeight);

    }

    }else{

    delay_ms(800);

    }

    }}

     




    請輸入搜索關(guān)鍵字

    確定
    色鲁99热99re超碰精品_91精品一区二区三区无码吞精_亚洲国产欧洲综合997久久_一级a性色生活片久久无
  • <noframes id="6fok0"><bdo id="6fok0"><listing id="6fok0"></listing></bdo>
    <ruby id="6fok0"></ruby>

    <progress id="6fok0"></progress>
  • <progress id="6fok0"></progress>
    <ruby id="6fok0"><table id="6fok0"></table></ruby>
  • <progress id="6fok0"><u id="6fok0"><form id="6fok0"></form></u></progress>