Beispiel #1
0
StatusCode RecTrackAlg::execute() {

  // get hits from event store
  const fcc::PositionedTrackHitCollection* hits = m_positionedTrackHits.get();
  debug() << "Reconstructing Track Hit collection of size: " << hits->size() << " ..." << endmsg;
  // delegate track seeding to tool
  auto seedmap = m_trackSeedingTool->findSeeds(hits);
  // delegate track fitting to tool
  auto tracksAndTrackstates = m_trackFittingTool->fitTracks(hits, seedmap);

  // output found tracks to edm
  auto m_recParticleColl = m_recParticles.createAndPut();
  for (auto track: (*tracksAndTrackstates.first)) {
    auto p = TrackState2Particle(track);
    auto pEdm = m_recParticleColl->create();
    //pEdm = TrackState2Particle(track);
    pEdm.bits(p.bits());
    pEdm.charge(p.charge());
    pEdm.p4(p.p4());
  }
  m_tracks.put(tracksAndTrackstates.first);
  m_trackStates.put(tracksAndTrackstates.second);

  return StatusCode::SUCCESS;
}
Beispiel #2
0
/*******************

Verander de status van de lader. Deze functie moet gebruikt worden aangezien bepaalde combinaties van relaystanden niet goed zijn voor de batterij
mogelijke status:   USE
					CHARGING
					DISCHARGING

*******************/
int setState(enum status new_state){
    if (new_state == status) return 1;
    // Huidige status bepaalt overgangsmethode
    switch (status) {
        case CHARGING:
            // Stel stroom in op 0A
            setCurrent(0);
            if (new_state == DISCHARGING) {
                // Ontkoppel de lader
                turnOff();
                // Schakel naar ontladen
                discharge();
                // Koppel lader
                turnOn();
                // Stel stroom in op gewenste waarde
                // TODO: gewenste stroom instellen
            }else if (new_state == USE){
                // Veilig ontkoppelen na opladen
                // Schakel naar ontladen
                discharge();
                // Ontkoppel de lader
                turnOff();
            }
            break;
        case DISCHARGING:
            // Stel stroom in op 0A
            setCurrent(0);
            // Ontkoppel de lader
            turnOff();
            if (new_state == CHARGING){
                // Schakel naar opladen
                charge();
                // Koppel de lader
                turnOn();
            }
            break;
        case USE:
            if (new_state == DISCHARGING) {
                // Schakel naar ontladen
                discharge();
                //instellen van de stroom
				setCurrentCharger(0);
				// Koppel de lader
                turnOn();
                // Stel stroom in
                // TODO: gewenste stroom instellen
            }else if (new_state == CHARGING){
                // Schakel naar opladen
                charge();
                // Koppel de lader
                turnOn();
                // Stel stroom in
                // TODO: gewenste stroom instellen
            }
            break;
        default:
            break;
    }
    return 0;
}
int main()
{

    printf("press a to send hydro\npress b to send solar\npress up to send flag\n\n");

    while(!a_button() && !b_button() && !up_button());
    if(a_button())
    {
        while(a_button());
        init_captain_planet_with_our_powers_combined();
        kill_process(TIMER_WATCHDOG_ID);
        printf("result of charge: %d\n",charge(HYDRO));
    }
    else if(b_button())
    {
        while(b_button());
        init_captain_planet_with_our_powers_combined();
        kill_process(TIMER_WATCHDOG_ID);
        printf("result of charge: %d\n",charge(SOLAR));
    }
    else if(up_button())
    {
        while(up_button());
        init_captain_planet_with_our_powers_combined();
        kill_process(TIMER_WATCHDOG_ID);
        printf("result of charge: %d\n",charge(FLAG));
    }

    kill_process(TIMER_PROCESS_ID);
    serializer_disconnect();
}
Beispiel #4
0
 void GibbsExcessVPSSTP::getElectrochemPotentials(doublereal* mu) const {
   getChemPotentials(mu);
   double ve = Faraday * electricPotential();
   for (int k = 0; k < m_kk; k++) {
     mu[k] += ve*charge(k);
   }
 }
Beispiel #5
0
/*******************

initialiseren van de constanten uit lader.h

*******************/
void init(){
	gpio_map();
	printf("We zijn in de lader.c\n");
	gpio_output(DISCHARGE_BANK, DISCHARGE_PIN);
	printf("lader1\n");
	gpio_output(ON_OFF_BANK, ON_OFF_PIN);
	printf("lader2\n");
	turnOff();
	printf("lader3\n");
	charge();
	printf("lader4\n");
		currentCharger=0; //uitgedrukt in mA
		printf("lader5\n");
//On: 1, off: 0
	on=0;
//Charging: 1, discharging: 0
	charging=1;

// Variabelen voor State of Charge
	integratedCurrent=0; // Accumulatie van vorige stromen
	printf("lader6\n");
	timeOfMeasurement=0;

//Lipo: 0, NiMH: 1
	batterij_type = LiPo;

// Toestanden voor relay-standen
	status = USE;
	printf("lader7\n");
}
Beispiel #6
0
void Geometry::computeGasteigerCharges()
{
// This is returning zero charges for some reason
return;
    qDebug() << "Geometry::computeGasteigerCharges() not working correctly";
    OpenBabel::OBAtom* obAtom(0);
    OpenBabel::OBMol obMol;

    obMol.BeginModify();
    obMol.UnsetPartialChargesPerceived();
    for (int i = 0; i < m_atoms.size(); ++i) {
        obAtom = obMol.NewAtom();
        obAtom->SetAtomicNum(m_atoms[i]->atomicNumber());
        obAtom->SetVector(m_coordinates[i].x, m_coordinates[i].y, m_coordinates[i].z);
    }
    obMol.SetTotalCharge(m_charge);
    obMol.SetTotalSpinMultiplicity(m_multiplicity);
    obMol.EndModify();
    
    OpenBabel::OBMolAtomIter iter(&obMol);
    for (int i = 0; i < m_atoms.size(); ++i, ++iter) {
        int index(iter->GetIdx());
        qDebug() << "Setting Gasteiger Charge for" << index << "to" << iter->GetPartialCharge();
        GasteigerCharge& charge(m_atoms[i]->getProperty<GasteigerCharge>());
        charge.setValue(iter->GetPartialCharge());
    }
}
void *control(int *unused)
{
    while(1)
    {
        if(mission>6)
        {
            printf("invalid value in mission: %d\n",mission);
        }
        else
        {
            switch(mission)
            {
            case FRONT:
                drive_random();
                break;
            case CHARGE:
                charge();
                break;
            case IDLE:
                create_stop();
                break;
            default:
                track(mission);
            }
        }
        create_charge=create_get_charge();
    }
}
 void PseudoBinaryVPSSTP::getElectrochemPotentials(doublereal* mu) const {
   getChemPotentials(mu);
   double ve = Faraday * electricPotential();
   for (size_t k = 0; k < m_kk; k++) {
     mu[k] += ve*charge(k);
   }
 }
void ThermoPhase::getElectrochemPotentials(doublereal* mu) const
{
    getChemPotentials(mu);
    double ve = Faraday * electricPotential();
    for (size_t k = 0; k < m_kk; k++) {
        mu[k] += ve*charge(k);
    }
}
Beispiel #10
0
int init(){
	gpio_map();
	gpio_output(DISCHARGE_BANK, DISCHARGE_PIN);
	gpio_output(ON_OFF_BANK, ON_OFF_PIN);
	turnOff();
	charge();
	return 0;
}
Beispiel #11
0
disposition consumer::disposition() const
{
    disposition d = ok;
    if (m_logic && m_entry)
        d =  m_logic->charge(*m_entry, charge(0));

    return d;
}
Beispiel #12
0
doublereal Phase::chargeDensity() const
{
    doublereal cdens = 0.0;
    for (size_t k = 0; k < m_kk; k++) {
        cdens += charge(k)*moleFraction(k);
    }
    return cdens * Faraday;
}
Beispiel #13
0
int
main(int argc, char **argv)
{
	char	fbuf[PATH_MAX+1], *fb;
	FILE	*pwf;
	int	c;
	struct passwd	*pw;
	struct disk	*entry;

	while ((c = getopt(argc, argv, "p:u:")) != EOF) {
		switch (c) {
		case 'u':
			if ((nchrg = fopen(optarg, "w")) == NULL)
				openerr(optarg);
			(void) chmod(optarg, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
			break;
		case 'p':
			pfile = optarg;
			break;
		default:
			exit(1);
		}
	}

	if (pfile) {
		if ((pwf = fopen(pfile, "r")) == NULL) {
			openerr(pfile);
		}
		/* fill usglist with the user's in the passwd file */
		while ((pw = fgetpwent(pwf)) != NULL) {
			if ((entry = hash_find(pw->pw_uid)) == NULL)
				entry = hash_insert(pw->pw_uid);
			validate_entry(entry, pw);
		}
		(void) fclose(pwf);
	}

	/* charge the files listed in names to users listed in the usglist */
	while (fgets(fbuf, sizeof (fbuf), stdin) != NULL) {
		if ((fb = strchr(fbuf, '\n')) != NULL) {
			/*
			 * replace the newline char at the end of the
			 * filename with a null character
			 */
			*fb = '\0';
		}
		charge(fbuf);
	}

	output();

	if (nchrg)
		(void) fclose(nchrg);
#ifdef DEBUG
	pdisk();
#endif
	return (0);
}
Beispiel #14
0
void singleSpectra( int c, int p, int cl, int ch, string en ) {


	vector<double> vals = readSpectra( c, p, cl, ch, en );
	vector<double> errors = readSpectraE1( c, p, cl, ch, en );

	TH1D * h = makeHisto( plcName( p ) + "_" + charge(c) + "_" + ts(cl) + "_" + ts(ch), vals, errors );

}
Beispiel #15
0
 doublereal Phase::chargeDensity() const {
   int k;
   int nsp = nSpecies();
   doublereal cdens = 0.0;
   for (k = 0; k < nsp; k++) 
     cdens += charge(k)*State::moleFraction(k);
   cdens *= Faraday;
   return cdens;
 }
Beispiel #16
0
doublereal Phase::chargeDensity() const
{
    size_t kk = nSpecies();
    doublereal cdens = 0.0;
    for (size_t k = 0; k < kk; k++) {
        cdens += charge(k)*moleFraction(k);
    }
    cdens *= Faraday;
    return cdens;
}
Beispiel #17
0
void Target::update (float rotateSpeed, Vec3f cursor, Vec3f screenCol){
    
    // fade in
    if (newT && fade >= 0){
        targetMaterial.setSpecular( ColorA (.9, .9, .9, .6-fade) );
        targetMaterial.setDiffuse( ColorA (.9, .9, .9, .6-fade));
        targetMaterial.setAmbient(ColorA (.3, .3, .3f, .05f-(fade/12))) ;
        targetMaterial.setShininess( 600.0f );
        tempTarget.setMaterial( targetMaterial );
        fade -= .01;
        if (fade <= 0)
            newT = false;
    }
    
    // light up inner cirle
    if (!boxed && cursor.z < location.z && cursor.y < location.y+50 && cursor.y > location.y-50
        && cursor.x < location.x+50 && cursor.x > location.x-50 &&!newT){
         soundPlaying = true;
        
        charge(screenCol);
        fade -= .005;  
            
        if (fade <= 0){
            boxed = true;
            newBox = true;
        }
    }
    // reset fade
    else if (!newT){
        fade = .6;
        soundPlaying = false;
    }
    
    //stop drawing inner circle
    if (boxed && newBox){
        tempTarget = cinder::gl::DisplayList (GL_COMPILE);
        tempTarget.newList();
        gl::drawStrokedCircle(Vec2f(0,0), 100);
        gl::drawStrokedCircle(Vec2f(0,0), 97);
        gl::drawStrokedCircle(Vec2f(0,0), 94);
        gl::drawStrokedCircle(Vec2f(0,0), 91);
        gl::drawStrokedCircle(Vec2f(0,0), 88);
        gl::drawStrokedCircle(Vec2f(0,0), 85);
        gl::drawStrokedCircle(Vec2f(0,0), 82);
        tempTarget.endList();
        tempTarget.setMaterial( targetMaterial );
        newBox = false;
    }   
    
    if (boxed)
    tempTarget.getModelMatrix().rotate( rotator, rotateSpeed );    

    tempTarget.draw();
}
Beispiel #18
0
InputParameters
validParams<EFieldAdvection>()
{
  InputParameters params = validParams<Kernel>();
  params.addCoupledVar("efield", {1, 1, 1}, "The electric field responsible for charge advection");
  MooseEnum charge("positive negative", "positive");
  params.addParam<MooseEnum>(
      "charge", charge, "Whether our primary variable is positive or negatively charged.");
  params.addParam<Real>("mobility", 1., "The mobility of the charge");
  return params;
}
Beispiel #19
0
void LEDSensor::measure() {
  if (mStartTime == -1 || isTimedOut()) {
    charge();
    delay(1); // charge it up
    discharge();

    mStartTime = millis();
  } else if (isDischarged()) {
    mTimeDelta = millis() - mStartTime;
    mStartTime = -1;
  }
}
Beispiel #20
0
void kruskal(AdjMatrix *G,top_group *topgroup,set *S){
    
    int i,j,k;
    int  flag;
    for(i = 1;i <= G->arcnum;i++){
        flag = charge(topgroup,S,i);
        if(flag == 1){
            printf("%d %d\n",topgroup->topgroup[i].vex1,topgroup->topgroup[i].vex2);
        }

    }

}
Beispiel #21
0
    char *allocate(size_type size)
    {
        boost::lock_guard<mutex_type> l(mtx_);
        check_invariants_locked();

        if(!data_) charge();

        iterator result = 0;

        HPX_ASSERT(size <= chunk_size_);

        typedef free_list_type::iterator free_iterator;
        free_iterator it = free_list_.lower_bound(size);
        if(it != free_list_.end())
        {
            result = it->second;
            HPX_ASSERT(it->first >= size);
            if(it->first == size)
            {
                free_list_.erase(it);
                check_invariants_locked(result, size);
                return result;
            }
            size_type new_size = it->first - size;
            iterator new_free_block = it->second + size;
            free_list_.erase(it);
            if(new_free_block + new_size == current_)
            {
                current_ = new_free_block;
                allocated_ -= new_size;
            }
            else
            {
                free_list_.insert(std::make_pair(new_size, new_free_block));
            }
            check_invariants_locked(result, size);
            return result;
        }

        if(size + allocated_ <= chunk_size_)
        {
            result = current_;
            current_ += size;
            allocated_ += size;
            check_invariants_locked(result, size);
            return result;
        }
        check_invariants_locked(0, size);
        return 0;
    }
Beispiel #22
0
List Factory::convert(Data::PointChargeList& pointCharges)
{
   Charges* charges(new Charges());
   unsigned nCharges(pointCharges.size());
   
   for (unsigned i = 0; i < nCharges; ++i) {
       double q(pointCharges[i]->value());
       qglviewer::Vec position(pointCharges[i]->position());
       Charge* charge(new Charge(q,position));
       charges->appendLayer(charge);
   }

   List list;
   list.append(charges);
   return list;
}
Beispiel #23
0
/* effectue un tour */
static void tour(void) {
  int i, j;
  kase *k = NULL;

  /* on remet a 0 les flags "fait" */
  for (i=0; i<20; i++) {
    for (j=0; j<20; j++) {
      kor(i,j)->fait = 0;
    }
  }

  /* on traite maintenant chaque case */
  for (i=0; i<20; i++) {
    for (j=0; j<20; j++) {
      k = kor(i,j);

      /* on diminue la pheromone de sucre */
      if (k->ph_sucre >= 5) {
	k->ph_sucre -= 5;
      } else if (k->ph_sucre) {
	k->ph_sucre = 0;
      }

      /* on ne fait rien si la case est deja traitee */
      if (kor(i,j)->fait) {
	continue;
      }

      /* on essaye chaque regle de 1 a 6
       * (priorite la + haute a la + faible)
       */
      if (!charge(i,j)) {
	if (!depose(i,j)) {
	  if (!achemine(i,j)) {
	    if (!remonte(i,j)) {
	      if (!retourve(i,j)) {
		deplace(i,j);
	      }
	    }
	  }
	}
      }

      /* fin de traitement de cette case */
    }
  }
}
Beispiel #24
0
bool HelloWorld::onTouchBegan(Touch *touch, Event *unused_event) {
	if (isGameover) {
		resetGameover();
		return true;
	}
	else if (isPlayerDie) {
		return true;
	}
	else if (isTitle) {    //타이틀이 보이면 클릭 못하게 막음
		setTitle();            //타이틀 출력상태에서 터치하면 게임시작됨
		return true;
	}
	Vec2 location = touch->getLocation();
	charge(location);

	return true;
}
Beispiel #25
0
void rcp( string en, int c, int p, string cpf = "/Users/danielbrandenburg/bnl/local/work/rcpMaker/products/presentation/11GeV/data.root" ){


	TCanvas * cc = new TCanvas( "c1", "c2", 250, 250 );

	gStyle->SetOptStat( 0 );
	
	vector<double> c6 = readSpectra( c, p, 0, 1, en );
	vector<double> c6e = readSpectraE1( c, p, 0, 1, en );

	TH1D * hc6 = makeHisto( "cen6", c6, c6e );

	vector<double> c0 = readSpectra( c, p, 8, 8, en );
	vector<double> c0e = readSpectraE1( c, p, 8, 8, en );
	TH1D * hc0 = makeHisto( "cen0", c0, c0e );

	hc0->Scale( 19.0 );
	hc6->Scale( 784.0 );

	hc0->Divide( hc6 );

	hc0->SetTitle( (plcName( p ) + " : " + hCharge( c )).c_str()  );
	hc0->GetYaxis()->SetRangeUser( 0.1, 5 );
	hc0->GetXaxis()->SetRangeUser( 0.0, 4 );
	hc0->SetMarkerStyle( 20 );
	hc0->SetMarkerColor( kBlue );
	hc0->Draw();
	gPad->SetLogy(1);	

	string name = "rcp_" + plcName( p ) + "_" + charge( c ) + "_0_Over_6";
	TFile * f = new TFile( cpf.c_str(), "READ" );

	TH1D * crcp = (TH1D*)f->Get( ("rcp/"+name).c_str() );
	crcp->SetMarkerStyle( 22 );
	crcp->SetMarkerColor( kRed );
	crcp->Scale( 1.08 );
	crcp->Draw( "same" );

	cc->SetGrid(1, 1);

	cc->Print( (name + ".pdf").c_str());



}
void chargedist(double xyzr[MAXATOMS][XYZRWIDTH],
double* chratm, Mat<>& charget, Mat<>& corlocqt, Mat<size_t>& loc_qt, size_t iatm){
	double x_q = xyzr[iatm-1][0];
	double y_q = xyzr[iatm-1][1];
	double z_q = xyzr[iatm-1][2];
	double q_q = chratm[iatm-1];

	size_t i_q = inverx(x_q);
	int j_q = invery(y_q);
	int k_q = inverz(z_q);


	Mat<size_t> loc_q(8,3);
	Mat<> corlocq(8,3);
	for (size_t i = 0; i <= 1; ++i) {
		for (size_t j = 0; j <= 1; ++j) {
			for (size_t k = 0; k <= 1; ++k) {
				size_t ind = 4*k + 2*j + i + 1;

				size_t ind_i = i_q + i;
				size_t ind_j = j_q + j;
				size_t ind_k = k_q + k;

				corlocq(ind,1) = xvalue(ind_i);
				corlocq(ind,2) = yvalue(ind_j);
				corlocq(ind,3) = zvalue(ind_k);

				loc_q(ind,1) = ind_i;
				loc_q(ind,2) = ind_j;
				loc_q(ind,3) = ind_k;
			}
		}
	}

	double x = xvalue(i_q);
	double y = yvalue(j_q);
	double z = zvalue(k_q);

	double xd1 = x_q - x;
	double yd1 = y_q - y;
	double zd1 = z_q - z;

	std::valarray<double> charge(0.0, 8);
	if (xd1 != 0 && yd1 != 0 && zd1 != 0) {
		for (int i = 0; i <= 1; ++i) {
			for (int j = 0; j <= 1; ++j) {
				for (int k = 0; k <= 1; ++k) {
					int ind = 4*k + 2*j + i;

					double xd = i*comdata.deltax - xd1;
					double yd = j*comdata.deltay - yd1;
					double zd = k*comdata.deltaz - zd1;

					charge[ind] = 1.0/fabs(xd*yd*zd);
				}
			}
		}
	} else if ((xd1 != 0 && yd1 != 0) || (xd1 != 0 && zd1 != 0) ||
					(yd1 != 0 && zd1 != 0)) {
		if (xd1 == 0) {
			for (int j = 0; j <= 1; ++j) {
				for (int k = 0; k <= 1; ++k) {
					double yd = j*comdata.deltay - yd1;
					double zd = k*comdata.deltaz - zd1;
					charge[4*j + 2*k] = 1.0/fabs(yd*zd);
				}
			}
		} else if (yd1 == 0) {
			for (int i = 0; i <= 1; ++i) {
				for (int k = 0; k <= 1; ++k) {
					double xd = i*comdata.deltax - xd1;
					double zd = k*comdata.deltaz - zd1;
					charge[i + 4*k] = 1.0/fabs(xd*zd);
				}
			}
		} else if (zd1 == 0) {
			for (int i = 0; i <= 1; ++i){
				for (int j = 0; j <= 1; ++j){
					double xd = i*comdata.deltax - xd1;
					double yd = j*comdata.deltay - yd1;
					charge[i + 2*j] = 1.0/fabs(xd*yd);
				}
			}
		}
	} else if (xd1 != 0 || yd1 != 0 || zd1 != 0 ) {
		if (xd1 != 0) {
			charge[0] = 1.0/xd1;
			charge[1] = 1.0/(comdata.deltax-xd1);
		} else if (yd1 != 0) {
			charge[0] = 1.0/yd1;
			charge[2] = 1.0/(comdata.deltay-yd1);
		} else if (zd1 != 0) {
			charge[0] = 1.0/zd1;
			charge[4] = 1.0/(comdata.deltaz-zd1);
		}
	} else {
		charge[0] = 1.0;
	}

	charge=q_q*charge/charge.sum();

	for (size_t j = 1; j <= charget.ny(); ++j) {
		charget(iatm,j) = charge[j-1];
		for (size_t k = 1; k <= corlocqt.nz(); ++k) {
			corlocqt(iatm,j,k) = corlocq(j,k);
			loc_qt(iatm,j,k) = loc_q(j,k);

		}
	}
}
void RedlichKisterVPSSTP::readXMLBinarySpecies(XML_Node& xmLBinarySpecies)
{
    std::string xname = xmLBinarySpecies.name();
    if (xname != "binaryNeutralSpeciesParameters") {
        throw CanteraError("RedlichKisterVPSSTP::readXMLBinarySpecies",
                           "Incorrect name for processing this routine: " + xname);
    }
    size_t Npoly = 0;
    vector_fp hParams, sParams;
    std::string iName = xmLBinarySpecies.attrib("speciesA");
    if (iName == "") {
        throw CanteraError("RedlichKisterVPSSTP::readXMLBinarySpecies", "no speciesA attrib");
    }
    std::string jName = xmLBinarySpecies.attrib("speciesB");
    if (jName == "") {
        throw CanteraError("RedlichKisterVPSSTP::readXMLBinarySpecies", "no speciesB attrib");
    }
    /*
     * Find the index of the species in the current phase. It's not
     * an error to not find the species. This means that the interaction doesn't occur for the current
     * implementation of the phase.
     */
    size_t iSpecies = speciesIndex(iName);
    if (iSpecies == npos) {
        return;
    }
    string ispName = speciesName(iSpecies);
    if (charge(iSpecies) != 0) {
        throw CanteraError("RedlichKisterVPSSTP::readXMLBinarySpecies", "speciesA charge problem");
    }
    size_t jSpecies = speciesIndex(jName);
    if (jSpecies == npos) {
        return;
    }
    std::string jspName = speciesName(jSpecies);
    if (charge(jSpecies) != 0) {
        throw CanteraError("RedlichKisterVPSSTP::readXMLBinarySpecies", "speciesB charge problem");
    }
    /*
     *  Ok we have found a valid interaction
     */
    numBinaryInteractions_++;
    size_t iSpot = numBinaryInteractions_ - 1;
    m_pSpecies_A_ij.resize(numBinaryInteractions_);
    m_pSpecies_B_ij.resize(numBinaryInteractions_);
    m_pSpecies_A_ij[iSpot] = iSpecies;
    m_pSpecies_B_ij[iSpot] = jSpecies;

    for (size_t iChild = 0; iChild < xmLBinarySpecies.nChildren(); iChild++) {
        XML_Node& xmlChild = xmLBinarySpecies.child(iChild);
        string nodeName = lowercase(xmlChild.name());
        /*
         * Process the binary species interaction child elements
         */
        if (nodeName == "excessenthalpy") {
            /*
             * Get the string containing all of the values
             */
            getFloatArray(xmlChild, hParams, true, "toSI", "excessEnthalpy");
            Npoly = std::max(hParams.size(), Npoly);
        }

        if (nodeName == "excessentropy") {
            /*
             * Get the string containing all of the values
             */
            getFloatArray(xmlChild, sParams, true, "toSI", "excessEntropy");
            Npoly = std::max(sParams.size(), Npoly);
        }
    }
    hParams.resize(Npoly, 0.0);
    sParams.resize(Npoly, 0.0);
    m_HE_m_ij.push_back(hParams);
    m_SE_m_ij.push_back(sParams);
    m_N_ij.push_back(Npoly);
    resizeNumInteractions(numBinaryInteractions_);
}
Beispiel #28
0
static void status()
{
	int ret;
	uint8_t tx[2];
	uint8_t rx[2];

	tx[0] = 0x04;
	tx[1] = 0x05;

	struct spi_ioc_transfer tr = {
		.tx_buf = (unsigned long)tx,
		.rx_buf = (unsigned long)rx,
		.len = ARRAY_SIZE(tx),
		.delay_usecs = delay,
		.speed_hz = speed,
		.bits_per_word = bits,
	};

	ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
	if (ret < 1)
		pabort("can't send spi message");

	printf("Charging   = %x\n", (rx[1] >> 2) & 1);
	printf("Power Fail = %x\n", (rx[1] >> 3) & 1);
	printf("DCDIV      = %x\n", (rx[1] >> 4) & 1);
	printf("Low Power  = %x\n", (rx[1] >> 5) & 1);
	printf("Fault      = %x\n", (rx[1] >> 6) & 1);


}

static void charge(int battery)
{
	int ret;

	uint8_t tx[1];
	uint8_t rx[1];

	tx[0] = battery | CHARGE_CMD;

	struct spi_ioc_transfer tr = {
		.tx_buf = (unsigned long)tx,
		.rx_buf = (unsigned long)rx,
		.len = ARRAY_SIZE(tx),
		.delay_usecs = delay,
		.speed_hz = speed,
		.bits_per_word = bits,
	};

	ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
	if (ret < 1)
		pabort("can't send spi message");

}

static void voltage_dac(double voltage)
{
	int ret;
	int vdac;
	int i;

	uint8_t tx[2];
	uint8_t rx[2];

	tx[0] = 0x01;
	tx[1] = 0x08;


	vdac = (int) floor(((voltage-.8)/32.752) * 2047);

	for(i=0;i<10;i++)
	{
		if(i<7)
			tx[0] |= (vdac & (1 << i)) ? (1 << (7-i)) : 0;
		else
			tx[1] |= (vdac & (1 << i)) ? (1 << (14-i)) : 0;
	}

	struct spi_ioc_transfer tr = {
		.tx_buf = (unsigned long)tx,
		.rx_buf = (unsigned long)rx,
		.len = ARRAY_SIZE(tx),
		.delay_usecs = delay,
		.speed_hz = speed,
		.bits_per_word = bits,
	};

	ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
	if (ret < 1)
		pabort("can't send spi message");

	do
	{
		tx[0] = 0x01;
		struct spi_ioc_transfer tr = {
			.tx_buf = (unsigned long)tx,
			.rx_buf = (unsigned long)rx,
			.len = 1,
			.delay_usecs = delay,
			.speed_hz = speed,
			.bits_per_word = bits,
		};

		ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
		if (ret < 1)
			pabort("can't send spi message");
	} while(rx[0]==0xFF);

}

static void current_dac(double current, int low_current)
{
	int ret;
	int cdac;
	int i;

	uint8_t tx[2];
	uint8_t rx[2];

	tx[0] = 0x01;
	tx[1] = 0x00;

	cdac = (int) (((current)*1023*0.05)/0.1023);

	for(i=0;i<10;i++)
	{
		if(i<7)
			tx[0] |= (cdac & (1 << i)) ? (1 << (7-i)) : 0;
		else
			tx[1] |= (cdac & (1 << i)) ? (1 << (14-i)) : 0;
	}

	tx[1] |= (low_current) ? 0x10 : 0x00;

	struct spi_ioc_transfer tr = {
		.tx_buf = (unsigned long)tx,
		.rx_buf = (unsigned long)rx,
		.len = ARRAY_SIZE(tx),
		.delay_usecs = delay,
		.speed_hz = speed,
		.bits_per_word = bits,
	};

	ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
	if (ret < 1)
		pabort("can't send spi message");

	do
	{
		tx[0] = 0x01;
		struct spi_ioc_transfer tr = {
			.tx_buf = (unsigned long)tx,
			.rx_buf = (unsigned long)rx,
			.len = 1,
			.delay_usecs = delay,
			.speed_hz = speed,
			.bits_per_word = bits,
		};

		ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
		if (ret < 1)
			pabort("can't send spi message");
	} while(rx[0]==0xFF);

}

void charge_timer(int i)
{
	if(battery_sel) charge(battery_sel);

	signal(SIGALRM, charge_timer);
}

void init_timer()
{
	tout_val.it_interval.tv_sec = 1; /* Next Value in seconds */
	tout_val.it_interval.tv_usec = 1; /* Next Value in microseconds */
	tout_val.it_value.tv_sec = 1; /* Current Value in seconds */
	tout_val.it_value.tv_usec = 1; /* Current Value in microseconds */
	setitimer(ITIMER_REAL, &tout_val, 0);
	signal(SIGALRM, charge_timer);
}

int main(int argc, char *argv[])
{
	int ret = 0;
	int done = 0;
	int low_current = 0;
	char key;
	double voltage, current;

	fd = open(device, O_RDWR);
	if (fd < 0)
		pabort("Cannot open device");

	ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
	if (ret == -1)
		pabort("Cannot set bits per word");

	ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
	if (ret == -1)
		pabort("Cannot set max speed hz");


	init_timer();

	printf("LTC1960 Battery Charger Demo\n\n");

	current = 2.0;
	voltage = 12.8;

	voltage_dac(voltage);
	current_dac(current, low_current);

	while(!done)
	{

		status();

		printf("\n");

		printf("Battery 1 is %s.\n", (battery_sel==CHARGE_BAT1) ? "charging" : "not charging");
	        printf("Battery 2 is %s.\n", (battery_sel==CHARGE_BAT2) ? "charging" : "not charging");
		printf("Current = %lfA\n",current);
		printf("Voltage = %lfV\n",voltage);
		printf("Low Current Mode %s.\n", (low_current) ? "ON" : "OFF");

		printf("\n");

		printf("1: Set battery voltage.\n");
		printf("2: Set battery current.\n");
		printf("3: Charge battery 1. \n");
		printf("4: Charge battery 2. \n");
		printf("5: Toggle Low Current Mode. \n");
		printf("6: Stop Charging. \n");
		printf("7: Print smart battery info.\n");
		printf("q: Quit Program\n");

		printf("\nInput: ");

		do
		{
			scanf("%c", &key);
		} while(key == '\n');

		printf("\n\n");
		switch(key)
		{
			case '1': printf("Voltage = ");
				  scanf("%lf", &voltage);
				  voltage_dac(voltage);
				  break;
			case '2': printf("Current = ");
				  scanf("%lf", &current);
				  current_dac(current, low_current);
				  break;
			case '3': battery_sel = CHARGE_BAT1;
				  charge(battery_sel);
				  break;
			case '4': battery_sel = CHARGE_BAT2;
				  charge(battery_sel);
				  break;
			case '5': low_current ^=1;
				  current_dac(current, low_current);
				  break;
			case '6': battery_sel = 0;
				  sleep(1);
				  break;
			case '7': system("cat /sys/class/power_supply/battery/uevent");
				  break;
			case 'q': done = 1;
				  break;
			default: continue;
		}
	}

	close(fd);

	return ret;
}
Beispiel #29
0
void CGarg::process()
{
	// did the garg get shot?
	if (mHealthPoints <= 0 && state != GARG_DYING )
	{
		// die, you stupid garg, die!
		state = GARG_DYING;
		dying = true;
		sprite = GARG_DYING_FRAME;
		yinertia = GARGDIE_START_INERTIA;
		playSound(SOUND_GARG_DIE);
	}

	// Check, if Garg is moving and collides and change directions whenever needed
	if(state != GARG_LOOK &&  state != GARG_CHARGE && state != GARG_DYING)
	{
		// Set the proper frame
		sprite = (movedir==LEFT) ? GARG_WALK_LEFT : GARG_WALK_RIGHT;
		sprite += walkframe;

		// collides? Change direction
		if( movedir==LEFT && blockedl )
			movedir = RIGHT;
		else if( movedir==RIGHT && blockedr )
			movedir = LEFT;

		// Compute the speed
		xinertia = (m_hardmode) ? GARG_WALK_SPEED_FAST : GARG_WALK_SPEED;

		// Set the correct speed according to direction
		if(movedir == LEFT)
			xinertia = -xinertia;
		dist_traveled++;
	}

	switch(state)
	{
	case GARG_DYING:
		if ( blockedd && yinertia >= 0 )
		{
			sprite = GARG_DEAD_FRAME;
			dead = true;
		}
		break;
	case GARG_LOOK:
		if (looktimes>GARG_NUM_LOOKS)
		{			
			if (!about_to_charge && rnd()%3==1)
			{
				// 25% prob, go the other way (but always charge towards player)				
				movedir = (movedir == LEFT) ? RIGHT : LEFT;
			}

			// however if we're blocked on one side we must go the other way
			if (blockedl)
				movedir = RIGHT;
			else if (blockedr)
				movedir = LEFT;

			timer = 0;
			walkframe = 0;
			dist_traveled = 0;
			if (about_to_charge)
			{
				state = GARG_CHARGE;
				about_to_charge = 0;
			}
			else state = GARG_MOVE;
		}

		// look animation
		if (!timer)
		{
			sprite = GARG_STAND + lookframe;
			looktimes++;

			if (++lookframe>3)
			{
				lookframe=0;
			}
			timer = GARG_LOOK_TIME;
		} else timer--;
		break;
	case GARG_MOVE:
	{
		// every now and then go back to look state
		if (dist_traveled > GARG_MINTRAVELDIST)
		{
			if (rnd()%GARG_LOOK_PROB==(GARG_LOOK_PROB/2))
			{
				looktimes = 0;
				timer = 0;
				state = GARG_LOOK;
				break;
			}
		}

		// walk animation
		if (timer > GARG_WALK_ANIM_TIME ||
				(timer > GARG_WALK_ANIM_TIME && m_hardmode))
		{
			walkframe ^= 1;
			timer = 0;
		} else timer++;
	}
	break;
	case GARG_JUMP:
		if( jumptime > 0 )
			jumptime--;
		else
			state = GARG_CHARGE;

		if( blockedd ) // There is floor
			state = GARG_CHARGE;

		charge();
		break;
	case GARG_CHARGE:
		charge();

		// if Garg is about to fall while charged make him jump
		if( !blockedd )
		{
			state = GARG_JUMP;
			yinertia = -(GARG_JUMP_SPEED);
			jumptime = GARG_JUMP_TIME;
		}

		break;
	default: break;
	}
}
Beispiel #30
0
/*
 * setMolalitiesByName()
 *
 *  This routine sets the molalities by name
 *  HKM -> Might need to be more complicated here, setting
 *         neutrals so that the existing mole fractions are
 *         preserved.
 */
void MolalityVPSSTP::setMolalitiesByName(compositionMap& mMap)
{
    size_t kk = nSpecies();
    doublereal x;
    /*
     * Get a vector of mole fractions
     */
    vector_fp mf(kk, 0.0);
    getMoleFractions(DATA_PTR(mf));
    double xmolS = mf[m_indexSolvent];
    double xmolSmin = std::max(xmolS, m_xmolSolventMIN);
    compositionMap::iterator p;
    for (size_t k = 0; k < kk; k++) {
        p = mMap.find(speciesName(k));
        if (p != mMap.end()) {
            x = mMap[speciesName(k)];
            if (x > 0.0) {
                mf[k] = x * m_Mnaught * xmolSmin;
            }
        }
    }
    /*
     * check charge neutrality
     */
    size_t largePos = npos;
    double cPos = 0.0;
    size_t largeNeg = npos;
    double cNeg = 0.0;
    double sum = 0.0;
    for (size_t k = 0; k < kk; k++) {
        double ch = charge(k);
        if (mf[k] > 0.0) {
            if (ch > 0.0) {
                if (ch * mf[k] > cPos) {
                    largePos = k;
                    cPos = ch * mf[k];
                }
            }
            if (ch < 0.0) {
                if (fabs(ch) * mf[k] > cNeg) {
                    largeNeg = k;
                    cNeg = fabs(ch) * mf[k];
                }
            }
        }
        sum += mf[k] * ch;
    }
    if (sum != 0.0) {
        if (sum > 0.0) {
            if (cPos > sum) {
                mf[largePos] -= sum / charge(largePos);
            } else {
                throw CanteraError("MolalityVPSSTP:setMolalitiesbyName",
                                   "unbalanced charges");
            }
        } else {
            if (cNeg > (-sum)) {
                mf[largeNeg] -= (-sum) / fabs(charge(largeNeg));
            } else {
                throw CanteraError("MolalityVPSSTP:setMolalitiesbyName",
                                   "unbalanced charges");
            }
        }

    }
    sum = 0.0;
    for (size_t k = 0; k < kk; k++) {
        sum += mf[k];
    }
    sum = 1.0/sum;
    for (size_t k = 0; k < kk; k++) {
        mf[k] *= sum;
    }
    setMoleFractions(DATA_PTR(mf));
    /*
     * After we formally set the mole fractions, we
     * calculate the molalities again and store it in
     * this object.
     */
    calcMolalities();
}