void servoisr()
{
	static int update;

	if (update>15){
		update = 0;

		if (STEP_ENABLE){
			SYNC = true;
			UpdatePosition();
			UpdateTrajectory();
			CalculateExtCount();
			UpdatePID();
			UpdatePWM();
			SYNC = false;
		}
		rx_timer++;

	} else update++;
}
Exemple #2
0
void main()
{			
	InitHardware();
	Encoder(true);
	
	ResetServo();
	delay_ms(200);

	bEnable = !STEP_ENABLE;
		
	// run these asynch tasks
	for (;;){
		if (bServo){
			SYNC = true;
			UpdatePosition();
			UpdateTrajectory();
			CalculateExtCount();
			UpdatePID();
			UpdatePWM();
			HandleErrorTask();
			bServo = false;
		} else {		
			//HandleRXData();
			
			if (SYNC){
				if (bDirty && !bEnable){
					bDirty = false;
					SaveEEPROM();
				}
				SYNC = false;	
			}


		}
	}
}
void CStarburstProjectile::Update()
{
	ttl--;
	uptime--;
	missileAge++;

	if (target != nullptr && weaponDef->tracks) {
		const CSolidObject* so = dynamic_cast<const CSolidObject*>(target);

		if (so != NULL) {
			targetPos = so->aimPos;
			if (allyteamID != -1 && !ignoreError) {
				const CUnit* u = dynamic_cast<const CUnit*>(so);

				if (u != nullptr)
					targetPos = u->GetErrorPos(allyteamID, true);
			}
		} else {
			targetPos = target->pos;
		}

		targetPos += aimError;
	}

	if (!luaMoveCtrl) {
		UpdateTrajectory();
	}

	if (ttl > 0) {
		explGenHandler->GenExplosion(cegID, pos, dir, ttl, damages->damageAreaOfEffect, 0.0f, NULL, NULL);
	}


	{
		const unsigned int newTracerPart = (curTracerPart + 1) % NUM_TRACER_PARTS;

		curTracerPart = newTracerPart;
		TracerPart* tracerPart = &tracerParts[curTracerPart];
		tracerPart->pos = pos;
		tracerPart->dir = dir;
		tracerPart->speedf = speed.w;

		unsigned int newsize = 0;

		for (float aa = 0; aa < speed.w + 0.6f && newsize < MAX_NUM_AGEMODS; aa += TRACER_PARTS_STEP, ++newsize) {
			const float ageMod = (missileAge < 20) ? 1.0f : (0.6f + (rand() * 0.8f) / RAND_MAX);
			tracerPart->ageMods[newsize] = ageMod;
		}

		if (tracerPart->numAgeMods != newsize) {
			tracerPart->numAgeMods = newsize;
		}
	}

	age++;
	numParts++;

	if (weaponDef->visuals.smokeTrail) {
		if (smokeTrail) {
			smokeTrail->UpdateEndPos(pos, dir);
			oldSmoke = pos;
			oldSmokeDir = dir;
		}

		if ((age % 8) == 0) {
			smokeTrail = new CSmokeTrailProjectile(
				owner(),
				pos,
				oldSmoke,
				dir,
				oldSmokeDir,
				age == 8,
				false,
				7,
				SMOKE_TIME,
				0.7f,
				weaponDef->visuals.texture2
			);

			numParts = 0;
			useAirLos = smokeTrail->useAirLos;
		}
	}

	UpdateInterception();
}