Exemple #1
0
static int lgps_pos(lua_State* L) {
    struct position pos;
    
    int timeout = luaL_optinteger(L, 1, 0xffffffff);
    
    // Read position
    if (gps_get_pos(&pos, timeout)) {
        // No position available
        lua_pushnil(L);
        return 1;
    }
    
    lua_pushnumber(L, pos.lat);
    lua_pushnumber(L, pos.lon);
    lua_pushinteger(L, pos.sats);
    lua_pushinteger(L, pos.when);

    return 4;
}
void application_mainloop(application_t *app)
{
    DEBUG("application_mainloop()");
    assert(app != 0);

    void *data;
    size_t length;
    float att[3], alt, spd, trk, brg, dst;
    char wpt[32];

    float accsum[3];
    float difftime;

    while(1)
    {
        // Process video
        if(!video_read(app->video, &data, &length))
        {
            ERROR("Cannot read from video device");
            break;
        }
        graphics_image_set_bitmap(app->image, data, length);
        graphics_draw(app->graphics, app->image, app->window_width / 2, app->window_height / 2,
                      (float)app->window_width / (float)app->window_height < (float)app->video_width / (float)app->video_height ?
                      (float)app->window_height / (float)app->video_height : (float)app->window_width / (float)app->video_width, 0);

        imu_get_attitude(app->imu, att);
        gps_get_pos(app->gps, NULL, NULL, &alt);

        imu_get_acceleration(app->imu, accsum, &difftime);
        gps_inertial_update(app->gps, accsum[0], accsum[1], accsum[2], difftime);

        // Draw landmarks
        void *iterator;
        float hangle, vangle, dist;
        drawable_t *label = gps_get_projection_label(app->gps, &hangle, &vangle, &dist, att, &iterator);
        while(iterator)
        {
            if((hangle > app->video_hfov / -2.0) &&
               (hangle < app->video_hfov / 2.0)  &&
               (vangle > app->video_vfov / -2.0) &&
               (vangle < app->video_vfov / 2.0)  &&
               (dist < app->visible_distance))
            {
                INFO("Projecting landmark hangle = %f, vangle = %f, distance = %f", hangle, vangle, dist / 1000.0);
                uint32_t x = (float)app->window_width  / 2 + (float)app->window_width  * hangle / app->video_hfov;
                uint32_t y = (float)app->window_height / 2 + (float)app->window_height * vangle / app->video_vfov;
                graphics_draw(app->graphics, label, x, y, 1, 0);
            }
            label = gps_get_projection_label(app->gps, &hangle, &vangle, &dist, att, &iterator);
        }

        // Draw HUD overlay
        gps_get_track(app->gps, &spd, &trk);
        gps_get_route(app->gps, wpt, &dst, &brg);
        graphics_hud_draw(app->hud, att, spd, alt, trk, brg, dst, wpt);

        // Render to screen
        if(!graphics_flush(app->graphics, NULL))
        {
            ERROR("Cannot draw");
            break;
        }
    }
}
Exemple #3
0
int main(void)
{
	uint32_t count = 0;
	int32_t lat, lon, alt, temp;
	uint8_t hour, minute, second;
	uint16_t mv;
	char msg[100];
	uint8_t i, r;
	
	/* Set the LED pin for output */
	DDRB |= _BV(DDB7);
	
	adc_init();
	rtx_init();
	gps_setup();	
	
	/* Enable the radio and let it settle */
	rtx_enable(1);
	_delay_ms(1000);
	
	sei();
	
	rtx_string_P(PSTR(RTTY_CALLSIGN " starting up\n"));	
	rtx_string_P(PSTR("Scanning 1-wire bus:\n"));
	
	for(i = 0; i < 3; i++)
	{
		r = ds_search_rom(id[i], i);
		
		if(r == DS_OK || r == DS_MORE)
		{
			rtx_wait();
			snprintf(msg, 100, "%i> %02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
				i,
				id[i][0], id[i][1], id[i][2], id[i][3],
				id[i][4], id[i][5], id[i][6], id[i][7]);
			rtx_string(msg);
		}
		else
		{
			rtx_wait();
			snprintf(msg, 100, "%i> Error %i\n", i, r);
			rtx_string(msg);
		}
		
		if(r != DS_MORE) break;
	}
	rtx_string_P(PSTR("Done\n"));
	
	while(1)
	{
		if(!gps_get_pos(&lat, &lon, &alt))
		{
			rtx_string_P(PSTR("$$" RTTY_CALLSIGN ",No or invalid GPS response\n"));
			continue;
		}
		
		if(!gps_get_time(&hour, &minute, &second))
		{
			rtx_string_P(PSTR("$$" RTTY_CALLSIGN ",No or invalid GPS response\n"));
			continue;
		}



		/* Read the battery voltage */
		mv = adc_read();

		/* Read the temperature from sensor 0 */
		ds_read_temperature(&temp, id[0]);
		
		rtx_wait();
		
		snprintf(msg, 100, "$$%s,%li,%02i:%02i:%02i,%s%li.%05li,%s%li.%05li,%li,%i.%02i,%li.%01li,%c",
			RTTY_CALLSIGN, count++,
			hour, minute, second,
			(lat < 0 ? "-" : ""), labs(lat) / 10000000, labs(lat) % 10000000 / 100,
			(lon < 0 ? "-" : ""), labs(lon) / 10000000, labs(lon) % 10000000 / 100,
			alt / 1000,
			mv / 1000, mv / 10 % 100,
			temp / 10000, labs(temp) / 1000 % 10,
			(geofence_uk(lat, lon) ? '1' : '0'));
		crccat(msg + 2);
		rtx_string(msg);
	}
}
Exemple #4
0
int main(void)
{
	uint32_t count = 0;
	int32_t lat, lon, alt, temp1, temp2, pressure;
	uint8_t hour, minute, second;
	uint16_t mv;
	char msg[100];
	uint8_t i, r;
	bmp085_t bmp;
	
	/* Set the LED pin for output */
	DDRB |= _BV(DDB7);
	
	adc_init();
	rtx_init();
	bmp085_init(&bmp);
	
#ifdef APRS_ENABLED
	ax25_init();
#endif

#ifdef SSDV_ENABLED
	c3_init();
#endif
	
	sei();
	
	gps_setup();
	
	/* Enable the radio and let it settle */
	rtx_enable(1);
	_delay_ms(1000);
	
	rtx_string_P(PSTR(RTTY_CALLSIGN " starting up\n"));
	
	/* Scan the 1-wire bus, up to 16 devices */
	rtx_string_P(PSTR("Scanning 1-wire bus:\n"));
	for(i = 0; i < 16; i++)
	{
		r = ds_search_rom(id[i], i);
		
		if(r == DS_OK || r == DS_MORE)
		{
			/* A device was found, display the address */
			rtx_wait();
			snprintf_P(msg, 100, PSTR("%i> %02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n"),
				i,
				id[i][0], id[i][1], id[i][2], id[i][3],
				id[i][4], id[i][5], id[i][6], id[i][7]);
				rtx_string(msg);
		}
		else
		{
			/* Device not responding or no devices found */
			rtx_wait();
			snprintf_P(msg, 100, PSTR("%i> Error %i\n"), i, r);
			rtx_string(msg);
		}
		
		/* No more devices? */
		if(r != DS_MORE) break;
	}
	rtx_string_P(PSTR("Done\n"));
	
	while(1)
	{
		/* Set the GPS navmode every 10 strings */
		if(count % 10 == 0)
		{
			/* Mode 6 is "Airborne with <1g Acceleration" */
			if(gps_set_nav(6) != GPS_OK)
			{
				rtx_string_P(PSTR("$$" RTTY_CALLSIGN ",Error setting GPS navmode\n"));
			}
		}
		
		/* Get the latitude and longitude */
		if(gps_get_pos(&lat, &lon, &alt) != GPS_OK)
		{
			rtx_string_P(PSTR("$$" RTTY_CALLSIGN ",No or invalid GPS response\n"));
			lat = lon = alt = 0;
		}
		
		/* Get the GPS time */
		if(gps_get_time(&hour, &minute, &second) != GPS_OK)
		{
			rtx_string_P(PSTR("$$" RTTY_CALLSIGN ",No or invalid GPS response\n"));
			hour = minute = second = 0;
		}
		
		/* Read the battery voltage */
		mv = adc_read();
		
		/* Read the temperature from sensor 0 */
		ds_read_temperature(&temp1, id[0]);
		
		/* Read the temperature from sensor 1 */
		ds_read_temperature(&temp2, id[1]);
		
		/* Read the pressure from the BMP085 */
		if(bmp085_sample(&bmp, 3) != BMP_OK) pressure = 0;
		else pressure = bmp085_calc_pressure(&bmp);
		
		/* Build up the string */
		rtx_wait();
		
		snprintf_P(msg, 100, PSTR("$$%s,%li,%02i:%02i:%02i,%s%li.%04li,%s%li.%04li,%li,%i.%01i,%li,%li,%li,%c"),
			RTTY_CALLSIGN, count++,
			hour, minute, second,
			(lat < 0 ? "-" : ""), labs(lat) / 10000000, labs(lat) % 10000000 / 1000,
			(lon < 0 ? "-" : ""), labs(lon) / 10000000, labs(lon) % 10000000 / 1000,
			alt / 1000,
			mv / 1000, mv / 100 % 10,
			temp1 / 10000,
			temp2 / 10000,
			pressure,
			(geofence_test(lat, lon) ? '1' : '0'));
		crccat(msg);
		rtx_string(msg);
		
#ifdef APRS_ENABLED
		tx_aprs(lat, lon, alt);
		{ int i; for(i = 0; i < 60; i++) _delay_ms(1000); }
#endif

#ifdef SSDV_ENABLED
		if(tx_image() == -1)
		{
			/* The camera goes to sleep while transmitting telemetry,
			 * sync'ing here seems to prevent it. */
			c3_sync();
		}
#endif
	}
}