예제 #1
0
  void Laser::Init() {

    // Initialize timers for laser intensity control
    #if LASER_CONTROL == 1

      #if IS_TIMER_3_PWR
        timer3_init(LASER_PWR_PIN);
      #elif IS_TIMER_4_PWR
        timer4_init(LASER_PWR_PIN);
      #endif

    #elif LASER_CONTROL == 2

      #if IS_TIMER_3_PWM
        timer3_init(LASER_PWM_PIN);
      #elif IS_TIMER_4_PWM
        timer4_init(LASER_PWM_PIN);
      #endif

    #endif

    #if ENABLED(LASER_PERIPHERALS)
      OUT_WRITE(LASER_PERIPHERALS_PIN, HIGH);         // Laser peripherals are active LOW, so preset the pin
      OUT_WRITE(LASER_PERIPHERALS_STATUS_PIN, HIGH);  // Set the peripherals status pin to pull-up.
    #endif

    #if LASER_CONTROL == 2
      OUT_WRITE(LASER_PWR_PIN, LASER_UNARM);  // Laser FIRING is active LOW, so preset the pin
    #endif

    // initialize state to some sane defaults
    laser.intensity = 100.0;
    laser.ppm = 0.0;
    laser.duration = 0;
    laser.status = LASER_OFF;
    laser.firing = LASER_ON;
    laser.mode = CONTINUOUS;
    laser.last_firing = 0;
    laser.diagnostics = false;
    laser.time = 0;

    #if ENABLED(LASER_RASTER)
      laser.raster_aspect_ratio = LASER_RASTER_ASPECT_RATIO;
      laser.raster_mm_per_pulse = LASER_RASTER_MM_PER_PULSE;
      laser.raster_direction = 1;
    #endif // LASER_RASTER

    laser.extinguish();

  }
예제 #2
0
void stepperInit_4pin(stepper_struct* current_stepper)
{
	// set default values in current_stepper struct
	current_stepper->step_number = 0;							// which step the motor is on
  current_stepper->direction = DIRECTION_CW;		// motor direction
	setSpeed(current_stepper, DEFAULT_PPS);				// set default pulsesPerSecond
	current_stepper->current_step_number = 0;			// set default home position to current position = 0;
	current_stepper->target_step_number = 0;			// set default target position to be the same as home position = 0;
	current_stepper->correction_pulses = 0;				// number of correction pulses - number of steps before output shaft actually moves
	
  // setup the pins on the microcontroller:
  gpio_pinSetup(current_stepper->motor_pin_1_bank, current_stepper->motor_pin_1, GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_Speed_40MHz);
	gpio_pinSetup(current_stepper->motor_pin_2_bank, current_stepper->motor_pin_2, GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_Speed_40MHz);
	gpio_pinSetup(current_stepper->motor_pin_3_bank, current_stepper->motor_pin_3, GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_Speed_40MHz);
	gpio_pinSetup(current_stepper->motor_pin_4_bank, current_stepper->motor_pin_4, GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_Speed_40MHz);
  // set default GPIO values
	GPIO_ResetBits(current_stepper->motor_pin_1_bank, current_stepper->motor_pin_1);
	GPIO_ResetBits(current_stepper->motor_pin_2_bank, current_stepper->motor_pin_2);
	GPIO_ResetBits(current_stepper->motor_pin_3_bank, current_stepper->motor_pin_3);
	GPIO_ResetBits(current_stepper->motor_pin_4_bank, current_stepper->motor_pin_4);
	
  // pin_count is used by the stepMotor():
  current_stepper->pin_count = 4;
	if(current_stepper->use_half_step == USE_HALF_STEP)
	{
		current_stepper->number_of_steps = 8;
	}
	else{
		current_stepper->number_of_steps = 4;
	}
	timer3_init();
}
예제 #3
0
파일: Rover.c 프로젝트: robideau/Rover
int main() {
	
	//initialize all necessary sensors and utilities
	lcd_init();
	timer1_init();
	timer3_init();
	move_servo(90);
 	ADC_init();
	USART_Init(MYUBRR);
	init_push_buttons();
	
	oi_t *sensor_data = oi_alloc();
	oi_init(sensor_data);
	
	audioInit(sensor_data);
	//oi_play_song(1);
	
	while(1) {
		//empty currentObjects before proceeding by setting all stored objects to "invalid" - ignored by later checks
		for (int i = 0; i < 20; i++) {
			currentObjects[i].isValid = 0;
		}
		char received = serial_getc(); //take keyboard input from putty
		takeDirectionInput(received, currentObjects); //translate keyboard input into functionality
	}
	
	return 0;
}
예제 #4
0
void ADC1_Init(void)
{
	INIT_ADC_GPIO();
	ADC_DMA_Init();
	ConfigADC();
	timer3_init(500,(72-1));//500
	memset(&adc_param,0,sizeof(adc_param));
	ADC1_DMA_Start();	
}
void laser_init()
{
  #if LASER_CONTROL == 1
	timer3_init();
  #endif // LASER_CONTROL ==1
  #if LASER_CONTROL == 2
    timer3_init();
    timer4_init();
  #endif // LASER_CONTROL == 2

  // Engage the pullup resistor for TTL laser controllers which don't turn off entirely without it.
  pinMode(LASER_FIRING_PIN, OUTPUT);

  #ifdef LASER_PERIPHERALS
  digitalWrite(LASER_PERIPHERALS_PIN, HIGH);  // Laser peripherals are active LOW, so preset the pin
  pinMode(LASER_PERIPHERALS_PIN, OUTPUT);

  digitalWrite(LASER_PERIPHERALS_STATUS_PIN, HIGH);  // Set the peripherals status pin to pull-up.
  pinMode(LASER_PERIPHERALS_STATUS_PIN, INPUT);
  #endif // LASER_PERIPHERALS

  // initialize state to some sane defaults
  laser.intensity = 100.0;
  laser.ppm = 0.0;
  laser.duration = 0;
  laser.status = LASER_OFF;
  laser.firing = LASER_OFF;
  laser.mode = CONTINUOUS;
  laser.last_firing = 0;
  laser.diagnostics = false;
  laser.time = 0;
  #ifdef LASER_RASTER
    laser.raster_aspect_ratio = LASER_RASTER_ASPECT_RATIO;
    laser.raster_mm_per_pulse = LASER_RASTER_MM_PER_PULSE;
    laser.raster_direction = 1;
  #endif // LASER_RASTER
  #ifdef MUVE_Z_PEEL
    laser.peel_distance = 2.0;
    laser.peel_speed = 2.0;
    laser.peel_pause = 0.0;
  #endif // MUVE_Z_PEEL
}
예제 #6
0
//Function to initialize all the devices
void init_devices()
{
 cli(); //Clears the global interrupt
 port_init();  //Initializes all the ports
 timer5_init();
 timer3_init();
 timer1_init();
 left_position_encoder_interrupt_init();
 right_position_encoder_interrupt_init();
 ext_position_encoder_interrupt_init ();
 sei();   // Enables the global interrupt 
}
예제 #7
0
파일: util.c 프로젝트: rsanders16/MarsRover
/**
* Initializes everything on the robot
* @author Group B1
* @param oi The open interface of the robot
* @date 12/4/2012
*/
void init_all(oi_t *oi)
{
	oi = oi_alloc();
	oi_init(oi);
	init_buttons();
	init_usart();
	lcd_init();
	timer3_init();
	ADC_init();
	init_printf(0,write_one_char);
	move_servo(0);
	wait_ms(1000);
	printf("\n");
	printf("\n");
}
예제 #8
0
void inits( void) {
	cli();
	USART_init(MYUBRR, TRUE);
	can_init();
	spi_init_master();
	fm_init();
	timer0_init();
	timer1_init();
	//TODO: RUN timer3_init();
	timer3_init();
	prepare_rx(1, ID_steeringWheel, MASK_FRONT_MODULE, fm_msg_handler);
	printf("\r\nFront module initialized");
	sei();
	set_bit(DDRB, DDB6);
	clear_bit(PORTB, PB6);
}
예제 #9
0
파일: m_goalie.c 프로젝트: jialue/robockey
// Public functions
// Initialize peripheral devices
void robockey_init(void)
{
	m_clockdivide(0);	// 16 MHz
	sei();				// Enable global interrupt
	
	timer1_init(0.5);	// kHz
	timer3_init(50);	// Hz
	//timer0_init(1);	// kHz
	adc_init();
	mode_init();
	
	m_rf_open(CHANNEL,RXADDRESS,PACKET_LENGTH_RF);	// Enable wireless
	m_usb_init();									// Enable usb communication
	m_bus_init();									// Enable mbus
	m_wii_open();									// Enable wii camera
}
예제 #10
0
void PD0_INT_Handler(void)
{
//	serial_puts("enter interrupt.......");	
	if(trig_num1==0)
	{
	timer3_init();
	trig_num1 ++;
	*(RP)(GPIO_PORTD_INTLEL) |= 0x1;//change PA0 to  trailing edge下降沿触发
	}
        else
	{
	time1 = *(RP)(TIMER_T3CCR);
//        *(RP)(GPIO_PORTD_INTLEL) &= ~(0x1<<0);//change PA1 to  trailing edge下降沿触发
	}
        *(RP)(GPIO_PORTD_INTCLR) |= 0x1;//clear PA0 interrupt
}
/**
 *
 * Function to initialize the timers, registers, etc. for the ir, ping, servo, lcd
 */
void initialize()
{
	// Initialize Serial Communication
	serial_init(57600);
	// initialize timers for use by ping sensor and servo
	timer3_init(); 
	timer_init();
	// initialize ADC for use by IR sensor
	ADC_init(); 
	// Initialize Open Interface and sensor data
	sensor_data = oi_alloc();
	oi_init(sensor_data);
	// initialize LCD
	lcd_init();
	load_songs();
	
}
예제 #12
0
파일: main.c 프로젝트: danielrichman/alien
int main()
{
  gps_init();
  log_init();
  radio_init();
  sms_init();
  statusled_init();
  timer1_init();
  timer3_init();
  watchdog_init();

  /* Interrupts on - go go go! */
  sei();

  /* Now sleep - the whole program is interrupt driven */
  for (;;) sleep_mode();
}
예제 #13
0
void main_init(void) {
    OSC_init();
    TRISA = 0b11100111; // SWB,SWG,SWR,Vcap,x,ADCB,ADCG,ADCR
    TRISB = 0b00000000; // PGD,PGC,x,PWMW,x,PWMB,PWMG,PWMR
    TRISC = 0b10111010; // RX,TX,D+,D-,Vusb,x,T1OSI,T1OSO
    ANCON0 = 0b11111000; // AN2,AN1,AN0 is analog
    ANCON1 = 0b00011111; // all digital
    INTCON2bits.RBPU = 0; // PORTB Pull-Up Enable

    timer0_init(8); // ?
    timer1_init(0, T1OSC); // ?
    timer3_init(2); // button?
    RTCC_init();
    PWM_init(PR_VALUE); //250 is 3kHz

    USB_CDC_init();
}
예제 #14
0
void main_init(void) {
    OSC_init();
    TRISA = 0b00010000; // x,x,x,Vcap,x,x,x,x
    TRISB = 0b00110001; // x,x,SDA,SCL,x,x,x,x
    TRISC = 0b10111010; // RX,TX,D+,D-,Vusb,LED,T1OSI,T1OSO
    ANCON0 = 0b11111111; // xxx,xxx,xxx,RA5,RA3,RA2,RA1,RA0
    ANCON1 = 0b00011111; // VBG,xxx,xxx,RB0,RC2,RB1,RB3,RB2
    INTCON2bits.RBPU = 0; // Pull-up enable

    timer0_init(6);
    timer1_init(0, T1OSC);
    timer3_init(2); // button
    I2C_LCD_init();
    RTCC_init();
    USB_CDC_init();
    UART_init();
}
예제 #15
0
void laser_init()
{
  // Initialize timers for laser intensity control
  #if LASER_CONTROL == 1
    if (LASER_FIRING_PIN == 2 || LASER_FIRING_PIN == 3 || LASER_FIRING_PIN == 5) timer3_init(LASER_FIRING_PIN);
    if (LASER_FIRING_PIN == 6 || LASER_FIRING_PIN == 7 || LASER_FIRING_PIN == 8) timer4_init(LASER_FIRING_PIN);
  #endif
  #if LASER_CONTROL == 2
    if (LASER_INTENSITY_PIN == 2 || LASER_INTENSITY_PIN == 3 || LASER_INTENSITY_PIN == 5) timer3_init(LASER_INTENSITY_PIN);
    if (LASER_INTENSITY_PIN == 6 || LASER_INTENSITY_PIN == 7 || LASER_INTENSITY_PIN == 8) timer4_init(LASER_INTENSITY_PIN);
  #endif

  #ifdef LASER_PERIPHERALS
    digitalWrite(LASER_PERIPHERALS_PIN, HIGH);  // Laser peripherals are active LOW, so preset the pin
    pinMode(LASER_PERIPHERALS_PIN, OUTPUT);

    digitalWrite(LASER_PERIPHERALS_STATUS_PIN, HIGH);  // Set the peripherals status pin to pull-up.
    pinMode(LASER_PERIPHERALS_STATUS_PIN, INPUT);
  #endif // LASER_PERIPHERALS

  // initialize state to some sane defaults
  laser.intensity = 100.0;
  laser.ppm = 0.0;
  laser.duration = 0;
  laser.status = LASER_OFF;
  laser.firing = LASER_OFF;
  laser.mode = CONTINUOUS;
  laser.last_firing = 0;
  laser.diagnostics = false;
  laser.time = 0;
  #ifdef LASER_RASTER
    laser.raster_aspect_ratio = LASER_RASTER_ASPECT_RATIO;
    laser.raster_mm_per_pulse = LASER_RASTER_MM_PER_PULSE;
    laser.raster_direction = 1;
  #endif // LASER_RASTER
  #ifdef MUVE_Z_PEEL
    laser.peel_distance = 2.0;
    laser.peel_speed = 2.0;
    laser.peel_pause = 0.0;
  #endif // MUVE_Z_PEEL
  
  laser_extinguish();
}
예제 #16
0
파일: main.c 프로젝트: tqdong/flyembedded
void My_System_Init(void)
{
uint8_t flag, i=0;
	NVIC_Configuration();
	delay_init(72);	   	 		//延时初始化	
	for(i=0;i<5;i++)
		delay_Ms_Loop(1000);	//上电短延时	确保供电稳定
	
	LED_Init();	
	LEDALL_ON;
	timer2_init();					//PWM输出定时器初始化
	timer3_init();					//PWM输出定时器初始化
	IIC_Init();
	uart_init(38400); 	    //调试用串口初始化
	My_usart2_init(38400);	//蓝牙用串口初始化
	printf("欢迎使用启天科技BUTTERFLY四旋翼\r\n");
	printf("QQ群:471023785\r\n");
	LEDALL_OFF;
	MPU6050_Init();					//6050初始化
	SPI1_INIT();						//SPI初始化,用于nRF模块
	flag = NRF_CHECK();			//检查NRF模块是否正常工作
	if(flag != 1)
	{
		while(1)
		{
			LEDALL_OFF;
			delay_Ms_Loop(200);
			LEDALL_ON;
			delay_Ms_Loop(200);
		}
	}
	NRF24L01_INIT();						//nRF初始化
	SetRX_Mode();								//设置为接收模式
	NRF24L01_INIT();						//nRF初始化
	NRF_GPIO_Interrupt_Init();	//nRF使用的外部中断的引脚初始化
	tim4_init();								//定时中断,作为系统的控制频率	
	adcInit();									//ADC初始化,测量电池电压
}
예제 #17
0
void stepperInit_2pin(stepper_struct* current_stepper)
{
  // set default values in current_stepper struct
	current_stepper->step_number = 0;							// which step the motor is on
  current_stepper->direction = DIRECTION_CW;		// motor direction
  current_stepper->use_half_step = 0; 					// 1 when the stepper motor is to be driven with half steps (only 4-wire)	
	setSpeed(current_stepper, DEFAULT_PPS);				// set default pulsesPerSecond
	current_stepper->current_step_number = 0;			// set default current position to home position = 0;
	current_stepper->target_step_number = 0;			// set default target position to be the same as home position = 0;
	current_stepper->correction_pulses = 0;				// number of correction pulses - number of steps before output shaft actually moves
	
	// setup the pins on the microcontroller:
  gpio_pinSetup(current_stepper->motor_pin_1_bank, current_stepper->motor_pin_1, GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_Speed_40MHz);
	gpio_pinSetup(current_stepper->motor_pin_2_bank, current_stepper->motor_pin_2, GPIO_Mode_OUT, GPIO_OType_PP, GPIO_PuPd_DOWN, GPIO_Speed_40MHz);
  // set default GPIO values
	GPIO_ResetBits(current_stepper->motor_pin_1_bank, current_stepper->motor_pin_1);
	GPIO_ResetBits(current_stepper->motor_pin_2_bank, current_stepper->motor_pin_2);
	
	// pin_count is used by the stepMotor() method:
  current_stepper->pin_count = 2;
	current_stepper->number_of_steps = 4;
	
	timer3_init();
}
/**
*	Used to control the robot.
*	Receive and transmit data, measure the distance from object and navigate to the retrieval zone.
**/
int main(void)
{
	lcd_init();
	timer3_init();
	timer_init();
	ADC_init();
	USART_Init();
	oi_t *sensor_data = oi_alloc();
	oi_init(sensor_data);//should turn the iRobot Create's power LED yellow
  
	lcd_init();
	serial_puts("Start");
	//USART_Transmit(13);
	//USART_Transmit(10);
	
	
    int TempAngle[4] = {0,0,0,0};
	int TempIR[4] = {0,0,0,0};
	int pos[4] = {0,0,0,0};
	int AddIR[4] = {0,0,0,0};
	int count[4] = {0,0,0,0};
	int found = 0;
	int x1 = 0;
	int x2 = 0;
	int x3 = 0;
	int x4 = 0;
	unsigned angle = 0;
	unsigned char IR = 0;
	volatile int i=0;
	volatile int x = 0;
	char command;
    char display[100];
	char display1[20];
	char display2[20];
	char display3[20];
	char display4[20];
	char display5[100];
	char display6[100];	
			
	while (1)
	{
		command = USART_Recieve();
		USART_Transmit(command);
		//USART_Transmit(13);
		//USART_Transmit(10);
		
		if (command == '1')
		{
			found = 0;
			angle = 0;
			int t;
			int TempAngle[6] = {0, 0,0,0,0,0};
			int TempIR[6] = {0, 0,0,0,0,0};
			int pos[6] = {0, 0,0,0,0,0};
			int AddIR[6] = {0, 0, 0,0,0,0};
			int count[6] = {0, 0, 0,0,0,0};
			for (angle = 0;angle < 181;angle++)
			{	
				move_servo(angle);
				wait_ms(20);				
				
				IR = 0;
				IR = 42800*pow(ADC_read(2),-1.23);
				
				sprintf(display6, "Angle: %5d		IR: %5d",angle,IR);
				serial_puts(display6);

				if (IR < 80)
				{
				   TempAngle[found]++;
				   count[found]++;
				   AddIR[found]+=IR;
				   TempIR[found]=AddIR[found]/count[found];
				}
				
				else
				{
					if(TempAngle[found] < 5)
					{
						TempAngle[found] = 0;
					}
					
					else
					{
						pos[found] = angle- TempAngle[found]/2;
						if (TempIR[found]*TempAngle[found]< 460)
						{
							USART_Transmit(13);
							USART_Transmit(10);
							for (int i = 0;i<strlen(s8);i++)
							{
								USART_Transmit(s8[i]);
							}
							
							sprintf(display5, "object position: %5d",pos[found]);
							serial_puts(display5);
						}
						sprintf(display, "object position: %5d		IR: %5d		object size: %5d",pos[found],TempIR[found],TempAngle[found]);
						serial_puts(display);
						USART_Transmit(13);
						USART_Transmit(10);
						found++;
					}	
			     }
			}
			OCR3B = 1000-1;				//return to 0 degree	
		}				

		 if (command == 'w')
		 {
			 move_forward(sensor_data,20);
		 }
		 if (command == 's')
		 {
			 move_backforward(sensor_data,20);
		 }
		 if (command == 'a')
		 {
			turn_clockwise(sensor_data,82);
		 }
		 if (command == 'd')
		 {
			turn_counterclockwise(sensor_data,82);
		 }
		 if (command == 'q')
		 {
			 turn_clockwise(sensor_data,38);
		 }
		 if (command == 'e')
		 {
			 turn_counterclockwise(sensor_data, 38);
		 }
		 if (command == '8')
		 {
			 move_forward(sensor_data,5);
		 }
		 if (command == '5')
		 {
			 move_backforward(sensor_data,5);
		 }
		 if (command == 'p')
		 {
			 oi_t* sensor = oi_alloc();
			 oi_init(sensor);
			 
			 load_songs();
			 oi_play_song(songings);
		 }
		 if(command == 'k')
		 {
			oi_update(sensor_data);
			x1 = sensor_data->cliff_left_signal;
			x2 = sensor_data->cliff_right_signal;
			x3 = sensor_data->cliff_frontleft_signal;
			x4 = sensor_data->cliff_frontright_signal; 
			sprintf (display1, "left        = %d",x1);
			sprintf (display2, "right       = %d",x2);
			sprintf (display3, "front left  = %d",x3);
			sprintf (display4, "front right = %d",x4);
			USART_Transmit(13);
			USART_Transmit(10);
	        serial_puts(display1);
	        serial_puts(display3);
	        serial_puts(display4);			
			serial_puts(display2);
			if (x1>500||x2>500||x3>500||x4>500)
			{
				USART_Transmit(13);
				USART_Transmit(10);
				for (int i=0;i<strlen(s6);i++)
				{
					USART_Transmit(s6[i]);
				}
			}						
		}
	}	
}		
예제 #19
0
void pwm_init(void) {
	timer1_init();
	timer3_init();
}
예제 #20
0
파일: Acrobat.c 프로젝트: banisadr/acrobat
/************************************************************
Main Loop
************************************************************/
int main(void)
{
	/* Confirm Power */
	m_red(ON);

	/* Initializations */
	init();
	usb_enable();
	timer3_init();
	int gy_previous_reading = 0;

	/* Confirm successful initialization(s) */
	m_green(ON);

	/* Run */
	while (1){
		if (m_imu_raw(data))
		{
			m_green(ON);
			m_red(OFF);
			
			
			ax = lowpass(0.85,ax,data[0])+AX_OFFSET;
			az = lowpass(0.85,az,data[2])+AZ_OFFSET;
			gy = lowpass(ALPHA_LOW,gy,data[4])+GY_OFFSET;
			gy = highpass(ALPHA_HIGH,gy,gy_previous_reading,data[4]);
			gy_previous_reading = data[4];
			
			/*
			m_usb_tx_string("ax= ");
			m_usb_tx_int(ax);
			m_usb_tx_string("     az=");
			m_usb_tx_int(az);
			m_usb_tx_string("     gy=");
			m_usb_tx_long(gy);
			m_usb_tx_string("\n");
			*/
			
			
			int angle = ((float)ax*RAD2DEG)/sqrt(((float)ax*ax+(float)az*az));
			
			if (check(TIFR3,OCF3A)){	//check if timestep has completed 
				angle += gy*TIMESTEP;	//add thetadot*timestep to angle 
				set(TIFR3,OCF3A);		//reset flag 
			}
			
			m_usb_tx_int(angle);
			m_usb_tx_string("\n");
			
			/*
			m_usb_tx_string("ax= ");
			m_usb_tx_int(data[0]);
			m_usb_tx_string("     ay= ");
			m_usb_tx_int(data[1]);
			m_usb_tx_string("     az= ");
			m_usb_tx_int(data[2]);
			m_usb_tx_string("     gx= ");
			m_usb_tx_int(data[3]);
			m_usb_tx_string("     gy= ");
			m_usb_tx_int(data[4]);
			m_usb_tx_string("     gz= ");
			m_usb_tx_int(data[5]);
			m_usb_tx_string("\n");
			*/
			
		}
		else
		{
			m_green(OFF);
			m_red(ON);
		}
	}
}
예제 #21
0
//--------------------------------------------------------------------
// Main Init function
//--------------------------------------------------------------------
void init(void)
{
  uint16_t dummy = 0;
  int16_t ret;

  LED_ERROR_ON;

  //enable AD converter
  adc_init();

  ResetImu();

  //enable communication to PC over USB
  HostInit();
  
  //enable communication to the bus
  BusInit();
  
  //enable communications with gps
  GpsInit();
  
  InitLeds();
  
  XbeeInit();

  //timer for sending out estop status
  timer3_init();
  //timer3_set_overflow_callback(SendEstopStatus);
  timer3_set_overflow_callback(globalTimerOverflow);  

  timer4_init();
  timer4_set_compa_callback(Rs485ResponseTimeout);
  timer4_disable_compa_callback();

  timer1_init();
  timer1_set_compa_callback(EncodersRequestFcn);

  //generate the request packets:
  encoderRequestRawPacketSize = DynamixelPacketWrapData(MMC_MOTOR_CONTROLLER_DEVICE_ID,
                          MMC_MOTOR_CONTROLLER_ENCODERS_REQUEST,
                          &dummy,sizeof(dummy),
                          encoderRequestRawPacket,
                          encoderRequestRawPacketMaxSize);

  Servo1Init(GlobalTimerGetTime());


  //buzzer port
  BUZZER_DDR |= _BV(BUZZER_PIN);

  //enable global interrupts 
  sei();
  
  DDRL |= _BV(PL3) | _BV(PL5) | _BV(PL4);
  PORTL |= _BV(PL3) | _BV(PL5) | _BV(PL4);
  //PORTL |= _BV(PL3);
  
  /*
  TCCR5A |= _BV(WGM51) | _BV(WGM50);
  TCCR5B |= _BV(WGM52) | _BV(WGM53);
  OCR5A = 2000;
  TCCR5A |= _BV(COM5A0);
  TCCR5A |= _BV(COM5B0);
  TCCR5A |= _BV(COM5C0);
  */

  LED_ERROR_OFF;
}
예제 #22
0
int main(int argc, char *argv[])
{
int i=0;
int h=0;
int bupi=0;


cli();
memset(command,'$',58);
init();
timer0_init();
timer1_init();
timer3_init();
timer4_init();
timer5_init();
//lcd_init();
//lcd_string("Welcome");
//lcd_move(0,1);
//lcdconfig();
//lcd_string("Give me a code:");
//lcd_move(0,2);
UART_init();
//adc_init();
//lcdsenddata('F');
//lcd_num(123456);
_delay_ms(1500);
sei();

	while(1)
	{
//-------------------------------------------------scan for input	
		while(mode==0)
		{
			while(1)//scan line
			{				

				if(command[comm]=USART_Receive())
				{
					if((command[comm]==13||command[comm]=='\n'||command[comm]==59)&&(comm<59))
					{
					break;
					}

					if(echo==1)
					{
					//USART_Transmit('[');
				//	USART_Transmit(comm+48);
				//	USART_Transmit(']');
					USART_Transmit(command[comm]);
					}

					comm++;

				}
				else
				{
				}

			
			}
			mode=1;
		
			if(echo==1)
			{
			USART_String_Transmit("\nTransition to parsing.");
			}
		
		}
		


//-------------------------------------------------parse commands
		while(mode==1)//parse commands
		{
			for(i=0;i<comm;i++)//cycling i till \n-1
			{

				if(command[i]=='N'&&command[i+1]>47&&command[i+1]<58)//GET LINE NUMBER
				{
					if(echo)
					{
					USART_String_Transmit("\n Getting line number.");
					}

					temp_line_number=fetchlong(command,i,'N');
				}				

				if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='0'&&command[i+3]=='5')//GET EXTRUDER TEMP
				{

				}
				

				
				if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='0'&&command[i+3]=='4')//SET EXTRUDER TEMP FAST SXXX
				{
	
				}					

				
				
				if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='0'&&command[i+3]=='9')//SET EXTRUDER TEMP AND WAIT RXXX
				{
				
				}

				
				
				if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='4'&&command[i+3]=='0')//SET BED TEMP FAST SXXX
				{
				
				}
				

				
				if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='9'&&command[i+3]=='0')//WAIT FOR BED TEMP TO HIT RXXX
				{
				
				}

				
				
				if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='0'&&command[i+3]=='7')//FAN OFF
				{
				
				}
				
				
				
				if(command[i]=='M'&&command[i+1]=='1'&&command[i+2]=='0'&&command[i+3]=='6')//FAN ON WITH FAN SPEED S255MAX
				{
				
				}

				
				

				if(command[i]=='M'&&command[i+1]=='8'&&command[i+2]=='2'&&command[i+3]==' ')//EXTRUDER TO ABSOLUTE MODE
				{
				
				}
				

				
				if(command[i]=='G'&&command[i+1]=='2'&&command[i+2]=='1'&&command[i+3]==' ')//METRIC VALUES
				{
				
				}

				
				
				if(command[i]=='G'&&command[i+1]=='9'&&command[i+2]=='0'&&command[i+3]==' ')//ABSOLUTE POSITIONING
				{
				
				}

				
				
				if(command[i]=='G'&&command[i+1]=='9'&&command[i+2]=='2'&&command[i+3]==' ')//ZERO EXTRUDED LENGTH WITH E0 otherwise set origin?
				{
				
				}

				
				
				if(command[i]=='G'&&command[i+1]=='0'&&command[i+2]==' ')//MOVE WITHOUT EXTUSION
				{
				if(echo)
				{
				USART_String_Transmit("\nG0 command.");
				}
				line_engine(double_scan_x,double_scan_y,double_scan_z,double_scan_e,i);
				if((echo==1)&&(xroll==1)&&(yroll=1))
				{
				USART_String_Transmit("\n Xroll=1");
				USART_String_Transmit("\n Yroll=1");
				}
				mode==2;
				
				}

				
				
				if(command[i]=='G'&&command[i+1]=='1'&&command[i+2]==' ')//MOVE WITH EXTRUSION
				{



				}

				
				
				if(command[i]=='Q'&&command[i+1]=='1')//MOTOR TEST					{
				{
					if(echo)
					{
					USART_String_Transmit("\n Motor test on.");
					//xroll=1;
					yroll=1;
					//testval=(threefetchdouble(command,i,'E')/0.01)*16;
					}
				}

				
				
				if(command[i]=='Q'&&command[i+1]=='0')//MOTOR TEST
				{
					if(echo)
					{
					USART_String_Transmit("\n Motor test off.");
					}
					//xroll=0;
					yroll=0;
				}
				

				
			}
			mode=2;
				if(echo)
				{
				USART_String_Transmit("\nTransition to set outputs.");
				}
			


		}	



//-------------------------------------------------setting outputs
		while(mode==2)
		{
			while(zroll==1||eroll==1||xroll==1||yroll==1)
			{
				if(USART_Receive()=='.')
				{
				zroll=0;
				eroll=0;
				xroll=0;
				yroll=0;
				
				USART_String_Transmit("\nSW Emergency stopped, please reset!");
			//	PINK|=0b00000001;
			//	PINA|=0b00000100;
			//	PINF|=0b00000100;
			//	PIND|=0b10000000;

				}
			}

			if(zroll==0&&eroll==0&&xroll==0&&yroll==0)
			{
				if(echo)
				{
				USART_String_Transmit("\nTransition to mode 3, reseting parameters.");
				}

				mode=3;
			}


		}



//-------------------------------------------------clear things
		while(mode==3)
		{
		cli();

		memset(command,'$',58);
		comm=0;
		i=0;
		double_scan_x=-1.0;
		double_scan_y=-1.0;
		double_scan_z=-1.0;
		double_scan_e=-1.0;
		
			if(echo)
			{
			USART_String_Transmit("\nParameters reseted returning to scanning mode");
			}

		USART_String_Transmit("\n\rok");
		
		sei();

		mode=0;
		}



		
//-------------------------------------------------
		while(mode==4)
		{

		}		

	}



return 0;
}