int main( void )
{
	led_init();
	timer_init();
	uart_init();
	servo_init();
	ppm_init();
	adc_init();
	input_init();

	sei();

	puts( "$Id: mainloop.c,v 2.14 2003/03/25 17:44:05 tramm Exp $\r\n" );

	while( 1 )
	{
		input_task();
		user_task();

		if( ppm_valid )
		{
			ppm_output();
			ppm_valid = 0;
		}

		/* Every 32768 microseconds */
		if( timer_periodic() == 0 )
			continue;

		adc_output();

	}
}
示例#2
0
int main(void)
{
	littleWire *myLittleWire = NULL;
	
	myLittleWire = littleWire_connect();

	if(myLittleWire == NULL){
		printf("Little Wire could not be found!\n");
		exit(EXIT_FAILURE);
	}

	servo_init(myLittleWire);

	for(;;)
	{
		printf("Current locations: %d\n",currentLocation);

		// Set two servo channels to the same location
		servo_updateLocation(myLittleWire,currentLocation,currentLocation);
		
		if(direction)
			currentLocation++;
		else
			currentLocation--;

		if(currentLocation==180)
			direction=0;
		else if(currentLocation==0)
			direction=1;

		delay(DELAY);
	}
}
示例#3
0
文件: main.c 项目: topnotcher/teabot
int main(void) {
	//allow everything to settle/boot/etc
	//(mainly the mp3 chip takes a while to boot up)
	_delay_ms(2000);

	servo_init();
	keypad_init();
	display_init();
	thermistor_init();
	ssr_init();
	init_timers();
	mp3_init();

	tea_off();

	PMIC.CTRL |= PMIC_MEDLVLEN_bm | PMIC_LOLVLEN_bm | PMIC_HILVLEN_bm;
	sei();

	//another 100 for things to settle
	_delay_ms(100);

	//welcome
	mp3_play(10);

	while (1) {
		char key;
		if ((key = keypad_getc()))
			handle_key(key);
	}
}
/* For backwards compatability */ 
void servo_control(unsigned char value)
{
	if (value == ENABLE)
		servo_init();
	else
		servo_setup(DISABLE);
}
示例#5
0
/*************************************************************
//! 函数名:void main (void)
//! 函数说明:主程序
*************************************************************/
void main (void)
{
   unsigned char i,max_data_chn; 
   struct movement_info *car_cmd;

   PCA0MD &= ~0x40;    //关闭看门狗                
   Oscillator_Init();  //时钟晶振初始化
    // ADC_PortInit();                  
   Timer1_Init();      //定时器1初始化                
   //Timer3_Init ();                                                        
   SMBus_Init ();      //SMBus初始化(IIC控制器)    
   PWM_Init();		   //PWM初始化
   servo_init();	   //舵机控制初始化            
  //Watchdog_Init();
   EA = 1;             // 开中断
  
	do
	{	      

	    Flag = 0; 
		while (!rec_flag) ;	//检测接收控制数据的标志

		rec_flag = 0;
		car_cmd = (struct movement_info *)Data; //若接收到数据,则从全局区取出
		car_movement_control(car_cmd);			//根据控制信息执行车体控制代码
		
	}while(1);

}
示例#6
0
int main(void)
{
    uint8_t angle = SERVO_ANGLE_MIN;
    uint8_t direction = 0;

    // disable global system prescaler
    // this makes the effective clock speed F_CPU
    CLKPR = _BV(CLKPCE);
    CLKPR = 0x00;

    servo_init();

    for (;;) {
        _delay_ms(100);
        servo_setAngle(angle);

        if (angle == SERVO_ANGLE_MIN || angle == SERVO_ANGLE_MAX) {
            direction = !direction;
        }

        if (direction) {
            angle += 5;
        } else {
            angle -= 5;
        }
    }

    return 0;
}
示例#7
0
void init() {
	/**
	 * Setup default pin config:
	 *
	 * 1-16 : Digital Output
	 * 17-32: Digital Input
	 *
	 * Servos on S1 - S12
	 *
	 * Motor control on associated pins
	 */

	out_ports[0] = &PORTF;
	out_ports[1] = &PORTK;
	out_ports[2] = &PORTA;
	out_ports[3] = &PORTC;

	in_ports[0] = &PINF;
	in_ports[1] = &PINK;
	in_ports[2] = &PINA;
	in_ports[3] = &PINC;

	dir_ports[0] = &DDRF;
	dir_ports[1] = &DDRK;
	dir_ports[2] = &DDRA;
	dir_ports[3] = &DDRC;
	
	servo_init();
	motor_init();
}
示例#8
0
void brain_run(void)
{
    /* initialize components */
    puts("[brain] initializing front distance sensor...");
    if (srf02_init(&dist_front, CONF_DIST_FRONT_I2C, CONF_DIST_FRONT_ADDR) < 0) {
        puts("[failed]");
        return;
    }

    puts("[brain] initializing back distance sensor...");
    if (srf02_init(&dist_back, CONF_DIST_BACK_I2C, CONF_DIST_BACK_ADDR) < 0) {
        puts("[failed]");
        return;
    }

    puts("[brain] initializing steering servo...");
    if (servo_init(&steering, CONF_STEERING_PWM, CONF_STEERING_PWM_CHAN,
                   CONF_STEERING_MIN, CONF_STEERING_MAX) < 0) {
        puts("[failed]");
        return;
    }
    servo_set(&steering, CONF_STEERING_CENTER);

    puts("[brain] initializing motor driver...");
    if (motor_init(&mot, &mot_params)) {
        puts("[failed]");
        return;
    }

    /* go and have fun */
    puts("[brain] components ready, all up an running!");
    thread_create(stack, sizeof(stack),
                  CONF_PRIO_COL_DETECT, THREAD_CREATE_STACKTEST,
                  colllision_detection, NULL, "col detect");
}
示例#9
0
文件: main.c 项目: 4dahalibut/RIOT
int main(void)
{
    int res;
    int pos = (STEP_LOWER_BOUND + STEP_UPPER_BOUND) / 2;
    int step = STEP;

    puts("\nRIOT RC servo test");
    puts("Connect an RC servo or scope to PWM_0 channel 0 to see anything");

    res = servo_init(&servo, DEV, CHANNEL, SERVO_MIN, SERVO_MAX);
    if (res < 0) {
        puts("Errors while initializing servo");
        return -1;
    }
    puts("Servo initialized.");

    while (1) {
        servo_set(&servo, pos);

        pos += step;
        if (pos <= STEP_LOWER_BOUND || pos >= STEP_UPPER_BOUND) {
            step = -step;
        }

        vtimer_usleep(WAIT);
    }

    return 0;
}
示例#10
0
servo_data_t *create_jim_servo()
{
    servo_data_t *servo = malloc(sizeof(servo_data_t));
    servo_init(servo);
    servo_calibrate(servo, 68, 285);
    servo_set_position_deg(servo, 90);
    return servo;
}
示例#11
0
文件: main.c 项目: erwincoumans/bldc
int main(void) {
    halInit();
    chSysInit();

    chThdSleepMilliseconds(1000);

    hw_init_gpio();
    LED_RED_OFF();
    LED_GREEN_OFF();

    conf_general_init();
    ledpwm_init();

    mc_configuration mcconf;
    conf_general_read_mc_configuration(&mcconf);
    mc_interface_init(&mcconf);

    commands_init();
    comm_usb_init();

    app_configuration appconf;
    conf_general_read_app_configuration(&appconf);
    app_init(&appconf);

    timeout_init();
    timeout_configure(appconf.timeout_msec, appconf.timeout_brake_current);

#if CAN_ENABLE
    comm_can_init();
#endif

#if WS2811_ENABLE
    ws2811_init();
    led_external_init();
#endif

#if ENCODER_ENABLE
    encoder_init();
#endif

#if SERVO_OUT_ENABLE
#if SERVO_OUT_SIMPLE
    servo_simple_init();
#else
    servo_init();
#endif
#endif

    // Threads
    chThdCreateStatic(periodic_thread_wa, sizeof(periodic_thread_wa), NORMALPRIO, periodic_thread, NULL);
    chThdCreateStatic(sample_send_thread_wa, sizeof(sample_send_thread_wa), NORMALPRIO - 1, sample_send_thread, NULL);
    chThdCreateStatic(timer_thread_wa, sizeof(timer_thread_wa), NORMALPRIO, timer_thread, NULL);

    for(;;) {
        chThdSleepMilliseconds(5000);
    }
}
示例#12
0
int main(void)
{
	struct heading result;
	/*u08 k=0;
	u08 b=0;
	u08 choice=0;
	u08 button=0;*/
	u08 ir=0;
	u08 i=0;

	x = 64;
	y = 48;
	initialize();
	motor_init();
	servo_init();
	set_motor_power(0,0);
	set_motor_power(1,0);
	set_motor_power(2,0);
	set_motor_power(3,0);
	compass_init();
	sonar_init();

	calCompass();
	while(1)
	{
		clear_screen();
		result = compass();

		/* use calibration data */
		result.x -= compZero.x;
		result.y -= compZero.y;

		print_string("x ");     /*  2 */
		print_int(result.x);    /*  3 */
		print_string(" y ");    /*  3 */
		print_int(result.y);    /*  3 */
		/* print_string(" s ");  */ /*  3 */
		/* print_int(getSonar(0)); */ /*  3 */
					 /*  =17 */
		next_line();
		/* print_string("a "); */ /*  2 */
		/* print_int(IR(0)); */ /*  3 */
		/* print_string(" b "); */ /*  3 */
		/* print_int(analog(1)); */ /*  3 */
		/* print_string(" c "); */ /*  3 */
		/* print_int(analog(2)); */ /*  3 */
		/* print_int(i++); */ /*  =17 */
		/* print_int(distance(0));
		print_string(" "); */
		print_int(sizeof(int));
		delay_ms(200);
		/* print_int(i);
		i=sweep(); */

	}
}
示例#13
0
void init_devices (void)
{
 cli(); //Clears the global interrupt
 port_init();  //Initializes all the ports
 uart0_init();
 lcd_set_4bit();
 lcd_init(); 
 servo_init();
 left_position_encoder_interrupt_init();
 right_position_encoder_interrupt_init();
 sei();   // Enables the global interrupt 
}
示例#14
0
文件: main.cpp 项目: teamon/sumocpp
void init(){
  led_init();
  motor_init();
  switch_init();
  ground_init();
  dist_init();
  servo_init();
  if(DEBUG) usart_init();

  motor1 = Motor(&OCR1A, &MOTOR1_DIR_PORT, MOTOR1_DIR_PIN, MAX_POWER);
  motor2 = Motor(&OCR1B, &MOTOR2_DIR_PORT, MOTOR2_DIR_PIN, MAX_POWER);
}
示例#15
0
int main(int argc, char* argv[]) {
	struct servo_shm* val = (struct servo_shm*)parse_attach(argc, argv, 1, sizeof(struct servo_shm));

	servo_init(val->channels);

	while(1) {
		update_pwm();
		val->lastUpdate = 0;
		msleep(10);
	}

	return 0;
}
示例#16
0
void servo_test()
{
    servo_data_t rservo; //fake malloc
    servo_data_t *servo = &rservo;

    servo_init(servo);

    servo_calibrate(servo, 8, 35);
    servo_set_position_deg(servo, 90);

    while (1)
    {
        if (isAvailable0())
        {
            char c = getChar0();
            switch (c)
            {
                case '0':
                    servo_set_position_deg(servo, 0);
                    break;
                case '4':
                    servo_set_position_deg(servo, 45);
                    break;
                case '9':
                    servo_set_position_deg(servo, 90);
                    break;
                case '3':
                    servo_set_position_deg(servo, 135);
                    break;
                case '8':
                    servo_set_position_deg(servo, 180);
                    break;
                case '+':
                    servo_increment_degrees(servo, 1);
                    break;
                case '-':
                    servo_decrement_degrees(servo, 1);
                    break;
                default:
                    break;
            }

            double calcDeg = servo_calculate_position_deg(servo);
            char buff[300];
            ftoa(buff, calcDeg);

            printf0("Cur pulse width: %u\t deg: %u\t calcDeg: %s\r\n", servo->cur_pulse_width, servo->desired_deg,
                    buff);
        }
    }
}
示例#17
0
文件: init.c 项目: gowgos5/RobotCar
void system_board_init(void)
{
	/* This function is meant to contain board-specific initialization code
	 * for, e.g., the I/O pins. The initialization can rely on application-
	 * specific board configuration, found in conf_board.h.
	 */
	
	io_init();
	timers_init();
	servo_init();
	bt_init();
	//	adc_init();
	hcsr04_init();
}
示例#18
0
文件: main.c 项目: fliedpig/ALF-llvm
void fbw_init(void) {
  uart_init_tx();
  uart_print_string("FBW Booting $Id: main.c,v 1.3 2008/10/22 19:41:19 casse Exp $\n");

#ifndef CTL_BRD_V1_1
  fbw_adc_init();
  fbw_adc_buf_channel(3, &vsupply_adc_buf);
  fbw_adc_buf_channel(6, &vservos_adc_buf);
#endif
  timer_init();
  servo_init();
  ppm_init();
  fbw_spi_init();
  //sei(); //FN
}
示例#19
0
void init_all()
{
	sensor_init();
	stepper_init();
	dc_mot_init();
	servo_init();
	pinMode(13,OUTPUT);
	Serial.begin(115200);

	pinMode(12,OUTPUT);
	digitalWrite(12,HIGH);
	pinMode(13,OUTPUT);
	digitalWrite(13,LOW);

}
示例#20
0
void fbw_init(void) {
  uart_init_tx();
  uart_print_string("FBW Booting $Id: main.c,v 1.4 2011-01-25 10:42:14 plazar Exp $\n");

#ifndef CTL_BRD_V1_1
  fbw_adc_init();
  fbw_adc_buf_channel(3, &vsupply_adc_buf);
  fbw_adc_buf_channel(6, &vservos_adc_buf);
#endif
  timer_init();
  servo_init();
  ppm_init();
  fbw_spi_init();
  //sei(); //FN
}
示例#21
0
void init(void)
{
    servo_init();
    door_init();
    if (mqtt_init() != 0) {
        printf("请检查您的网络!\n");
        exit(-1);
    }
    debug_print("mqtt init over");
    create_doorbell_sound_pipeline();
    debug_print("create_doorbell_sound_pipeline");
    create_receive_pipeline();
    debug_print("create_receive_pipeline");
    set_receive_pipeline_playing();
}
示例#22
0
void main()
{
    servo_init(no_of_servos);    //initialize servo control
    interrupt_init();            //initialize interrupts
    unsigned char i;
    while(1)
    {
        //move from 0deg to 180deg in 20deg steps
        for(i=0; i<181; i+=20)
        {
            servo_move(i, 1);
            Delay_ms(1000);
        }
    }
}
int main(void)
{
     int i;
     clock_init();
     gpio_init();
     servo_init();

     //gpio_set(GPIOC, GPIO13);

     for(i=0;i<100;i++){
       gpio_toggle(GPIOC, GPIO13); /* LED on/off */   
       delay(1500000);
     }

     gpio_clear(GPIOC, GPIO13);  

     // let pan-til "look around a little"
     while(1) {
          set_servos(SERVO_MIN, SERVO_MAX);

          set_servos(SERVO_NULL, SERVO_NULL);

          set_servos(SERVO_MAX, SERVO_MIN);

          set_servos(SERVO_NULL, SERVO_NULL);

          set_servos(SERVO_MIN, SERVO_MIN);

          set_servos(SERVO_MAX, SERVO_MAX);

          set_servos(SERVO_NULL, SERVO_NULL);

          set_servos(SERVO_MIN, SERVO_NULL);

          set_servos(SERVO_MAX, SERVO_NULL);

          set_servos(SERVO_NULL, SERVO_NULL);

          set_servos(SERVO_NULL, SERVO_MIN);

          set_servos(SERVO_NULL, SERVO_MAX);

          set_servos(SERVO_NULL, SERVO_NULL);

     }

     return 0;
}
示例#24
0
int main (void) {
	uint8_t i = 0;
	uint8_t j = 0;
	char read = 0;
	char command[COMMAND_LENGTH];
	uint8_t commandPosition = 0;
	uint8_t checksum = 0;

	for (i = 0; i < SERVO_COUNT; i++) {
		servopos[i] = 100;
	}

	sei();
	servo_init();
	ioinit();

	while (1) {
		read = uart_getchar();
		command[commandPosition] = read;
		checksum += read;

		if (read == 0) {
			if (checksum == 0) {
				// Handle command

				switch (command[0]) {
				case 0x01:
					setServo(command[1], command[2]);
					break;
				case 0x02:
					getServo(command[1]);
					break;
				}
			} else {
				// Command error
				uart_putchar(0xFF);
			}
			checksum = 0;
			commandPosition = 0;
		} else {
			commandPosition++;
		}
	}

	return 0;
}
示例#25
0
文件: servo.c 项目: bitursa/maos
/**
   Applies type I or type II filter based on number of entries in gain.
*/
int servo_filter(SERVO_T *st, const dcell *_merr){
    if(!st->initialized && _merr){
	servo_init(st, _merr);
    }
    const dcell *merr=servo_shift_al(st, _merr);
    if(!merr) return 0;
    servo_shift_ap(st);
    if(!st->mint){
	error("SERVO_T must be created using servo_new()\n");
    }
    switch(st->ep->nx){
    case 1://type I
	if(st->ep->ny==1){
	    dcelladd(&st->mpreint, 0, merr, st->ep->p[0]);//just record what is added.
	}else{
	    if(!st->mpreint){
		st->mpreint=dcellnew2(merr);
	    }
	    for(int ic=0; ic<merr->nx; ic++){
		if(!merr->p[ic]) continue;
		assert(merr->p[ic]->nx==st->ep->ny);
		for(long i=0; i<merr->p[ic]->nx; i++){
		    st->mpreint->p[ic]->p[i]=st->ep->p[i]*merr->p[ic]->p[i];
		}
	    }
	}
	break;
    case 2:{//PID controller
	if(st->ep->ny!=1) error("not supported\n");
	double g1=st->ep->p[0]+st->ep->p[1];
	double g2=-st->ep->p[1];
	dcelladd(&st->mpreint, 0, merr, g1);
	dcelladd(&st->mpreint, 1, st->merrlast, g2);
	dcellcp(&st->merrlast, merr);
    }
	break;
    case 3://type II
	servo_typeII_filter(st, merr);
	break;
    default:
	error("Invalid: st->ep->nx=%ld", st->ep->nx);
    }
    dcelladd(st->mint->p, 1, st->mpreint, 1);
    return 1;
}
int main(void)
{
	_delay_ms(250);

	servo_init();
	ir_init();
	bluetooth_init();
	ultrasonic_init();
	buttons_init();
	sei();
	
    while(1) {
		comm_exec();
		move_proc();
		
		if (button_get_state(1)) move_enable(false);
		if (button_get_state(2)) move_enable(true);
    }
}
示例#27
0
文件: main.c 项目: tuwuhs/servomotion
int main(void)
{
	struct gpio_pin heartbeat_led;
	struct timer heartbeat_timer;

	struct aparser_ctx uart_parser;

	cli();

	gpio_init_output(&yellow_led, &PORTC, 0, false);
	gpio_init_output(&heartbeat_led, &PORTB, 5, false);
	timer_set_period_ms(&heartbeat_timer, 500);

	servo_init();
	uart_init();
	systick_init();

	aparser_init(&uart_parser, 2);
	aparser_register_commands(&uart_parser, uart_parser_item);

	wdt_enable(WDTO_500MS);

	sei();

	for (;;) {
		uint8_t data;

		if (uart_getchar(&data) == UART_RETCODE_SUCCESS) {
			uart_putchar(data);
			aparser_update_and_execute(&uart_parser, data);
		}

		if (timer_has_expired(&heartbeat_timer)) {
			timer_restart(&heartbeat_timer);
			gpio_toggle(&heartbeat_led);
		}

		wdt_reset();
	}

	return 0;
}
示例#28
0
文件: main.c 项目: likon/bldc
int main(void) {
	halInit();
	chSysInit();
	ledpwm_init();
	mcpwm_init();
	comm_init();
	servo_init();

#if USE_SERVO_INPUT
	servodec_init();
#endif

	// Threads
	chThdCreateStatic(periodic_thread_wa, sizeof(periodic_thread_wa), NORMALPRIO, periodic_thread, NULL);
	chThdCreateStatic(sample_send_thread_wa, sizeof(sample_send_thread_wa), NORMALPRIO, sample_send_thread, NULL);

	for(;;) {
		chThdSleepMilliseconds(100);
	}
}
示例#29
0
int main(int argc, char *argv[])
{
    pthread_t read_loop, servo_loop, simulate_loop, control_loop,
        command_loop;

    control_init();
    simulate_temp_init();
    servo_init();
    read_temp_init();

    pthread_create(&control_loop, NULL, control_thread, NULL);
    pthread_create(&command_loop, NULL, command_thread, NULL);
    pthread_create(&simulate_loop, NULL, simulate_temp_thread, NULL);
    pthread_create(&read_loop, NULL, read_temp_thread, NULL);
    pthread_create(&servo_loop, NULL, servo_thread, NULL);

    for (;;)
        usleep(1e6);

    return 0;
}
示例#30
0
文件: servo.c 项目: bitursa/maos
/**
   Initialize. al is additional latency
*/
SERVO_T *servo_new(dcell *merr, const dmat *ap, int al, double dt, const dmat *ep){
    SERVO_T *st=calloc(1, sizeof(SERVO_T));
    if(ap){
	st->ap=ddup(ap);
    }else{
	st->ap=dnew(2,1);
	st->ap->p[0]=1;
    }
    if(st->ap->nx<2){
	dresize(st->ap, 2, 1);//2 element to ensure we keep integrator history.
    }
    st->mint=cellnew(st->ap->nx, 1);
    st->dt=dt;
    st->al=al;
    st->merrhist=cellnew(st->al+1, 1);
    servo_update(st, ep);
    if(merr && merr->nx!=0 && merr->ny!=0 && merr->p[0]){
	servo_init(st, merr);
    }
    return st;
}