Hi All,

I'm trying to add an external board to the APM 2.5+ system using the expansion analog pins. The board communicates to the APM via one input voltage and one output voltage, both analog values.

I've had the setup working with the ArduPlane 2.68 code, but I've just recently migrated my code changes to the ArduPlane 2.72 code. With that change, I've needed to use the customized ardupilot-arduino-1.0.3 to compile and upload the code. However, now my code changes don't compile anymore. The errors I get are:

Building for ArduPilot Mega 2.x
Excluding arduino core from include paths
system.pde: In function 'void check_terminate()':
system:690: error: 'analogRead' was not declared in this scope
system:700: error: 'analogWrite' was not declared in this scope

I've added the function "check_terminate()" For some reason analogRead and analogWrite are now preventing the code from compiling.

The portion of the code is below:

static void check_terminate()
{
    terminate_pin = analogRead(60); // read value from analog pin (pin 60 = A6)
    terminate_volts = terminate_pin*(5.0/1023.0); // convert to voltage
    
    // manual terminate
    if (terminate_volts < 1 && terminate_volts >= -1)    // terminate activated
    {
        terminate_count++;
        if (terminate_count > terminate_threshold){
            TERMINATE = true;
            digitalWrite(A_LED_PIN, LED_ON);
            analogWrite(61, 1023); // confirm terminate (pin 61 = A7)]
            set_mode(CIRCLE);
            if (!terminate_debug){
                //Serial.printf_P(PSTR("MANUAL TERMINATE"));
                gcs_send_text_P(SEVERITY_HIGH,PSTR("MANUAL TERMINATE"));
                terminate_debug = true;
            }
        }
    } else          // if terminate not active
    {
        terminate_count = 0;
        digitalWrite(A_LED_PIN, LED_OFF);
        analogWrite(61, 0); // confirm terminate (pin 61 = A7)
    }
   

Any ideas/help would be awesome.

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Hi,

    The analog port interface has changed since the HAL was introduced.

    I'd suggest you find the code to read the battery voltage or current, and trace that back. You can begin the reverse search in GCS_Mavlink, where the values must be mentioned (since that code send them to the ground station).

    Please note that some time ago, ADC input in APM was made relative to a measurement of an internal voltage reference. This makes logging of brownouts possible (before, the reference voltage was the very same one that browned out, so nothing was seen) but noise and precision performance went downhill. There is still some way to get the old-style conversion where the 5V supply is the reference, but I don't have the details right here.

    It is not true that analog input is no longer possible.

    There never was any analog output, however you can see if you can find a timer that is not used for PWM servo/motor output, and use the PWM features of that. You will wanna make it run somewhat faster than the default 50/400Hz. After a little low pass filtering, a PWM value is analog.

    Regards

    Soren

  • Hey,

    Thanks Philippe. However this solution is to analogread. If i want to write in the analog? What is the solution?

  • Hey,

    I think (and anybody is more then welcome to correct me if I am wrong) that this problem stems from the fact that the software now also supports Px4 Autopilot. Therefore the functions analogWrite and analogRead are not supported anymore.

    I copied the code for read-in for the other analog sensors:

    First setup the sensor: (in my case this code will read an analog sensor for determining the MotorTemperatur)

    static AP_HAL::AnalogSource *MotTemp_pin;        //Setup

    Now in void setup(), setting the input pin (number 7 in my case)

    MotTemp_pin    = hal.analogin->channel(7);

    and finally you can readout the voltage:

    float MotorTemperature = MotTemp_pin->voltage_average();

    So this is my guess how this works. However I could be wrong as I did not test this...

    Good Luck

    Phil

This reply was deleted.

Activity