Esempio n. 1
0
double CalcEngSpeed(double speed, int gear, double pedal, int engineIsRunning)
{
  // in Newton
  double engSpeed, ratio;
  
  if ((gear < 0) || (gear > 5)) runError(1002,55);

  if (engineIsRunning) 
  {
    if (gear==0)
    {
      if (pedal<6) 
      {
        engSpeed = 10;
      }
      else 
      {
        engSpeed = 100;
      }
    } 
    else 
    { 
      // stationary condition
      ratio = EngSpeedToSpeedRatio(gear);
      engSpeed = speed * ratio;
      if (engSpeed > 100) engSpeed = 100;
    }
  } 
  else 
  {
    engSpeed = 0;
  }
  
  return engSpeed;
}
Esempio n. 2
0
double Force(double power, int gear, int isEngineRunning)
{
  // gear==0: idle gear 
  // force in Newton
  // power in kW
  double force;

  double kGearForceFactor[6] =    { 0.0, 
                                    50,  // max at 150 kW  
                                    36.0,  // max at 100 kW
                                    20.0,  // max at 120 kW
                                    18.0,  // max at 100 kW   
                                    30.0   // max at 100 kW 
                                    };
  double kMaxGearForce[6] = { 0.0, 5500, 4600, 4200, 3500, 3000 };

  if ((gear < 0) || (gear > 5)) runError(1001,55);

  if (isEngineRunning)  
  {
    force = power *( kGearForceFactor[gear] );
 
    // limit force   
    if( force > kMaxGearForce[gear]) 
    {
      force = kMaxGearForce[gear];
    }
  }
  else
  {
    force = 0;
  }

  return force;
}
Esempio n. 3
0
void CimAcqImec::run()
{
// ---------
// Configure
// ---------

    setPauseAck( false );

    if( !configure() )
        return;

// -------
// Buffers
// -------

    const int
        tpntPerFetch    = 12,
        tpntPerBlock    = 48,
        apPerTpnt       = p.im.imCumTypCnt[CimCfg::imSumAP],
        lfPerTpnt       = p.im.imCumTypCnt[CimCfg::imSumNeural]
                            - p.im.imCumTypCnt[CimCfg::imSumAP],
        syPerTpnt       = 1,
        chnPerTpnt      = (apPerTpnt + lfPerTpnt + syPerTpnt);

    QVector<float>  lfLast( lfPerTpnt, 0.0F );
    vec_i16         i16Buf( tpntPerBlock * chnPerTpnt );
    ElectrodePacket E;

// -----
// Start
// -----

    atomicSleepWhenReady();

    if( !startAcq() )
        return;

// -----
// Fetch
// -----

// Minus here ala User manual 5.7 "Probe signal inversion"

    const float yscl = -MAX10BIT/0.6F;

    double  lastCheckT  = getTime(),
            startT      = lastCheckT,
            peak_loopT  = 0,
            sumdT       = 0,
            dT;
    int     nTpnt       = 0,
            ndT         = 0;

    while( !isStopped() ) {

        if( isPaused() ) {
            setPauseAck( true );
            usleep( 0.01 * 1e6 );
            continue;
        }

        double  loopT = getTime();
        qint16  *dst;

        // -------------
        // Read a packet
        // -------------

        int err = IM.neuropix_readElectrodeData( E );

        // ------------------
        // Handle empty fetch
        // ------------------

        if( err == DATA_BUFFER_EMPTY ) {

            if( isPaused() )
                continue;

            // BK: Allow up to 5 seconds for (external) trigger.
            // BK: Tune with experience.

            if( loopT - startT >= 5.0 ) {
                runError( "DAQ IMReader getting no samples." );
                return;
            }

            goto next_fetch;
        }

        // -------------------
        // Handle packet error
        // -------------------

        if( err != READ_SUCCESS ) {

            if( isPaused() )
                continue;

            runError(
                QString("IMEC readElectrodeData error %1.").arg( err ) );
            return;
        }

        // ---------------
        // Emplace samples
        // ---------------

        dst = &i16Buf[nTpnt*chnPerTpnt];

        for( int it = 0; it < tpntPerFetch; ++it ) {

            // ap - as is
            for( int ap = 0; ap < apPerTpnt; ++ap )
                *dst++ = yscl*(E.apData[it][ap] - OFFSET);

            // lf - interpolated
            for( int lf = 0; lf < lfPerTpnt; ++lf ) {
                *dst++ = yscl*(lfLast[lf]
                            + it*(E.lfpData[lf]-lfLast[lf])/tpntPerFetch
                            - OFFSET);
            }

            // synch
            *dst++ = E.synchronization[it];
        }

        // update saved lf
        for( int lf = 0; lf < lfPerTpnt; ++lf )
            lfLast[lf] = E.lfpData[lf];

        // -------
        // Publish
        // -------

        nTpnt += tpntPerFetch;

        if( nTpnt >= tpntPerBlock ) {

            owner->imQ->enqueue( i16Buf, nTpnt, totalTPts );
            totalTPts += tpntPerBlock;
            nTpnt     = 0;
        }

        // ---------------
        // Rate statistics
        // ---------------

        dT = getTime() - loopT;

        sumdT += dT;
        ++ndT;

        if( dT > peak_loopT )
            peak_loopT = dT;

next_fetch:
        if( loopT - lastCheckT >= 5.0 && !isPaused() ) {

            float   qf = IM.neuropix_fifoFilling();

            if( qf >= 5.0F ) {  // 5.0F standard

                Warning() <<
                    QString("IMEC FIFOQFill% %1, loop ms <%2> peak %3")
                    .arg( qf, 0, 'f', 2 )
                    .arg( 1000*sumdT/ndT, 0, 'f', 2 )
                    .arg( 1000*peak_loopT, 0, 'f', 2 );

                if( qf >= 95.0F ) {
                    runError(
                        QString(
                        "IMEC Ethernet queue overflow; stopping run...") );
                    return;
                }
            }

            peak_loopT  = 0;
            sumdT       = 0;
            ndT         = 0;
            lastCheckT  = getTime();
        }
    }

// ----
// Exit
// ----

    close();
}
Esempio n. 4
0
void GameClient::runWaitingRoom()
{
  std::string msg="";
  _window.setTitle("Battle Not Cheap - Let's place your ships captain !");
  sf::Sprite spr_grid, spr_wlist,spr_radis;
  sf::Texture txt_grid, txt_wlist,txt_radis;
  sf::Text randomPosText, wlistText;
  sf::Font font;
  sf::Clock clock;
  sf::Time dCLickTime = sf::milliseconds(350);

  // Recuperation du numero de bateau dans click
  // Utilisation dans released
  int boatNumber=-1;
  
  if (!font.loadFromFile("../Fonts/DooM.ttf"))
    exit(-1);
  if (!txt_grid.loadFromFile("../Textures/grid_bg.png"))
    exit(-1);
  if (!txt_wlist.loadFromFile("../Textures/waitinglist_bg.png"))
    exit(-1);
  if (!txt_radis.loadFromFile("../Textures/radis.png"))
    exit(-1);

  spr_grid.setTexture(txt_grid);
  spr_grid.setPosition(50,125);
  
  spr_wlist.setTexture(txt_wlist);
  spr_wlist.setPosition(450,200);

  spr_radis.setTexture(txt_radis);
  spr_radis.setPosition(700,525);

  randomPosText.setFont(font);
  randomPosText.setString("Generate random position");
  randomPosText.setCharacterSize(20);
  randomPosText.setColor(Gray);
  randomPosText.setPosition(50,500);


  wlistText.setFont(font);
  wlistText.setString("");
  wlistText.setCharacterSize(20);
  wlistText.setColor(Black);
  wlistText.setPosition(460,220);


  _client.setJRandFlotte();
  
  while (_window.isOpen())
    {
      sf::Event event;
      while (_window.pollEvent(event))
	{
	  if (event.type == sf::Event::Closed)
	    _window.close();
	  if (event.type == sf::Event::MouseButtonPressed)
	    {
	      if (event.mouseButton.button == sf::Mouse::Left)
		{
		  // Gestion du double click souris
		  if ( clock.getElapsedTime() <= dCLickTime )
		    {
		      if ( spr_grid.getGlobalBounds().contains(_window.mapPixelToCoords(sf::Mouse::getPosition(_window))) )
			{
			  int xPosInGrid = (sf::Mouse::getPosition(_window).x - 50)/CELL_SIZE;
			  int yPosInGrid = (sf::Mouse::getPosition(_window).y - 125)/CELL_SIZE;
			  if ( _client.getJoueur().getFlotte().foundInFlotte(Position{xPosInGrid,yPosInGrid}) )
			    {
			      // Search the boat's number at (x,y)
			      int boatNum = _client.getJoueur().getFlotte().searchBoatAt(Position{xPosInGrid,yPosInGrid});
			      _client.turnJBoat(boatNum);
			    }		   
			}
		    }
		  else
		    {
		      clock.restart();

		      if ( spr_grid.getGlobalBounds().contains(_window.mapPixelToCoords(sf::Mouse::getPosition(_window))) )
			{
			  int xPosInGrid = (sf::Mouse::getPosition(_window).x - 50)/CELL_SIZE;
			  int yPosInGrid = (sf::Mouse::getPosition(_window).y - 125)/CELL_SIZE;
   
			  if ( _client.getJoueur().getFlotte().foundInFlotte(Position{xPosInGrid,yPosInGrid}) )
			    {
			      boatNumber = _client.getJoueur().getFlotte().searchBoatAt(Position{xPosInGrid,yPosInGrid});
			      
			      }	   
			}
		      if ( spr_radis.getGlobalBounds().contains(_window.mapPixelToCoords(sf::Mouse::getPosition(_window))) )
			{ 
			  std::ostringstream uneflotte;
			  uneflotte << _client.getJoueur().getFlotte();
			  if (_client.send(SEND_FLOTTE, uneflotte.str())
			      == sf::Socket::Done ) {
			    runBoards();}
			}
		      
		      if ( randomPosText.getGlobalBounds().contains(_window.mapPixelToCoords(sf::Mouse::getPosition(_window))) )
			{
			  _client.setJRandFlotte();
			}
		    }
		}
	    }
	  // Utilisation du numero de bateau ici
	  if ( event.type == sf::Event::MouseButtonReleased )
	    {
	      if ( boatNumber != -1 )
		{
		  int xPosReleased = (sf::Mouse::getPosition(_window).x - 50)/CELL_SIZE;
		  int yPosReleased = (sf::Mouse::getPosition(_window).y - 125)/CELL_SIZE;
		  // Moove boat at xPosReleased,yPosReleased if valid
		  _client.mooveJBoat(boatNumber,Position{xPosReleased,yPosReleased}); 
		}
	    }
	  if ( randomPosText.getGlobalBounds().contains(_window.mapPixelToCoords(sf::Mouse::getPosition(_window))) )
	    randomPosText.setColor(RedWine);
	  if ( ! randomPosText.getGlobalBounds().contains(_window.mapPixelToCoords(sf::Mouse::getPosition(_window))) )
	    randomPosText.setColor(Gray);
	  if ( spr_radis.getGlobalBounds().contains(_window.mapPixelToCoords(sf::Mouse::getPosition(_window))) )
	    spr_radis.setColor(DarkGray);
	  if ( !spr_radis.getGlobalBounds().contains(_window.mapPixelToCoords(sf::Mouse::getPosition(_window))) )
	    spr_radis.setColor(White);
	}
      if (_client.receive(msg) == sf::Socket::Done){
        wlistText.setString(_client._listeJoueurs);    
      }
      
      if( _client.getCloseRunWait()) {
	   runError();
	  _client.setCloseRunWait(false);
	  _window.close();
	}

      if (_client.getShutDown() ){
	_client._messageServeur = "le serveur s'arrette !";
        _window.close();
      }
      _window.clear(White);
      _window.draw(_sprBG);
      _window.draw(spr_radis);
      _window.draw(spr_wlist);
      _window.draw(wlistText);
      _window.draw(spr_grid);
      _window.draw(randomPosText);
      drawSpritesGrid(spr_grid.getPosition().x,spr_grid.getPosition().y);
      _window.display();
    }
  
}