Пример #1
0
void arduinoThread::journeyOn(bool new_coffee){
    
    if (new_coffee) {
        start_transition = true;
        current = ofPoint(home_x, home_y);
        target = *points.begin();
        paths_i = points_i = 0;
        fireEngines();
    }
    else {
        planJourney();
        
        // starting a transition
        if (start_transition){
            start_transition = false;
            stopInk();
            fireEngines();
        }
        // starting a new poy, ink flows
        else if (start_path){
            start_path = false;
            startInk();
            fireEngines();
        }
        // drawing last segment in a polyline
        else if (end_path) {
            end_path = false;
            fireEngines();
        }
        // check to see if movements are long enough, if not add a point
        else {
            int sx = abs(getSteps(current.x, target.x, true));
            int sy = abs(getSteps(current.y, target.y, false));
            
            // we've hit the last point
            if (paths_i >= paths.size() && points_i >= points.size()) {
                fireEngines();
            }
            
            // if we're already above tolerance, fire
            if (sx > TOL && sy > TOL) {
                fireEngines();
            }
            // if one dimension gets too big, fire
            else if (sx > TOL*4 || sy > TOL*4) {
                fireEngines();
            }
            else {
                // if you didn't fire and return out then you're hitting planJourney() again
                point_count++;
                update();
            }
        }
    }
}
Пример #2
0
task main()
{
	initReadMode("auton.txt", 1024);

	int nSteps = getSteps();

	for(int i = 0; i < nSteps; i++)	{
		int* stps = getNextStep();
		for(int m = 0; m < 5; m++)	{
			nMotorEncoder[mtrs[m]] = 0;
			nMotorEncoderTarget[mtrs[m]] = stps[m];
			motor[mtrs[m]] = 80 * sgn(stps[m]);
		}

		for(int s = 0; s < 2; s++)	{
			servo[servos[s]] = stps[s+6];
		}

		motor[ScissorLeft] = 80 * sgn(stps[5]);
		while(nMotorRunState[ScissorRight] != IDLE)	{};
		motor[ScissorLeft] = 0;
	}

	moveArm();
}
Пример #3
0
int Player::getScore() {
    Global *g = Global::get();
    int computedScore = 0;
    for (Item &item : items) {
        computedScore += item.getValue();
    }
    return (computedScore * g->getDifficulty() + getSteps());
}
Пример #4
0
void arduinoThread::fireEngines(){
    int sdelta_x = 0;
    int sdelta_y = 0;
    int delay_x = DELAY_MIN;
    int delay_y = DELAY_MIN;
    
    // get steps
    int sx = abs(sdelta_x = getSteps(current.x, target.x, true));
    int sy = abs(sdelta_y = getSteps(current.y, target.y, false));
    
    // if nowhere to go, skip it
    if (sx == 0 && sy == 0) {
        return;
    }
    
    // get delays
    if (sy > sx && sx != 0) {
        delay_x = DELAY_MIN * sy / sx;
    } else if (sx > sy && sy != 0) {
        delay_y = DELAY_MIN * sx / sy;
    }
    
    // toggle direction pins and enable motors
    bool DIR = (sdelta_x > 0) ? ARD_LOW : ARD_HIGH;
    ard.sendDigital(X_DIR_PIN, DIR);
    DIR = (sdelta_y > 0) ? ARD_LOW : ARD_HIGH;
    ard.sendDigital(Y_DIR_PIN, DIR);
    
    // send variables to motors and start them
    x_steps = sx;
    x_inc = 0;
    x_delay = delay_x;
    y_steps = sy;
    y_inc = 0;
    y_delay = delay_y;

    // debugging
    hex = "\nsdelta_x:   " + ofToString(sdelta_x) + "\ndelay_x:    " + ofToString(delay_x);
    hwy = "\nsdelta_y:   " + ofToString(sdelta_y) + "\ndelay_y:    " + ofToString(delay_y)
        + "\npoint_count " + ofToString(point_count);

    // after the move, we are at the target, our new current position
    current = target;
    point_count = 1;
}
Пример #5
0
void Bomb::createFire() {
    
    Fire* obj = new Fire();
    
    obj->setStep(getSteps());
    obj->setPosition(this->_position.x, this->_position.z);
    obj->setDirection(Fire::None);
    obj->setParent(getParent());
    
    addObject(obj);
}
Пример #6
0
float MapgenCarpathian::terrainLevelAtPoint(s16 x, s16 z)
{
	float ground = NoisePerlin2D(&noise_base->np, x, z, seed);
	float height1 = NoisePerlin2D(&noise_height1->np, x, z, seed);
	float height2 = NoisePerlin2D(&noise_height2->np, x, z, seed);
	float height3 = NoisePerlin2D(&noise_height3->np, x, z, seed);
	float height4 = NoisePerlin2D(&noise_height4->np, x, z, seed);
	float hter = NoisePerlin2D(&noise_hills_terrain->np, x, z, seed);
	float rter = NoisePerlin2D(&noise_ridge_terrain->np, x, z, seed);
	float ster = NoisePerlin2D(&noise_step_terrain->np, x, z, seed);
	float n_hills = NoisePerlin2D(&noise_hills->np, x, z, seed);
	float n_ridge_mnt = NoisePerlin2D(&noise_ridge_mnt->np, x, z, seed);
	float n_step_mnt = NoisePerlin2D(&noise_step_mnt->np, x, z, seed);

	int height = -MAX_MAP_GENERATION_LIMIT;

	for (s16 y = 1; y <= 30; y++) {
		float mnt_var = NoisePerlin3D(&noise_mnt_var->np, x, y, z, seed);

		// Gradient & shallow seabed
		s32 grad = (y < water_level) ? grad_wl + (water_level - y) * 3 : 1 - y;

		// Hill/Mountain height (hilliness)
		float hill1 = getLerp(height1, height2, mnt_var);
		float hill2 = getLerp(height3, height4, mnt_var);
		float hill3 = getLerp(height3, height2, mnt_var);
		float hill4 = getLerp(height1, height4, mnt_var);
		float hilliness = std::fmax(std::fmin(hill1, hill2), std::fmin(hill3, hill4));

		// Rolling hills
		float hill_mnt = hilliness * pow(n_hills, 2.f);
		float hills = pow(hter, 3.f) * hill_mnt;

		// Ridged mountains
		float ridge_mnt = hilliness * (1.f - fabs(n_ridge_mnt));
		float ridged_mountains = pow(rter, 3.f) * ridge_mnt;

		// Step (terraced) mountains
		float step_mnt = hilliness * getSteps(n_step_mnt);
		float step_mountains = pow(ster, 3.f) * step_mnt;

		// Final terrain level
		float mountains = hills + ridged_mountains + step_mountains;
		float surface_level = ground + mountains + grad;

		if (y > surface_level && height < 0)
			height = y;
	}

	return height;
}
/**
 * @brief 导出Step数据到文件
 */
void clsDataExport::on_btnStepExport_clicked()
{
    QString strFileName = QFileDialog::getSaveFileName(this,tr("Svae rec file information to CSV file"),
                                                       tmpDataDir,
                                                       tr("CSV file(*.csv)"));
    if(strFileName.isEmpty())
        return;

    tmpDataDir = QFileInfo(strFileName).absoluteDir().canonicalPath();
    saveSettings();
    QStringList steps = getSteps();
    QStringList components;
    if(rbStepAll->isChecked())
        components = getComponents(All);

    if(rbStepPass->isChecked())
        components = getComponents(Pass);

    if(rbStepFail->isChecked())
        components = getComponents(Fail);

    QStringList items, titles;

    titles <<tr("Component No.")<<tr("Step") <<tr("P/F")<<tr("Test1")<<tr("T1 Result")<<tr("T1 P/F")
          <<tr("Test2")<<tr("T2 Result")<<tr("T2 P/F")<<tr("Date and Time");
    items <<"ComponentNo"<<"mStepNumber"<<"ResultStatus"<<"mTerm1"<<"mT1Result"<<"T1Status"
         <<"mTerm2"<<"mT2Result"<<"T2Status"<<"CompTimeStamp";

    if(1)
    {
        if(chkStepFrequency->isChecked())
        {
            titles << tr("Frequency");
            items <<"mFrequency";
        }

        if(chkStepSpeed->isChecked())
        {
            titles << tr("Speed");
            items <<"mStepSpeed";
        }

        if(chkStepDriverLevel->isChecked())
        {
            titles <<tr("Drive Level");
            items <<"mDriveType" <<"mACLevel";
        }


        if(chkStepRange->isChecked())
        {
            titles << tr("Range");
            items<<"mStepRange";
        }

        if(chkStepEqucct)
        {
            titles << tr("Equ-CCT");
            items <<"mStepCCT";
        }
    }

    QStringList titles2;

    for(int i=0; i< steps.length(); i++)
    {
        titles2 << titles;
    }
    writeHeader(strFileName,titles2);

    //int:Step index, QList<QString>:一个Step的所有元件内容
    QMap <int, QList<QStringList> > res; //定义存储空间

    //进度显示
    QProgressDialog progress(tr("Generating data record.."), tr("Abort"), 0,
                             steps.length(), this);
    progress.setWindowTitle(this->windowTitle());
    progress.setWindowModality(Qt::WindowModal);
    progress.setWindowFlags(progress.windowFlags()&~Qt::WindowContextHelpButtonHint &~Qt::WindowCloseButtonHint);
    progress.setCancelButton(0);
    progress.setValue(0);
    progress.show();


    for( int i =0; i< steps.length(); i++)
    {
        QString tmpStep = steps.at(i); //步骤数

        QMap<int, clsQueryDetailSheet *> pool;

        QStringListIterator it(components);

        int index=0;
        QStringList compNo;
        while(it.hasNext())
        {
            compNo.append(it.next());

            if(compNo.length() == 20000)
            {
                clsQueryDetailSheet * tmpQT = new clsQueryDetailSheet();
                tmpQT->setQueryItems(items,compNo,tmpStep);
                tmpQT->setIndex(index);
                pool.insert(index, tmpQT);

                compNo.clear();
                index++;
            }
        }

        if(!compNo.isEmpty())
        {
            clsQueryDetailSheet * tmpQT = new clsQueryDetailSheet();
            tmpQT->setQueryItems(items,compNo,tmpStep);
            tmpQT->setIndex(index);
            pool.insert(index, tmpQT);
        }

        for(int ii=0; ii< pool.count(); ii++)
            pool.value(ii)->run();

        while(1)
        {
            bool status=false;

            for(int ii =0; ii< pool.count(); ii++)
            {
                status = status || pool.value(ii)->isRunning();
            }

            if(! status)
                break;

            qApp->processEvents();

            clsUserFunction::sleepMs(10);
        }

        QList<QStringList> tmpRes;

        for(int ii=0; ii< pool.count(); ii++)
        {
            tmpRes += pool.value(ii)->getRes();
        }

        res.insert(i,tmpRes);
        progress.setValue(i+1);
    }

    progress.setValue(steps.length());
    progress.accept();

    QList <QStringList> wholeThings;
    for(int i=0; i< components.length(); i++)
    {
        QStringList tmpList;
        for(int j=0; j<steps.length(); j++)
        {
            tmpList << res.value(j).at(i);
        }

        wholeThings.append(tmpList);
    }
    writeContent(strFileName,wholeThings);
}
Пример #8
0
int MapgenCarpathian::generateTerrain()
{
	MapNode mn_air(CONTENT_AIR);
	MapNode mn_stone(c_stone);
	MapNode mn_water(c_water_source);

	s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT;
	u32 index2d = 0;
	u32 index3d = 0;

	// Calculate noise for terrain generation
	noise_base->perlinMap2D(node_min.X, node_min.Z);
	noise_height1->perlinMap2D(node_min.X, node_min.Z);
	noise_height2->perlinMap2D(node_min.X, node_min.Z);
	noise_height3->perlinMap2D(node_min.X, node_min.Z);
	noise_height4->perlinMap2D(node_min.X, node_min.Z);
	noise_hills_terrain->perlinMap2D(node_min.X, node_min.Z);
	noise_ridge_terrain->perlinMap2D(node_min.X, node_min.Z);
	noise_step_terrain->perlinMap2D(node_min.X, node_min.Z);
	noise_hills->perlinMap2D(node_min.X, node_min.Z);
	noise_ridge_mnt->perlinMap2D(node_min.X, node_min.Z);
	noise_step_mnt->perlinMap2D(node_min.X, node_min.Z);
	noise_mnt_var->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);

	//// Place nodes
	for (s16 z = node_min.Z; z <= node_max.Z; z++) {
		for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) {
			u32 vi = vm->m_area.index(node_min.X, y, z);
			for (s16 x = node_min.X; x <= node_max.X;
					x++, vi++, index2d++, index3d++) {
				if (vm->m_data[vi].getContent() != CONTENT_IGNORE)
					continue;

				// Base terrain
				float ground = noise_base->result[index2d];

				// Gradient & shallow seabed
				s32 grad = (y < water_level) ? grad_wl + (water_level - y) * 3 : 1 - y;

				// Hill/Mountain height (hilliness)
				float height1 = noise_height1->result[index2d];
				float height2 = noise_height2->result[index2d];
				float height3 = noise_height3->result[index2d];
				float height4 = noise_height4->result[index2d];
				float mnt_var = noise_mnt_var->result[index3d];
				// Combine height noises and apply 3D variation
				float hill1 = getLerp(height1, height2, mnt_var);
				float hill2 = getLerp(height3, height4, mnt_var);
				float hill3 = getLerp(height3, height2, mnt_var);
				float hill4 = getLerp(height1, height4, mnt_var);
				// 'hilliness' determines whether hills/mountains are
				// small or large
				float hilliness = std::fmax(std::fmin(hill1, hill2), std::fmin(hill3, hill4));

				// Rolling hills
				float hter = noise_hills_terrain->result[index2d];
				float n_hills = noise_hills->result[index2d];
				float hill_mnt = hilliness * pow(n_hills, 2.f);
				float hills = pow(fabs(hter), 3.f) * hill_mnt;

				// Ridged mountains
				float rter = noise_ridge_terrain->result[index2d];
				float n_ridge_mnt = noise_ridge_mnt->result[index2d];
				float ridge_mnt = hilliness * (1.f - fabs(n_ridge_mnt));
				float ridged_mountains = pow(fabs(rter), 3.f) * ridge_mnt;

				// Step (terraced) mountains
				float ster = noise_step_terrain->result[index2d];
				float n_step_mnt = noise_step_mnt->result[index2d];
				float step_mnt = hilliness * getSteps(n_step_mnt);
				float step_mountains = pow(fabs(ster), 3.f) * step_mnt;

				// Final terrain level
				float mountains = hills + ridged_mountains + step_mountains;
				float surface_level = ground + mountains + grad;

				if (y < surface_level) {
					vm->m_data[vi] = mn_stone; // Stone
					if (y > stone_surface_max_y)
						stone_surface_max_y = y;
				} else if (y <= water_level) {
					vm->m_data[vi] = mn_water; // Sea water
				} else {
					vm->m_data[vi] = mn_air; // Air
				}
			}
			index2d -= ystride;
		}
		index2d += ystride;
	}

	return stone_surface_max_y;
}
Пример #9
0
int ReadStarDrop::createDropletObj(int numSteps, float *timeFrame)
{
    // object arrays : create all in a loop
    coDistributedObject **outObj[6];
    char nameMask[6][256];

    int portNo;
    for (portNo = 0; portNo < 6; portNo++)
    {
        outObj[portNo] = new coDistributedObject *[numSteps + 1];
        outObj[portNo][numSteps] = NULL;
        sprintf(nameMask[portNo], "%s_%%d", p_dropOut[portNo]->getObjName());
    }

    int step, drop;
    char buf[128];

    // 1=no stuck, 2=all, 3=stuck only
    int stickHandling = p_stickHandling->getValue();

    // get the point size from covise.config
    std::string pointSize = coCoviseConfig::getEntry("Module.ReadStarDrop.PointSize");

    // we already calculated the start/end Times, but now for the STEPS
    int *dropStart = new int[d_numDrops];
    int *dropEnd = new int[d_numDrops];

    getSteps(numSteps, timeFrame, dropStart, dropEnd, stickHandling);

#ifdef VERBOSE
    {
        int i;
        fprintf(debug, "\n\nSteps\n======\n\n");
        for (i = 0; i < d_numDrops; i++)
            if (dropStart[i] != INT_MAX || dropEnd[i] != -1)
                fprintf(debug, "Drop %8d : %5d - %5d\n", i, dropStart[i], dropEnd[i]);
            else
                fprintf(debug, "Drop %8d : Never appears\n", i);
    }
#endif

    ///// This may be too many droplets to show, so thin out here

    int useDrops = p_maxDrops->getValue();
    if (useDrops && useDrops < d_numDrops)
    {
        int i = 0;

        // we increase useDrops instead of decreasing d_numDrops
        while (useDrops < d_numDrops)
        {
            i = (i + 786433) % (d_numDrops - 1); // loop with prime -> reach all elements once
            dropStart[i + 1] = INT_MAX;
            dropEnd[i + 1] = -1;
            useDrops++;
        }
    }

///// loop over time steps

#ifdef VERBOSE
    fprintf(debug, "\nTimeframes used:\n---------------\n\n");
#endif

    for (step = 0; step < numSteps; step++)
    {
        // count droplets in step
        int numDrops = 0;
        for (drop = 1; drop < d_numDrops; drop++)
        {
            if (step >= dropStart[drop] && step <= dropEnd[drop])
                numDrops++;
        }
#ifdef VERBOSE
        fprintf(debug, "Step %5d: %5d Drops  Time %5f - %5f\n-----------\n",
                step, numDrops, timeFrame[step], timeFrame[step + 1]);
#endif
        // alocate output objects : create 0-sized objects as well !!!

        sprintf(buf, nameMask[LOCA], step);
        coDoPoints *locaObj = new coDoPoints(buf, numDrops);
        outObj[LOCA][step] = locaObj;
        if (!pointSize.empty())
            locaObj->addAttribute("POINTSIZE", pointSize.c_str());

        sprintf(buf, nameMask[VELO], step);
        coDoVec3 *veloObj = new coDoVec3(buf, numDrops);
        outObj[VELO][step] = veloObj;

        sprintf(buf, nameMask[TEMP], step);
        coDoFloat *tempObj = new coDoFloat(buf, numDrops);
        outObj[TEMP][step] = tempObj;

        sprintf(buf, nameMask[DIAM], step);
        coDoFloat *diamObj = new coDoFloat(buf, numDrops);
        outObj[DIAM][step] = diamObj;

        sprintf(buf, nameMask[MASS], step);
        coDoFloat *massObj = new coDoFloat(buf, numDrops);
        outObj[MASS][step] = massObj;

        sprintf(buf, nameMask[COUN], step);
        coDoFloat *counObj = new coDoFloat(buf, numDrops);
        outObj[COUN][step] = counObj;

        if (numDrops)
        {
            float *x, *y, *z, *u, *v, *w;
            float *temp, *diam, *mass, *coun;

            locaObj->getAddresses(&x, &y, &z);
            veloObj->getAddresses(&u, &v, &w);
            tempObj->getAddress(&temp);
            diamObj->getAddress(&diam);
            massObj->getAddress(&mass);
            counObj->getAddress(&coun);

            for (drop = 1; drop < d_numDrops; drop++)
            {
                DropRec *dropRec;
                if (step >= dropStart[drop]
                    && step <= dropEnd[drop])
                {
                    dropRec = getDroplet(drop, timeFrame[step], timeFrame[step + 1],
                                         stickHandling);
                    if (dropRec)
                    {
                        numDrops--;

                        *x = d_scale * dropRec->x;
                        x++;
                        *y = d_scale * dropRec->y;
                        y++;
                        *z = d_scale * dropRec->z;
                        z++;

                        *u = dropRec->u;
                        u++;
                        *v = dropRec->v;
                        v++;
                        *w = dropRec->w;
                        w++;

                        *temp = dropRec->temp;
                        temp++;
                        *diam = dropRec->diam;
                        diam++;
                        *mass = dropRec->mass;
                        mass++;
                        *coun = dropRec->coun;
                        coun++;
                    }
                    else
                    {
#ifdef VERBOSE
                        fprintf(debug, "Step %4d : Drop %7d not in Step\n", step, drop);
                        getDroplet(drop, timeFrame[step], timeFrame[step + 1], stickHandling);
#endif
                    }
                }
            }
            if (numDrops != 0)
                cerr << "Step " << step << " left " << numDrops << " empty Drops" << endl;
        }
    }

    // content for timestep attrib
    sprintf(buf, "0 %d", numSteps - 1);

    // Create all Sets
    for (portNo = 0; portNo < 6; portNo++)
    {
        coDoSet *set = new coDoSet(p_dropOut[portNo]->getObjName(), outObj[portNo]);
        set->addAttribute("TIMESTEP", buf);
        set->addAttribute("DataObjectName", "Droplet");
        if (portNo > 0)
            set->addAttribute("SPECIES", s_species[portNo]);
        p_dropOut[portNo]->setCurrentObject(set);
    }

    return SUCCESS;
}