簡體   English   中英

用C編程計算過程均值以用contiki實現

[英]calculate process mean with c programming to implement with contiki

我開始在夏季實習期間使用contiki並學習c編程。 我必須計算正在進行的制冷機供電過程的平均值。 我做了這樣的代碼

#include <stdlib.h>
#include <stdio.h>
#include <homadeus/processes/fridge_process.h>
#include <homadeus/devices/78M6610.h>
#include <homadeus/utils/utils.h>

float global_variable;
int current_state = 0; //down =0, up =1

float current_power = 0;
int sample[n];


float get_instant_power()
{

    double scaled_value = MAXIM_78M6610_SCALING_RESOLUTION_POWER_WATTS * maxim_78M6610_get_register_int24(MAXIM_78M6610_P);
    if (scaled_value>0) return scaled_value;
    else return 0;
}

float get_sum()
{   float sum = 0;
    float mean;
    while(1){
        for(int i=1; i<n ; i++){
            sample[i]=get_instant_power();
            sum +=sample[i];
        }

    }
}

int get_current_state()
{
    current_power = get_instant_power();
    if(current_power < 0) return  0;
    else return 1; 
}

PROCESS(hmd_fridge_process, HOMADEUS_FRIDGE_PROCESS_DESCRIPTION);

PROCESS_THREAD(hmd_fridge_process, ev, data) {


  static struct etimer timer;

  PROCESS_BEGIN();



  while(1){
      start = clock();
      etimer_set(&timer, CLOCK_CONF_SECOND);
      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
      ......

    }


  }

  PROCESS_END();
}

如何獲得權力的價值已經得到處理。 每隔一秒鍾,它將顯示消耗的功率(get_instant_power())。 我不知道如何開始和結束樣本編號。 如果我從1開始,應該怎么辦? 另外,是否可以將功率存儲在陣列中以進行累加?

代碼更正

#include <stdlib.h>
#include <stdio.h>
#include <homadeus/processes/fridge_process.h>
#include <homadeus/devices/78M6610.h>
#include <homadeus/utils/utils.h>

float global_variable;
int current_state = 0; //down =0, up =1
float current_power = 0;
int sample =1;
float mean;


float get_instant_power()
{

    double scaled_value = MAXIM_78M6610_SCALING_RESOLUTION_POWER_WATTS * maxim_78M6610_get_register_int24(MAXIM_78M6610_P);
    return scaled_value;
}

float get_sum()
{   float sum = 0;
    int dummy[10];
        for(int i=1; i<sample ; sample++){
            dummy[i]=get_instant_power();
            sum +=dummy[i];
        }
}

int get_current_state()
{
    current_power = get_instant_power();
    if(current_power < 0) return  0;
    else return 1; 
}

PROCESS(hmd_fridge_process, HOMADEUS_FRIDGE_PROCESS_DESCRIPTION);

PROCESS_THREAD(hmd_fridge_process, ev, data) {
  static struct etimer timer;

  PROCESS_BEGIN();

  while(1){
      start = clock();
      etimer_set(&timer, CLOCK_CONF_SECOND);
      PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
      ...
    }


  }

  PROCESS_END();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM