示例#1
0
文件: main.cpp 项目: Slin/Chloe
int main()
{
	CL::Motors motors;

	CL::Sensors sensors;
	sensors.Calibrate(3.0f);
	CL::Controller controller;

	while(1)
	{
		sensors.Update();
		controller.Update(sensors.orientation, 0.3f);

		motors.SetSpeed(CL::Motors::Motor::FrontLeft, controller.GetSpeed(CL::Motors::Motor::FrontLeft));
		motors.SetSpeed(CL::Motors::Motor::FrontRight, controller.GetSpeed(CL::Motors::Motor::FrontRight));
		motors.SetSpeed(CL::Motors::Motor::BackLeft, controller.GetSpeed(CL::Motors::Motor::BackLeft));
		motors.SetSpeed(CL::Motors::Motor::BackRight, controller.GetSpeed(CL::Motors::Motor::BackRight));
	}

	motors.SetSpeed(CL::Motors::Motor::FrontLeft, 0.0f);
	motors.SetSpeed(CL::Motors::Motor::FrontRight, 0.0f);
	motors.SetSpeed(CL::Motors::Motor::BackLeft, 0.0f);
	motors.SetSpeed(CL::Motors::Motor::BackRight, 0.0f);

	mraa_deinit();

	return MRAA_SUCCESS;
}
int main(int argc, char** argv)
{
    mraa_uart_context uart;
    uart = mraa_uart_init(0);
	mraa_uart_set_baudrate(uart, 9600);
    if (uart == NULL) {
        fprintf(stderr, "UART failed to setup\n");
        printf("UART fialed");
	return EXIT_FAILURE;
    }

    char buffer[] = "Hello Mraa!";
//    mraa_uart_write(uart, buffer, sizeof(buffer));
	printf("buffer: ");
    char* current;
	while(1){
	printf("%c",buffer[1]);
    	mraa_uart_read(uart, buffer, 9);
	printf("buff:%c %c %c %c %c %c %c %c %c\n",buffer[0], buffer[1], 
buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], 
buffer[8] );
	sleep(1);

    }
//    mraa_uart_stop(uart);

    mraa_deinit();

    return EXIT_SUCCESS;
}
示例#3
0
文件: main.cpp 项目: Slin/Chloe
int main()
{
	CL::Motors motors;
	CL::Display display;

	displayText("Connect the\nBatterie", display);

	motors.SetSpeed(CL::Motors::Motor::FrontLeft, 1.0f);
	motors.SetSpeed(CL::Motors::Motor::FrontRight, 1.0f);
	motors.SetSpeed(CL::Motors::Motor::BackLeft, 1.0f);
	motors.SetSpeed(CL::Motors::Motor::BackRight, 1.0f);

	usleep(10000000);

	motors.SetSpeed(CL::Motors::Motor::FrontLeft, 0.0f);
	motors.SetSpeed(CL::Motors::Motor::FrontRight, 0.0f);
	motors.SetSpeed(CL::Motors::Motor::BackLeft, 0.0f);
	motors.SetSpeed(CL::Motors::Motor::BackRight, 0.0f);

	usleep(5000000);

	display.Clear();

	mraa_deinit();

	return MRAA_SUCCESS;
}
示例#4
0
mkInterface::~mkInterface() {

    if ( gpio )
    	delete gpio;

    mraa_deinit();
    fprintf(stdout, "\nGoodbye mraa\n\n" );

}
int main(int argc, char** argv)
{
    const char* board_name = mraa_get_platform_name();
    int i2c_bus, i, i2c_adapter;
    fprintf(stdout, "hello mraa\n Version: %s\n Running on %s\n", 
mraa_get_version(), board_name);
    mraa_deinit();
    return MRAA_SUCCESS;
}
示例#6
0
int
main(int argc, char** argv)
{
    mraa_uart_context uart;
    uart = mraa_uart_init(0);

    if (uart == NULL) {
        fprintf(stdout, "UART failed to setup\n");
    }

    mraa_deinit();
    return 0;
}
示例#7
0
文件: main.cpp 项目: Slin/Chloe
int main()
{
	signal(SIGINT, sigkill);
	signal(SIGQUIT, sigkill);
	signal(SIGTERM, sigkill);

	CL::Display display;
	_display = &display;

	displayText("Calibra...\nDON'T MOVE", display);
	CL::Sensors sensors;
//	sensors.Calibrate(20.0f);

	CL::Network network;

	displayText("Waiting", display);
	while(!network.GetIsStarted())
	{
		network.Update();
		usleep(1000);
	}

	CL::Motors motors;
	CL::Controller controller;

	_motors = &motors;

	displayText("Active", display);
	while(network.GetIsStarted() && network.GetIsConnected())
	{
		network.Update();
		sensors.Update();
		controller.Update(sensors.orientation, CL::Quaternion(network.GetTargetOrientation()), network.GetUpSpeed());
		network.SendOrientation(sensors.orientation.GetEulerAngle());

		motors.SetSpeed(CL::Motors::Motor::FrontLeft, controller.GetSpeed(CL::Motors::Motor::FrontLeft));
		motors.SetSpeed(CL::Motors::Motor::FrontRight, controller.GetSpeed(CL::Motors::Motor::FrontRight));
		motors.SetSpeed(CL::Motors::Motor::BackLeft, controller.GetSpeed(CL::Motors::Motor::BackLeft));
		motors.SetSpeed(CL::Motors::Motor::BackRight, controller.GetSpeed(CL::Motors::Motor::BackRight));
	}

	motors.SetSpeed(CL::Motors::Motor::FrontLeft, 0.0f);
	motors.SetSpeed(CL::Motors::Motor::FrontRight, 0.0f);
	motors.SetSpeed(CL::Motors::Motor::BackLeft, 0.0f);
	motors.SetSpeed(CL::Motors::Motor::BackRight, 0.0f);

	display.Clear();
	mraa_deinit();

	return MRAA_SUCCESS;
}
示例#8
0
文件: main.cpp 项目: Slin/Chloe
void sigkill(int signum)
{
	if(_motors)
	{
		_motors->SetSpeed(CL::Motors::Motor::FrontLeft, 0.0f);
		_motors->SetSpeed(CL::Motors::Motor::FrontRight, 0.0f);
		_motors->SetSpeed(CL::Motors::Motor::BackLeft, 0.0f);
		_motors->SetSpeed(CL::Motors::Motor::BackRight, 0.0f);
	}

	if(_display)
	{
		_display->Clear();
	}

	mraa_deinit();

	exit(0);
}
示例#9
0
int main(int argc, char *argv[])
{
    mraa_init();

    fprintf(stdout, "Hello mraa.\nVersion: %s\n", mraa_get_version());

    // LED
    out = mraa_gpio_init(20);
    if(out == NULL){
        printf("Error: init out.\r\n");
        return 1;
    }
    mraa_gpio_dir(out, MRAA_GPIO_OUT);

    // Switch
    mraa_gpio_context in = mraa_gpio_init(14);
    if(in == NULL){
        printf("Error: init in.\r\n");
        return 1;
    }
    mraa_gpio_dir(in, MRAA_GPIO_IN);
    mraa_gpio_mode(in, MRAA_GPIO_PULLUP);

    // 割込関数の登録
    mraa_gpio_isr(in, MRAA_GPIO_EDGE_BOTH, interrupt_in, (void *)in);

    while(1) {}




    mraa_gpio_isr_exit(in);
    mraa_gpio_close(in);
    mraa_gpio_close(out);

    mraa_deinit();

    return 0;
}
示例#10
0
文件: main.c 项目: achilikin/edradio
int	main(UNUSED(int argc), UNUSED(char** argv))
{
	uint32_t tso = rdtsc32();

	stdio_mode(STDIO_MODE_CANON);

	// initialize mraa and software SPI
	mraa_init();
	printf("MRAA paltform %s, version %s\n", mraa_get_platform_name(), mraa_get_version());
	mraa_spi_sw_context spi = sw_spi_init(MRAA_SCK, MRAA_MOSI, MRAA_MISO);
	
	// initialize RFM12BS
	rfm12_t rfm;
	memset(&rfm, 0,  sizeof(rfm));
	rfm12_init_spi(&rfm, spi, MRAA_CS1, MRAA_GP047);
	rfm12_init(&rfm, 0xD4, RFM12_BAND_868, 868.0, RFM12_BPS_9600);
	rfm12_set_mode(&rfm, RFM_MODE_RX);

	printf("started up in %u msec\n", millis(tso));

	// default application configuration
	cfg.flags |= APPF_ECHO_DAN;
	cfg.rfm = &rfm;

	// initialize command line interface
	console_io_t cli;
	memset(&cli, 0,  sizeof(cli));
	cli.prompt = '>';
	cli.data = &cfg;

	stdio_init(&cli, stdio_cmd_handler);
	stdio_mode(STDIO_MODE_RAW);

	dnode_t node;

	while(!cli.stop) {
		cli.interact(&cli, cli_cmd);

		if (rfm12_receive_data(&rfm, &node, sizeof(node), cfg.flags & RFM_RX_DEBUG) == sizeof(node)) {
			rfm12_set_mode(&rfm, RFM_MODE_RX);
			if (node.nid == NODE_TSYNC) {
				tso = rdtsc32();
				ts_unpack(&node);
				cfg.rtc_hour = node.hour;
				cfg.rtc_min = node.min;
				cfg.rtc_sec = node.sec;
			}
			if (cfg.flags & APPF_ECHO_DAN)
				print_node(&cli, &node);
		}

		if (millis(tso) >= 1000) {
			tso = rdtsc32();
			if (++cfg.rtc_sec == 60) {
				cfg.rtc_sec = 0;
				if (++cfg.rtc_min == 60) {
					cfg.rtc_min = 0;
					if (++cfg.rtc_hour == 24)
						cfg.rtc_hour = 0;
				}
			}
		}
		usleep(1); // be nice 
	}

	stdio_mode(STDIO_MODE_CANON);
	rfm12_close_spi(&rfm);
	sw_spi_close(spi);
	mraa_deinit();
}
示例#11
0
int main()
{
    int sampleCount = 0;
    int sampleRate = 0;
    uint64_t rateTimer;
    uint64_t displayTimer;
    uint64_t now;

    //  Using RTIMULib here allows it to use the .ini file generated by RTIMULibDemo.
    //  Or, you can create the .ini in some other directory by using:
    //      RTIMUSettings *settings = new RTIMUSettings("<directory path>", "RTIMULib");
    //  where <directory path> is the path to where the .ini file is to be loaded/saved

    RTIMUSettings *settings = new RTIMUSettings("RTIMULib");

    RTIMU *imu = RTIMU::createIMU(settings);

    if ((imu == NULL) || (imu->IMUType() == RTIMU_TYPE_NULL)) {
        printf("No IMU found\n");
        exit(1);
    }

    //  This is an opportunity to manually override any settings before the call IMUInit

    //  set up IMU

    imu->IMUInit();

    //  this is a convenient place to change fusion parameters

    imu->setSlerpPower(0.02);
    imu->setGyroEnable(true);
    imu->setAccelEnable(true);
    imu->setCompassEnable(true);


    // Set up serial out UART ports
    mraa_uart_context uart;
    //uart = mraa_uart_init(0);
    uart=mraa_uart_init_raw("/dev/ttyGS0");
	mraa_uart_set_baudrate(uart, 9600);
	if (uart == NULL) {
		fprintf(stderr, "UART failed to setup\n");
		return 0;
	}
	char buffer[20]={}; // To hold output



    while (1) {

        while (imu->IMURead()) {
            RTIMU_DATA imuData = imu->getIMUData();

            	//sleep(1);
                printf("%s\r", RTMath::displayDegrees("Gyro", imuData.fusionPose) );
                //printf("\nx %f ",imuData.gyro.x()*(180.0/3.14));
                //printf("\ny %f ",imuData.gyro.y()*(180.0/3.14));
                //printf("\nz %f\n",imuData.gyro.z()*(180.0/3.14));

                sprintf(buffer,"%4f\n",imuData.fusionPose.x()*(180.0/3.14));
                mraa_uart_write(uart, buffer, sizeof(buffer));

                printf("\n\n");
                //imuData.
                fflush(stdout);
                //displayTimer = now;



        }

    }
    mraa_uart_stop(uart);
  	mraa_deinit();
}
示例#12
0
文件: spi.c 项目: KurtE/mraa
int
main(int argc, char** argv)
{
    mraa_result_t status = MRAA_SUCCESS;
    mraa_spi_context spi;
    int i, j;

    /* initialize mraa for the platform (not needed most of the times) */
    mraa_init();

    //! [Interesting]
    /* initialize SPI bus */
    spi = mraa_spi_init(SPI_BUS);
    if (spi == NULL) {
        fprintf(stderr, "Failed to initialize SPI\n");
        mraa_deinit();
        return EXIT_FAILURE;
    }

    /* set SPI frequency */
    status = mraa_spi_frequency(spi, SPI_FREQ);
    if (status != MRAA_SUCCESS)
        goto err_exit;

    /* set big endian mode */
    status = mraa_spi_lsbmode(spi, 0);
    if (status != MRAA_SUCCESS) {
        goto err_exit;
    }

    /* MAX7219/21 chip needs the data in word size */
    status = mraa_spi_bit_per_word(spi, 16);
    if (status != MRAA_SUCCESS) {
        fprintf(stdout, "Failed to set SPI Device to 16Bit mode\n");
        goto err_exit;
    }

    /* do not decode bits */
    mraa_spi_write_word(spi, 0x0900);

    /* brightness of LEDs */
    mraa_spi_write_word(spi, 0x0a05);

    /* show all scan lines */
    mraa_spi_write_word(spi, 0x0b07);

    /* set display on */
    mraa_spi_write_word(spi, 0x0c01);

    /* testmode off */
    mraa_spi_write_word(spi, 0x0f00);

    while (flag) {
        /* set display pattern */
        mraa_spi_write_buf_word(spi, pat, 16);

        sleep(2);

        /* set inverted display pattern */
        mraa_spi_write_buf_word(spi, pat_inv, 16);

        sleep(2);

        /* clear the LED's */
        mraa_spi_write_buf_word(spi, pat_clear, 16);

        /* cycle through all LED's */
        for (i = 1; i <= 8; i++) {
            for (j = 0; j < 8; j++) {
                mraa_spi_write_word(spi, (i << 8) + (1 << j));
                sleep(1);
            }
            mraa_spi_write_word(spi, i << 8);
        }
    }

    /* stop spi */
    mraa_spi_stop(spi);

    //! [Interesting]
    /* deinitialize mraa for the platform (not needed most of the times) */
    mraa_deinit();

    return EXIT_SUCCESS;

err_exit:
    mraa_result_print(status);

    /* stop spi */
    mraa_spi_stop(spi);

    /* deinitialize mraa for the platform (not needed most of the times) */
    mraa_deinit();

    return EXIT_FAILURE;
}
示例#13
0
// Finally done, exiting
void closeMRAA( void ) {

	mraa_deinit();
}
示例#14
0
文件: uart.c 项目: byyangyang/drone
void serial_close(void){
mraa_uart_stop(uart);
mraa_deinit();}