コード例 #1
0
ファイル: message.c プロジェクト: robotronik/archives
void fin(void) {
	motors_stop();
	while (1) {
		allumer_del();
		pause_ms(500);
		eteindre_del();
		pause_ms(500);
	}
}
コード例 #2
0
ファイル: init.c プロジェクト: robotronik/archives
void io_init(void)
{
	// "All port pins are defined as inputs after a Reset"

	// Reglage du PORTA
	//_TRISA0 = 1;	// MOTOR_LEFT_CURRENT
	//_TRISA1 = 1;
	//_TRISA2 = 1;	// MOTOR_SF

	// Reglage du PORTB
	//U1MODEbits.UARTEN = 0b0; // UART déconnecté
	//_TRISB2 = 0;
	_TRISB3 = 1;

	_TRISB4 = 0;	// Motor_enable
	_RB4 = 1;
	pause_ms(1);
	_TRISB5 = 0;	// DEL en mode output
	_RB5 = 1;	 	// On eteint la DEL par defaut
	//_TRISB6 = 1;	// Coder right B
	//_TRISB7 = 1;	// Coder right A
	//_TRISB10 = 1;	// Coder left B
	//_TRISB11 = 1;	// Coder left A

	_TRISB12 = 0;	// MOTEUR IN1 right
	_RB12 = 0;		// PWM en IO général si non-utilisé (au moins 2 broches sur 4)
	_TRISB13 = 0;	// MOTEUR IN2 right
	_RB13 = 0;
	_TRISB14 = 0;	// MOTEUR IN1 left
	_RB14 = 0;
	_TRISB15 = 0;	// MOTEUR IN2 left
	_RB15 = 0;
}
コード例 #3
0
ファイル: asser.c プロジェクト: robotronik/archives
void asservir()
{
	if(consigne_alpha != 0)
	{
		asser_tourner(consigne_alpha);
		pause_ms(200);	// peut etre a changer	
		return;
	}
	else if(consigne_delta != 0)
	{
		asser_avancer(consigne_delta);
		pause_ms(200);	// peut etre a changer
		return;
	}
	else
	{
		motors_stop();
	}
}
コード例 #4
0
ファイル: strategie.c プロジェクト: robotronik/archives
void evitementObstacle(InfoMvt *infoMvt) {
    if (getDistance(!(infoMvt->sensMvt)) > DISTANCE_PROXIMITE) { // On peut manœvrer
        // On recule, on se tourne de 90° et on avance
        //        Angle currentAlpha = getAlphaAbs();

        sendDelta(-DISTANCE_EVITEMENT);
        sendAlpha(90);
        if (getDistance(infoMvt->sensMvt) > DISTANCE_PROXIMITE) {
            sendDelta(+DISTANCE_EVITEMENT);
        } else {
            // On est un peu coinsé !
        }
    } else {
        // On tourne sur place
        sendAlpha(45);
        if (getDistance(infoMvt->sensMvt) > DISTANCE_PROXIMITE) {
            pause_ms(1000);
        }
    }
}
コード例 #5
0
ファイル: main.c プロジェクト: robotronik/archives
int main() {
    long int tickG = 0, tickD = 0;
    long int vG=7900, vD=7900;
    init();


    while (tickG < 10 && tickD < 10)
    {
        vG += 20;
        vD += 20;
        tickG = 0;
        tickD = 0;
        motors_reset_qei();
        motors_set_speed(echelle(vG), echelle(vD));
        pause_ms(70);
        motors_get_qei(&tickG, &tickD);
    }
    motors_set_speed(0, 0);
    AD_minSpeed = (long int)((float)vG*1.1);
    asser();
    
    return 0;
}
コード例 #6
0
ファイル: endgame.cpp プロジェクト: jaksd/Liberal-Crime-Squad
/* endgame - checks if a constitutional amendment is ratified */
char ratify(int level,int lawview,int view,char congress,char canseethings)
{
   if(canseethings)
   {
      music.play(MUSIC_ELECTIONS);
      erase();

      set_color(COLOR_WHITE,COLOR_BLACK,1);

      move(0,0);
      addstr("The Ratification Process:");
   }

   //THE STATE VOTE WILL BE BASED ON VIEW OF LAW
   int mood=publicmood(lawview);
   //OR OF A PARTICULAR ISSUE
   if(view>=0) mood=attitude[view];

   //CONGRESS
   bool ratified=false;

   int y=0;

   if(congress)
   {
      ratified=true;

      if(canseethings)
      {
         move(0,62);
         addstr("House");

         move(0,70);
         addstr("Senate");

         move(24,0);
         addstr("Press any key to watch the Congressional votes unfold.     ");

         getkey();
      }

      bool yeswin_h=false,yeswin_s=false;
      int yesvotes_h=0,yesvotes_s=0,vote,s=0;

      for(int l=0;l<HOUSENUM;l++)
      {
         vote=house[l];
         if(vote>=-1&&vote<=1) vote+=LCSrandom(3)-1;

         if(level==vote) yesvotes_h++;

         if(l==HOUSENUM-1) if(yesvotes_h>=HOUSESUPERMAJORITY) yeswin_h=true;

         if(canseethings)
         {
            if(l==HOUSENUM-1&&yeswin_h) set_color(COLOR_WHITE,COLOR_BLACK,1);
            else if(l==HOUSENUM-1) set_color(COLOR_BLACK,COLOR_BLACK,1);
            else set_color(COLOR_WHITE,COLOR_BLACK,0);
            move(2,62);
            addstr(yesvotes_h);
            addstr(" Yea");

            if(l==HOUSENUM-1&&!yeswin_h) set_color(COLOR_WHITE,COLOR_BLACK,1);
            else if(l==HOUSENUM-1) set_color(COLOR_BLACK,COLOR_BLACK,1);
            else set_color(COLOR_WHITE,COLOR_BLACK,0);
            move(3,62);
            addstr(l+1-yesvotes_h);
            addstr(" Nay");
         }

         if(l%4==0&&s<SENATENUM)
         {
            vote=senate[s++];
            if(vote>=-1&&vote<=1) vote+=LCSrandom(3)-1;

            if(level==vote) yesvotes_s++;
         }

         if(l==HOUSENUM-1&&yesvotes_s>=SENATESUPERMAJORITY) yeswin_s=true;

         if(canseethings)
         {
            if(l==HOUSENUM-1&&yeswin_s) set_color(COLOR_WHITE,COLOR_BLACK,1);
            else if(l==HOUSENUM-1) set_color(COLOR_BLACK,COLOR_BLACK,1);
            else set_color(COLOR_WHITE,COLOR_BLACK,0);
            move(2,70);
            addstr(yesvotes_s);
            addstr(" Yea");

            if(l==HOUSENUM-1&&!yeswin_s) set_color(COLOR_WHITE,COLOR_BLACK,1);
            else if(l==HOUSENUM-1) set_color(COLOR_BLACK,COLOR_BLACK,1);
            else set_color(COLOR_WHITE,COLOR_BLACK,0);
            move(3,70);
            addstr(s-yesvotes_s);
            addstr(" Nay");

            if(l%5==0) pause_ms(10);
         }
      }

      if(!yeswin_h||!yeswin_s) ratified=false;

      y+=4;
   }
   else ratified=true;

   if(level==3) level=-2; // special case for Stalinists: do this after Congress but before the states

   //STATES
   if(ratified)
   {
      ratified=false;

      int yesstate=0;

      if(canseethings)
      {
         set_color(COLOR_WHITE,COLOR_BLACK,1);

         for(int s=0;s<50;s++)
         {
            if(s<17) move(5+s,0);
            else if(s<34) move(5+s-17,27);
            else move(5+s-34,54);
            addstr(statename(s));
         }

         move(24,0);
         addstr("Press any key to watch the State votes unfold.              ");

         getkey();
      }

      int vote,smood;
      for(int s=0;s<STATENUM;s++)
      {
         smood=mood;

         // State biases.
         int multiplier = 5+LCSrandom(3);
         switch(s)
         {
            case 0:smood-=3*multiplier;break;  // Alabama
            case 1:smood-=4*multiplier;break;  // Alaska
            case 2:smood-=1*multiplier;break;  // Arkansas
            case 3:smood-=2*multiplier;break;  // Arizona
            case 4:smood+=4*multiplier;break;  // California
            case 5:break;                      // Colorado
            case 6:smood+=3*multiplier;break;  // Connecticut
            case 7:smood+=3*multiplier;break;  // Delaware
            case 8:break;                      // Florida
            case 9:smood-=2*multiplier;break;  // Georgia
            case 10:smood+=4*multiplier;break; // Hawaii
            case 11:smood-=5*multiplier;break; // Idaho
            case 12:smood+=4*multiplier;break; // Illinois
            case 13:smood-=1*multiplier;break; // Indiana
            case 14:smood+=1*multiplier;break; // Iowa
            case 15:smood-=3*multiplier;break; // Kansas
            case 16:smood-=3*multiplier;break; // Kentucky
            case 17:smood-=1*multiplier;break; // Louisiana
            case 18:smood+=2*multiplier;break; // Maine
            case 19:smood+=3*multiplier;break; // Maryland
            case 20:smood+=6*multiplier;break; // Massachusetts
            case 21:smood+=2*multiplier;break; // Michigan
            case 22:smood+=2*multiplier;break; // Minnesota
            case 23:smood-=4*multiplier;break; // Mississippi
            case 24:smood-=1*multiplier;break; // Missouri
            case 25:smood-=2*multiplier;break; // Montana
            case 26:smood-=3*multiplier;break; // Nebraska
            case 27:break;                     // Nevada
            case 28:smood+=1*multiplier;break; // New Hampshire
            case 29:smood+=3*multiplier;break; // New Jersey
            case 30:smood+=1*multiplier;break; // New Mexico
            case 31:smood+=5*multiplier;break; // New York
            case 32:smood-=1*multiplier;break; // North Carolina
            case 33:smood-=3*multiplier;break; // North Dakota
            case 34:break;                     // Ohio
            case 35:smood-=4*multiplier;break; // Oklahoma
            case 36:smood+=3*multiplier;break; // Oregon
            case 37:smood+=2*multiplier;break; // Pennsylvania
            case 38:smood+=4*multiplier;break; // Rhode Island
            case 39:smood-=5*multiplier;break; // South Carolina
            case 40:smood-=3*multiplier;break; // South Dakota
            case 41:smood-=2*multiplier;break; // Tennessee
            case 42:smood-=4*multiplier;break; // Texas
            case 43:smood-=6*multiplier;break; // Utah
            case 44:smood+=5*multiplier;break; // Vermont
            case 45:break;                     // Virginia
            case 46:smood+=3*multiplier;break; // Washington
            case 47:smood-=2*multiplier;break; // West Virginia
            case 48:smood+=2*multiplier;break; // Wisconsin
            case 49:smood-=5*multiplier;break; // Wyoming
         }

         vote=-2;
         if(LCSrandom(100)<smood)vote++;
         if(LCSrandom(100)<smood)vote++;
         if(LCSrandom(100)<smood)vote++;
         if(LCSrandom(100)<smood)vote++;
         if(vote==1&&!LCSrandom(2)) vote=2;
         if(vote==-1&&!LCSrandom(2)) vote=-2;

         if(canseethings)
         {
            set_color(COLOR_WHITE,COLOR_BLACK,1);
            if(s<17) move(5+s,22);
            else if(s<34) move(5+s-17,49);
            else move(5+s-34,76);
         }
         if(vote==level)
         {
            yesstate++;
            if(canseethings) addstr("Yea");
         }
         else if(canseethings) addstr("Nay");

         if(canseethings)
         {
            if(s==STATENUM-1&&yesstate>=STATESUPERMAJORITY) set_color(COLOR_WHITE,COLOR_BLACK,1);
            else if(s==STATENUM-1) set_color(COLOR_BLACK,COLOR_BLACK,1);
            else set_color(COLOR_WHITE,COLOR_BLACK,0);
            move(23,50);
            addstr(yesstate);
            addstr(" Yea");

            if(s==STATENUM-1&&yesstate<STATESUPERMAJORITY) set_color(COLOR_WHITE,COLOR_BLACK,1);
            else if(s==STATENUM-1) set_color(COLOR_BLACK,COLOR_BLACK,1);
            else set_color(COLOR_WHITE,COLOR_BLACK,0);
            move(23,60);
            addstr(s+1-yesstate);
            addstr(" Nay");

            pause_ms(50);
         }
      }

      if(yesstate>=STATESUPERMAJORITY) ratified=true;
   }

   if(canseethings)
   {
      set_color(COLOR_WHITE,COLOR_BLACK,1);
      move(23,0);
      if(ratified) addstr("AMENDMENT ADOPTED.");
      else addstr("AMENDMENT REJECTED.");
   }

   return ratified;
}
コード例 #7
0
ファイル: debug.c プロジェクト: robotronik/archives
void pause_s(unsigned int n)
{
	unsigned int i;
	for(i=0; i<n; i++)
		pause_ms(1000);
}