Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 55:fbd59767e175
- Parent:
- 53:50ecf1240eba
- Child:
- 57:6c87f4989616
--- a/main.cpp Fri Jun 03 14:35:01 2022 +0200
+++ b/main.cpp Fri Jun 03 16:52:19 2022 +0200
@@ -19,7 +19,7 @@
int main()
{
// while loop gets executed every main_task_period_ms milliseconds
- const int main_task_period_ms = 50; // define main task period time in ms e.g. 50 ms -> main task runns 20 times per second
+ const int main_task_period_ms = 40; // define main task period time in ms e.g. 50 ms -> main task runns 20 times per second
Timer main_task_timer; // create Timer object which we use to run the main task every main task period time in ms
// led on nucleo board
@@ -36,9 +36,7 @@
// create object for GNSS Sensor NEO-M9N
NEOM9N neom9n(PA_9, PA_10); // UART1
- //NEOM9N neom9n(PA_2, PA_3); // UART2
- //Timer neom9n_timer;
-
+
// attach button fall and rise functions to user button object
user_button.fall(&user_button_pressed_fcn);
user_button.rise(&user_button_released_fcn);
@@ -46,20 +44,18 @@
// start timer
main_task_timer.start();
- //neom9n_timer.start();
-
while (true) { // this loop will run forever
main_task_timer.reset();
+ // update magnetometer
mag.readMag(); // this needs approx 2450 mus
- mag_val[0] = raw_mx2mx.evaluate(mag.magX());
- mag_val[1] = raw_my2my.evaluate(mag.magY());
- mag_val[2] = raw_mz2mz.evaluate(mag.magZ());
+ mag_val[0] = raw_mx2mx.evaluate( mag.magX() );
+ mag_val[1] = raw_my2my.evaluate( mag.magY() );
+ mag_val[2] = raw_mz2mz.evaluate( mag.magZ() );
- //neom9n_timer.reset();
+ // update GNSS
neom9n.update();
- //int neom9n_elapsed_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(neom9n_timer.elapsed_time()).count();
if (do_execute_main_task) {
@@ -69,11 +65,33 @@
user_led = !user_led;
- int main_task_elapsed_time_mus = std::chrono::duration_cast<std::chrono::microseconds>(main_task_timer.elapsed_time()).count();
+ //int main_task_elapsed_time_mus = std::chrono::duration_cast<std::chrono::microseconds>(main_task_timer.elapsed_time()).count();
// do only output via serial what's really necessary (this makes your code slow)
- printf("%f, %f, %f\r\n", mag_val[0], mag_val[1], mag_val[2]);
- printf("Update time: %d, GPS time: %d, num sat: %d, lat: %d, lon: %d, speed: %d, heading: %d\r\n", main_task_elapsed_time_mus, neom9n.actualPVT.itow, neom9n.actualPVT.numSV, neom9n.actualPVT.lat, neom9n.actualPVT.lon, neom9n.actualPVT.speed, neom9n.actualPVT.headMot);
+ printf("%0.3f, %0.3f, %0.3f, ", // 1: 3 : scaled with 10.0f
+ mag_val[0] * 10.0f,
+ mag_val[1] * 10.0f,
+ mag_val[2] * 10.0f);
+ printf("%0.3f, %0.3f, %0.3f, ", // 4: 6 : scaled with 10.0f
+ neom9n.getVelN() * 10.0f,
+ neom9n.getVelE() * 10.0f,
+ neom9n.getVelD() * 10.0f);
+ printf("%0.3f, %0.3f, %0.3f, %0.3f, ", // 7:10 : scaled with 10.0f
+ neom9n.getGroundSpeed() * 10.0f,
+ neom9n.getSpeedAcc() * 10.0f,
+ neom9n.getHeading() * 10.0f,
+ neom9n.getHeadAcc() * 10.0f);
+ printf("%0.6f, %0.6f, %0.3f, %0.3f, ", // 11:14 : scaled with 10.0f
+ neom9n.getLon() * 10.0f,
+ neom9n.getLat() * 10.0f,
+ neom9n.getHeight() * 10.0f,
+ neom9n.getHeightMSL() * 10.0f);
+ printf("%0.3f, %d", // 15:16 : no scaling
+ neom9n.getSatTime(),
+ neom9n.getNumSat());
+
+ printf("\r\n");
+ //printf("Update time: %d\r\n", main_task_elapsed_time_mus);
// read timer and make the main thread sleep for the remaining time span (non blocking)
int main_task_elapsed_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(main_task_timer.elapsed_time()).count();