예제 #1
0
void Reflow_Init(void) {
//	PID_init(&PID,16,0.1,2,PID_Direction_Direct);
	PID_init(&PID,17,0.11,2,PID_Direction_Direct);
	EEPROM_Read((uint8_t*)ee1.temperatures, 2, 96);
	ByteswapTempProfile(ee1.temperatures);
	EEPROM_Read((uint8_t*)ee2.temperatures, 128+2, 96);
	ByteswapTempProfile(ee2.temperatures);
	intsetpoint = 30;
	PID.mySetpoint = 30.0f; // Default setpoint
	PID_SetOutputLimits(&PID, 0,255+248);
	PID_SetMode(&PID, PID_Mode_Manual);
	PID.myOutput = 248; // Between fan and heat
	PID_SetMode(&PID, PID_Mode_Automatic);
	RTC_Zero();
}
예제 #2
0
파일: Controller.c 프로젝트: YJ92/Quad_2016
//*****************************************************************************
// PID control : 200Hz
//*****************************************************************************
void Init_PID(){
	// Rate pid
	PID_init(&_r_rate_PID, r_rate_Kp, r_rate_Ki, r_rate_Kd, PID_Direction_Direct);
	PID_init(&_p_rate_PID, p_rate_Kp, p_rate_Ki, p_rate_Kd, PID_Direction_Direct);
	PID_init(&_y_rate_PID, y_rate_Kp, y_rate_Ki, y_rate_Kd, PID_Direction_Direct);

	PID_SetSampleTime(&_r_rate_PID, 5); // 0.005s
	PID_SetSampleTime(&_p_rate_PID, 5);
	PID_SetSampleTime(&_y_rate_PID, 5);

	PID_SetMode(&_r_rate_PID, PID_Mode_Automatic);
	PID_SetMode(&_p_rate_PID, PID_Mode_Automatic);
	PID_SetMode(&_y_rate_PID, PID_Mode_Automatic);

	PID_SetOutputLimits(&_r_rate_PID,-20.0,20.0);
	PID_SetOutputLimits(&_p_rate_PID,-20.0,20.0);
	PID_SetOutputLimits(&_y_rate_PID,-20.0,20.0);

	_prev_angle_error = 0;
}
예제 #3
0
int main() {

	usartInit(57600);
	usartEnableReceiver();
	usartEnableTransmitter();
	usartStdio();

	setBit(DDRB, M1_DIR);
	setBit(DDRD, M1_PWM);
	setBit(DDRD, M2_DIR);
	setBit(DDRD, M2_PWM);

	clrBit(PORTB, M1_DIR);
	clrBit(PORTD, M1_PWM);
	clrBit(PORTD, M2_PWM);
	clrBit(PORTD, M2_DIR);

	timer0FastPWMMaxMode();
	timer0ClockPrescaller64();
	timer0OC0ANonInvertedMode();
	timer0OC0BNonInvertedMode();
	timer0SetCompareAValue(0);
	timer0SetCompareBValue(0);
	timer0DeactivateCompareAInterrupt();
	timer0DeactivateCompareBInterrupt();

	timer2ClockPrescaller256();
	timer2NormalMode();
	timer2OC2AOff();
	timer2OC2BOff();
	timer2ActivateOverflowInterrupt();


	i2c_init();

	adxl345_init();

	l3g4200d_init();
	l3g4200d_setoffset(0.11, -1.71, -0.46);
	//l3g4200d_settemperatureref();

	PID_init(&PID, 15,0.2,1, 0);
	PID_SetMode(&PID, 1);
	PID_SetOutputLimits(&PID, -255, 255);

	PID.mySetpoint = 0;

	motor1(0);
	motor2(0);


//	printf("\e[1;1H\e[2J");
//	printf("STARTED!\r\n");
//	_delay_ms(200);

//	motor1(120);
//	printf("Motor1 = 120\r\n");
//	_delay_ms(500);
//	motor1(-120);
//	printf("Motor1 = -120\r\n");
//	_delay_ms(500);
//	motor1(120);
//	printf("Motor1 = 120\r\n");
//	_delay_ms(500);
//	motor1(0);
//	printf("Motor1 = 0\r\n");

	sei();

	while(1);

	return 0;
}