Ardupilot Libraries Sample code HAL

Hello everyone,

I am trying to write a main code that calls the RC and GPS sample codes from AP libraries. However, I am only able to print on the Serial Monitor one of them at a time. Can someone give any ideas how I can merge the classes and methods in one main code that, when compiled, will give me both results in one window without the other one crashing.

Thanks

I am trying to write a main code that calls the RC and GPS sample codes from AP libraries.

Links to the libraries? Where is your code?

However, I am only able to print on the Serial Monitor one of them at a time.

Why?

Can someone give any ideas how I can merge the classes and methods in one main code that, when compiled, will give me both results in one window without the other one crashing.

Sure. Write good code. We'll be happy to review it, and point out potential issues. What Arduino are you using? How are you reading from two devices at the same time?

#include <stdio.h>
#include <AP_RCMapper.h>

#include <AP_Common.h>
#include <AP_Param.h>
#include <AP_Progmem.h>
#include <AP_Math.h>

#include <AP_HAL.h>
#include <AP_GPS.h>
#include <AP_HAL_AVR.h>
#include <AP_HAL_AVR_SITL.h>
#include <AP_HAL_Empty.h>

#define TIMESTAMP 0
#define INPUT_CH 1
#define STATE_LEN 37

#define DISPLAY_INPUTS //uncomment to print input from transmitter to console

//boolean loggingIsOn = false;
double state[STATE_LEN];
uint16_t channels[8];
//const AP_HAL::HAL& hal = AP_HAL_BOARD_DRIVER;

#if CONFIG_HAL_BOARD == HAL_BOARD_APM2
const AP_HAL::HAL& hal = AP_HAL_AVR_APM2;
#elif CONFIG_HAL_BOARD == HAL_BOARD_APM1
const AP_HAL::HAL& hal = AP_HAL_AVR_APM1;
#endif

void schedule_toggle_1(uint32_t machtnichts) {
loopServo();
}

void schedule_toggle_2(uint32_t machtnichts) {
loopGPS();
}

void setup()
{
setupServo();
setupGPS();

//hal.scheduler->register_timer_process(schedule_toggle_1);
//hal.scheduler->register_timer_process(schedule_toggle_2);
}

void loop()
{
#ifdef DISPLAY_INPUTS
loopServo();
loopGPS();
//loopSonar();
#endif

}

AP_HAL_MAIN();

This is the main code that calls the Sample Codes in the APM library for GPS and RC. The reason why we can't print is because somehow when you call the loopServo () and loopGPS () in the same time, it chooses to run only one and it prints only the values for one.

You need to post links to the libraries you are using. Where are loopServo() and loopGPS() defined? I wonder if the names provide a clue.