Exemplo n.º 1
0
//************************
//Configura sensores e joga erros na tela
//************************
void F_STATE_CONFIG()
{
  MTASK_SET_RUN(MT_BEEP);
  //Enquanto o estado atual for o estado target

  eraseDisplay();
  nxtDisplayCenteredBigTextLine(3, "WAIT");

  while(ESTADO_IS_CURRENT())
  {
    //=====================================
    wait10Msec(100);

    //Seta os tipos de porta no NXT
    SensorType[PORT_ARD] = sensorI2CCustom;
    SensorType[PORT_ACC] = sensorI2CCustom;
    SensorType[PORT_COMP] = sensorI2CCustom;

    //Inicia Arduino
    while(!ERRO_SET_CODE(" CF: ARDU ERR",ARDUinit(PORT_ARD)));

    //Inicia Acc Sensor
    while(!ERRO_SET_CODE(" CF: ACC ERR",HTACinit(PORT_ACC)));

    HTACreadAllAxes(PORT_ACC,ACCEL[0],ACCEL[1],ACCEL[2]);
    ACCEL_Offset=ACCEL[ACCEL_AXIS_RAMPA];

    //Inicia Line Leader
    while(!ERRO_SET_CODE(" CF: LL ERR",LLinit(PORT_LL)));

    //Inicia Bussola
    while(!ERRO_SET_CODE(" CF: COMP ERR",HTMCreadHeading(PORT_COMP)>=0));

    //Testa motores
    while(!ERRO_SET_CODE(" CF: MOTOR A",TEST_MOTOR(MA)));

    while(!ERRO_SET_CODE(" CF: MOTOR C",TEST_MOTOR(MC)));

    bMotorReflected[MA] = true;
    bMotorReflected[MC] = true;

    GARRA_H(PORT_ARD, GARRA_H_FECHA);
    wait10Msec(20);


    GARRA_V(PORT_ARD,GARRA_V_SOBE);
    wait10Msec(30);
    GARRA_V(PORT_ARD,GARRA_V_PARA);
    GARRA_H(PORT_ARD, GARRA_H_PARA);

    setSafe(3,300);
    setSafe(4,300);

    ESTADO_SET_TARGET(ST_WAIT);
    //=====================================
  }
}
Exemplo n.º 2
0
//************************
// Entra na Sala
//************************
void F_STATE_ENTRA()
{
  PlayTone(500,10);
  MTASK_SET_RUN(MT_STOP_BUTTON);

  while(ESTADO_IS_CURRENT())
  {
    //=====================================

    MV_StopMotors();
	  GARRA_V(PORT_ARD,GARRA_V_SOBE);
	  wait10Msec(50);
	  GARRA_V(PORT_ARD,GARRA_V_PARA);

    setSafe(0,5000);
    MV_Reto_Unlimited(60);
    while(getSafe(0) && !ReadTouch(PORT_ARD)==0);
    MV_Reto(80,0,7);
    MV_Reto(-60,100);
    ESTADO_SET_TARGET(ST_WAIT);
    //=====================================
  }
}
Exemplo n.º 3
0
SafeListView::SafeListView(QWidget *parent, const char *name, Safe *safe)
  : Q3ListView(parent, name), m_target_is_child(false)
{
  setShowSortIndicator(true);
  setAllColumnsShowFocus(true);
  setAcceptDrops(true);
  viewport()->setAcceptDrops(true);
  setRootIsDecorated(false);

  addColumn(tr("Name"), 150);
  addColumn(tr("User"), 100);
  addColumn(tr("Notes"), 150);
  addColumn(tr("Last Modified"), 100);
  addColumn(tr("Accessed on"), 100);
  addColumn(tr("Created on"), 100);
  addColumn(tr("Lifetime"), 100);
#ifdef DEBUG
  addColumn(tr("Group"));
#endif
  setSafe(safe);

  connect(this, SIGNAL(dropped(QDropEvent *)), SLOT(dropped(QDropEvent *)));
}
Exemplo n.º 4
0
void cTerritory::processNode( const cElement* Tag, uint hash )
{
	QString TagName( Tag->name() );
	QString Value( Tag->value() );

	//<guards>
	//  <npc mult="2">npcsection</npc> (mult inserts 2 same sections into the list so the probability rises!
	//	<npc><random list="npcsectionlist" /></npc>
	//  <list id="npcsectionlist" />
	//</guards>
	if ( TagName == "guards" )
	{
		for ( uint i = 0; i < Tag->childCount(); ++i )
		{
			const cElement* childNode = Tag->getChild( i );

			if ( childNode->name() == "npc" )
			{
				uint mult = childNode->getAttribute( "mult" ).toInt();
				if ( mult < 1 )
					mult = 1;

				for ( uint j = 0; j < mult; j++ )
					this->guardSections_.push_back( childNode->value() );
			}
			else if ( childNode->name() == "list" && childNode->hasAttribute( "id" ) )
			{
				QStringList NpcList = Definitions::instance()->getList( childNode->getAttribute( "id" ) );
				QStringList::const_iterator it( NpcList.begin() );
				for ( ; it != NpcList.end(); ++it )
					this->guardSections_.push_back( *it );
			}
		}
	}

	// <fixedlight>number</fixedlight>
	else if ( TagName == "fixedlight" )
		this->fixedlight_ = Value.toShort();

	// <guardowner>text</guardowner>
	else if ( TagName == "guardowner" )
		if ( Value == "the town" )
			this->guardowner_ = "";
		else
			this->guardowner_ = Value;

	// <resores>ORES</resores>
	else if ( TagName == "resores" )
		this->resores_ = Value;

	// <firstcoin>IDofCOIN</firstcoin>
	else if ( TagName == "firstcoin" )
		this->firstcoin_ = Value;

	// <secondcoin>IDofCOIN</secondcoin>
	else if ( TagName == "secondcoin" )
		this->secondcoin_ = Value;

	// <thirdcoin>IDofCOIN</thirdcoin>
	else if ( TagName == "thirdcoin" )
		this->thirdcoin_ = Value;

	// <midilist>MIDI_COMBAT</midilist>
	else if ( TagName == "midilist" )
		this->midilist_ = Value;
	// <extraflags>ExtraFlags</extraflags>
	else if ( TagName == "extraflags" )
		this->extraflags_ = Value.toUShort();
	else if ( TagName == "flags" )
	{
		flags_ = 0;

		for ( unsigned int i = 0; i < Tag->childCount(); ++i )
		{
			const cElement* childNode = Tag->getChild( i );

			if ( childNode->name() == "guarded" )
				setGuarded( true );
			else if ( childNode->name() == "nomark" )
				setNoMark( true );
			else if ( childNode->name() == "nogate" )
				setNoGate( true );
			else if ( childNode->name() == "norecallout" )
				setNoRecallOut( true );
			else if ( childNode->name() == "norecallin" )
				setNoRecallIn( true );
			else if ( childNode->name() == "recallshield" )
				setRecallShield( true );
			else if ( childNode->name() == "noagressivemagic" )
				setNoAgressiveMagic( true );
			else if ( childNode->name() == "antimagic" )
				setAntiMagic( true );
			else if ( childNode->name() == "escortregion" )
				setValidEscortRegion( true );
			else if ( childNode->name() == "cave" )
				setCave( true );
			else if ( childNode->name() == "nomusic" )
				setNoMusic( true );
			else if ( childNode->name() == "noguardmessage" )
				setNoGuardMessage( true );
			else if ( childNode->name() == "noentermessage" )
				setNoEnterMessage( true );
			else if ( childNode->name() == "nohousing" )
				setNoHousing( true );
			else if ( childNode->name() == "nodecay" )
				setNoDecay( true );
			else if ( childNode->name() == "instalogout" )
				setInstaLogout( true );
			else if ( childNode->name() == "noteleport" )
				setNoTeleport( true );
			else if ( childNode->name() == "safe" )
				setSafe( true );
			else if ( childNode->name() == "nocriminalcombat" )
				setNoCriminalCombat( true );
			else if ( childNode->name() == "nokillcount" )
				setNoKillCount( true );
		}
	}

	// <snowchance>50</snowchance>
	else if ( TagName == "snowchance" )
	{
		this->snowchance_ = Value.toUShort();
	}

	// <rainchance>50</rainchance>
	else if ( TagName == "rainchance" )
	{
		this->rainchance_ = Value.toUShort();
	}

	// <rainduration>2</rainduration>
	else if ( TagName == "rainduration" )
	{
		this->rainduration_ = Value.toUShort();
	}
	// <snowduration>2</snowduration>
	else if ( TagName == "snowduration" )
	{
		this->snowduration_ = Value.toUShort();
	}
	// <dryduration>4</dryduration>
	else if ( TagName == "dryduration" )
	{
		this->dryduration_ = Value.toUShort();
	}
	// <rainrangeduration>1</rainrangeduration>
	else if ( TagName == "rainrangeduration" )
	{
		this->rainrangeduration_ = Value.toUShort();
	}
	// <snowrangeduration>1</snowrangeduration>
	else if ( TagName == "snowrangeduration" )
	{
		this->snowrangeduration_ = Value.toUShort();
	}
	// <dryrangeduration>1</dryrangeduration>
	else if ( TagName == "dryrangeduration" )
	{
		this->dryrangeduration_ = Value.toUShort();
	}
	// <minintensity>1</minintensity>
	else if ( TagName == "minintensity" )
	{
		this->minintensity_ = Value.toUShort();
	}
	// <maxintensity>1</maxintensity>
	else if ( TagName == "maxintensity" )
	{
		this->maxintensity_ = Value.toUShort();
	}
	// <tradesystem>
	//		<good num="1">
	//			<buyable>10</buyable>
	//			<sellable>20</sellable>
	//			<randomvalue min="10" max="20" />
	//		</good>
	//		<good ...>
	//		...
	//		</good>
	// </tradesystem>
	else if ( TagName == "tradesystem" )
	{
		for ( unsigned int i = 0; i < Tag->childCount(); ++i )
		{
			const cElement* childNode = Tag->getChild( i );

			good_st goods;
			goods.buyable = 0;
			goods.sellable = 0;
			goods.rndmin = 0;
			goods.rndmax = 0;
			uint num = 0xFFFFFFFF;

			if ( childNode->name() == "good" )
			{
				if ( childNode->hasAttribute( "num" ) )
					num = childNode->getAttribute( "num" ).toInt();

				for ( unsigned int j = 0; j < childNode->childCount(); ++j )
				{
					const cElement* chchildNode = childNode->getChild( j );

					QString childValue = chchildNode->value();

					if ( chchildNode->name() == "buyable" )
						goods.buyable = childValue.toInt();
					else if ( chchildNode->name() == "sellable" )
						goods.sellable = childValue.toInt();
					else if ( chchildNode->name() == "randomvalue" )
					{
						goods.rndmin = chchildNode->getAttribute( "min" ).toInt();
						goods.rndmax = chchildNode->getAttribute( "max" ).toInt();
					}
				}
			}

			if ( num != 0xFFFFFFFF )
				this->tradesystem_[num] = goods;
		}
	}

	// <region id="Cove Market Place">
	//		...region nodes...
	// </region>
	else if ( TagName == "region" )
	{
		cTerritory* toinsert_ = new cTerritory( Tag, this );
		this->subregions_.push_back( toinsert_ );
	}
	else if ( TagName == "teleport" )
	{
		if ( !Tag->hasAttribute( "source" ) )
		{
			Console::instance()->log( LOG_ERROR, tr("processing teleport tag, missing source attribute") );
			return;
		}

		if ( !Tag->hasAttribute( "destination" ) )
		{
			Console::instance()->log( LOG_ERROR, tr("processing teleport tag, missing destination attribute") );
			return;
		}
		Coord source, destination;
		if ( !parseCoordinates( Tag->getAttribute( "source" ), source ) )
		{
			Console::instance()->log( LOG_ERROR, tr("parsing source attribute, not a valid coordinate vector") );
			return;
		}
		if ( !parseCoordinates( Tag->getAttribute( "destination" ), destination ) )
		{
			Console::instance()->log( LOG_ERROR, tr("parsing destination attribute, not a valid coordinate vector") );
			return;
		}
		bool bothways = Tag->hasAttribute( "bothways" );
		teleporters_st teleporter;
		teleporter.source = source;
		teleporter.destination = destination;
		teleporters.append( teleporter );
		if ( bothways )
		{
			teleporter.source = destination;
			teleporter.destination = source;
			teleporters.append( teleporter );
		}
	}
	else
		cBaseRegion::processNode( Tag, hash );
}
Exemplo n.º 5
0
tentacle* RecoverySet::recover(std::vector<grid_cart_point> collision_points)
{
    setSafe(collision_points);
    return getBestTent();
}
Exemplo n.º 6
0
//************************
// Passa do GAP
//************************
void F_STATE_GAP()
{
  MTASK_SET_RUN(MT_ACCEL,MT_LL,MT_STOP_BUTTON);



  int ZZDir = 1;
  int Move = 90;
  int MA_enc;
  int MC_enc;

  /*
   * Checa se foi uma curva de 90o
   * e se alinha na linha
   */
  if(getSafe(2)){
    TryAlign++;
  }else{
	  TryAlign = 0;
	}
	setSafe(1,4000);
	if(TryAlign==0){
    nMotorEncoder[MA] = 0;
	  nMotorEncoder[MC] = 0;
	  for(int i = 0; i < 90; i++){
	    while(getSafe(1) && abs(nMotorEncoder[MA]) <i && !ACCEL_Rampa){
	      motor[MA]=-50;
	      motor[MC]=0;
	    }

	    while(getSafe(1) && abs(nMotorEncoder[MC]) <i && !ACCEL_Rampa){
	      motor[MA]=0;
	      motor[MC]=-50;
	    }
	    MV_StopMotors();
	    if(LL_Avr > 0){
	      MV_Reto(-50,40);
	      break;
	    }
	  }
  }

  setSafe(2,2000);

  MC_enc = nMotorEncoder[MC];
  motor[MA] = 0;
  motor[MC] = 50*ZZDir;
  while(getSafe(1) && abs(nMotorEncoder[MC] - MC_enc) < Move/2 && !ACCEL_Rampa){
    if(LL_Avr > 0){
      ESTADO_SET_TARGET(ST_LINHA);
      break;
    }
  }
  MV_StopMotors();

  while(ESTADO_IS_CURRENT())
  {
    //=====================================



    //Faz um zigue zague

    MA_enc = nMotorEncoder[MA];
    motor[MA] = 50*ZZDir;
    motor[MC] = 0;
    while(getSafe(1) && abs(nMotorEncoder[MA] - MA_enc) < Move && !ACCEL_Rampa){
      if(LL_Avr > 0){
        ESTADO_SET_TARGET(ST_LINHA);
        break;
      }
    }

    MV_StopMotors();

    MC_enc = nMotorEncoder[MC];
    motor[MA] = 0;
    motor[MC] = 50*ZZDir;
    while(getSafe(1) && abs(nMotorEncoder[MC] - MC_enc) < Move && !ACCEL_Rampa){
      if(LL_Avr > 0){
        ESTADO_SET_TARGET(ST_LINHA);
        break;
      }
    }

    MV_StopMotors();

    if(!getSafe(1)){
      ZZDir = ZZDir*-1;
      setSafe(1,5000);
    }

    //Se detectou rampa com acceleracao, sobe a rampa
    if(ACCEL_Rampa)ESTADO_SET_TARGET(ST_SOBE);

    //=====================================
  }
}
Exemplo n.º 7
0
sub MTASK_DOTASK(int MTASK_ID){
  switch (MTASK_ID)
  {
    //********
    case MT_DEFAULT:
	    wait1Msec(1);
	    break;

    //********
    case MT_BEEP:
	    PlayTone(200, 12);
	    wait10Msec(120);
	    break;

    //********
	  case MT_STOP_BUTTON:
	    if(nNxtButtonPressed==BT_ENTER)
	    {
	      int static TimeDif;
	      TimeDif=time10[T4];
	      while(nNxtButtonPressed==BT_ENTER){
	        if(time10[T4]-TimeDif>50)
	        {
    	      MV_StopMotors();
    	      ClearSounds();
	          PlaySound(soundBlip);
	          ESTADO_SET_TARGET(ST_WAIT);
	          break;
	        }
	      }
	    }
	    break;

	  //********
    case MT_ACCEL:

      if(!getSafe(3))
      {
        hogCPU();
        HTACreadAllAxes(PORT_ACC,ACCEL[0],ACCEL[1],ACCEL[2]);
        releaseCPU();
        if(abs(ACCEL[ACCEL_AXIS_RAMPA]-ACCEL_Offset)>ACCEL_DELTA){
          if (ACCEL_Filter++ > 2){
            ACCEL_Rampa = true;
            ACCEL_Filter = 3;
          }
        }else{
          if (ACCEL_Filter-- < 2){
            ACCEL_Filter = 0;
            ACCEL_Rampa = false;
          }
        }
        setSafe(3,300);
      }

	    break;

	  //********
    case MT_TOQUE:
	    wait1Msec(1);
	    break;

	  //********
    case MT_LL:
      hogCPU();
	    LL_Avr = LLreadAverage(PORT_LL);
	    LL_IO  = LLreadResult(PORT_LL);
	    releaseCPU();
	    wait1Msec(5);

	    break;

	  //********
    case MT_US:
	    wait10Msec(3);
	    hogCPU();
      ReadAllUS_short(PORT_ARD,USwall);
      releaseCPU();
	    break;

  }
}