fork download
  1. // Lab 8, Working with structs
  2. // Programmer : Maiar Khattab
  3. // Editor(s) used : Code Blocks 13.12
  4. // Compiler(s) used : Code Blocks 13.12
  5.  
  6. #include<iostream>
  7. using std::cout;
  8. using std::endl;
  9.  
  10. #include<cstdlib>
  11.  
  12. //struct def
  13. struct tod
  14. {
  15. int hour;// the hr , 0-23
  16. int minute;// the min, 0-59
  17. int second;//the sec, 0-59
  18. char descr [32];//the description of the time of day
  19.  
  20. };
  21. //void printTod(const tod&);
  22. int main ()
  23. {
  24. cout << "Lab 8, Working With structs\n";
  25. cout << "Programmer: Maiar Khattab\n";
  26. cout << "Editor(s) used: Code Blocks 13.12\n";
  27. cout << "Compiler(s) used: Code Blocks 13.12\n";
  28. cout << "File: " << __FILE__ << endl;
  29. cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;
  30.  
  31. tod theTime[] = {{12,0,0, "noon"},
  32. {0,0,0," midnight"},
  33. {6,00,00," supper "},
  34. {11,30,0,"bedtime"}};
  35.  
  36. for(int i; i <5; i++)
  37. {
  38. char descr [32];
  39. cout << theTime[i].descr << " is " << theTime[i].hour << ':'
  40. << theTime[i].minute << ":" << theTime[i].second << endl;
  41. }
  42. }
  43.  
  44.  
Success #stdin #stdout 0.01s 5256KB
stdin
 #include "user.h"
#include "../API/controllers.h"         // Discrete-time controllers
 
MPPTracker string1_mppt, string2_mppt;  // Maximum Power Point Trackers
PIDController Ipv_reg;                  // Controller for the PV current
 
tUserSafe UserBackground();
void SlowSubTask();
float SubTaskTimer = 0.0;
bool SubTaskFlag = false;
 
USER_SAFE UserInit(void)
{
  // Configure the main timebases on CLOCK_0:
  Clock_SetPeriod(CLOCK_0, (int)(SWITCHING_FREQUENCY));
 
  // Configure the interrupts:
  ConfigureMainInterrupt(UserInterrupt, CLOCK_0, 0.5);
  RegisterBackgroundCallback(UserBackground);
 
  // Configure the PI controllers:
  ConfigPIDController(&Ipv1_reg, 12.0, 0.3, 0.0, 60, -60, SAMPLING_PERIOD, 10);
 
  // Configure and initialize the MPP-trackers:
  #define increment 0.01
  ConfigMPPTracker(&mymppt, increment, 7.0, 16.0, 1.5, 0.01);
 
  return SAFE;
}

tUserSafe UserInterrupt(void)
{
  // Measure all the necessary quantities:
  Upv = Adc_GetValue(8); // Voltage on the PV string
  Ipv = -Adc_GetValue(0); // PV current
     
  // Execute the current controllers on the MPPT string:
  Epv = Upv - RunPIController(&Ipv_reg, Ipv_ref - Ipv);
  CbPwm_SetDutyCycle(PWM_CHANNEL_3, Epv/Udc);
 
  // Compute the power drawn from the PV panel:
  #define k_iir_lpf 0.05
  Ppv = k_iir_lpf* (Upv*Ipv) + (1.0-k_iir_lpf)* Ppv;
     
  SubTaskTimer += SWITCHING_PERIOD;
  if(SubTaskTimer >= MPPTPERIOD){
    SubTaskTimer = SubTaskTimer - MPPTPERIOD;
    SubTaskFlag  = true;
  }
   
  return SAFE;
}

tUserSafe UserBackground()
{
  if(SubTaskFlag)
  {
    SlowSubTask();
    SubTaskFlag = false;
  }
  return SAFE;
}

void SlowSubTask()
{
  // When appropriate, execute the MPPT algorithm:
  if (enable_MPPT==1){
    // Run the Maximum Power Point Tracking (MPPT) algorithm:
    Ipv_ref = RunMPPTracking(&string_mppt, Ipv, Ppv);
  }
  else{
    // Leave the setpoints unaltered
  }
}
stdout
Lab 8, Working With structs
Programmer: Maiar Khattab
Editor(s) used: Code Blocks 13.12
Compiler(s) used: Code Blocks 13.12
File: prog.cpp
Complied: Dec 17 2024 at 14:13:38

noon is 12:0:0
 midnight is 0:0:0
 supper  is 6:0:0
bedtime is 11:30:0
L?o g� is 1504393768:32764:-1397654528