Issue with analog input ports on AMP 2.6

I am attempting modify the ardupCopter code and use "analogRead( )" to interpret an external input.  However, when compiling I receive the following error: "analogRead was not declared in this scope."  I tried to include the Arduino.h file in the library (I am under the assumption that Arduino.h contains the instructions for the analogRead function).  Any suggestions on how to include analogRead and other common arduino functions with the arduCopter code?  The following is a brief description of what I am trying to accomplish.  Any suggestion or different approaches are appreciated.

Currently I have a raspberry pi w/ camera module performing some color and shape recognition.  When it detects the desired object, I have the pi output 3.3V at one of its ports.  I am trying to connect this port to one of the analog input ports on the APM 2.6.  The copter will be flying a predetermine route to scan an area for the object.  When the object is detected I am having the high input signal the copter to switch from AUTO to LOITER flight mode.

Any help is greatly appreciated.

-Matt

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

Join diydrones

Email me when people reply –

Replies

  • I had to include an Arduino.h file in order to even get it to compile.  What I can't figure is that the Arduino.h file is empty.  Go figure.

  • Did you figure this out?  Look in Libraries AP_HAL and AP_HAL_AVR then search for board_vcc_analog_source in system.pde.  That should get you started. It's all done in HAL now and I do not fully understand all that for sure.  If you figure it out, let me know with a sample.  I tried this: It compiled but not sure it reads the volts since I could not get to the pins on my APM (in a copter)

    AP_HAL::AnalogSource* testain;
    testain = hal.analogin->channel(0); // read A0 ??
    float testain1 = testain->read_average();
    cliSerial->printf_P(PSTR("Batery volts = %4.4f \n"),testain1);

    HAL sure complicated things for those with only APM.

    Perhaps someone else can chime in.  Example of how to read An  (analog in A0, A1, ,,,)

    • I tested your code...

      AP_HAL::AnalogSource* testain;
      testain = hal.analogin->channel(1); // read A1 pete
      float testain1 = testain->read_average();
      //cliSerial->printf_P(PSTR("Batery volts = %4.4f \n"),testain1);
      gcs_send_text_fmt(PSTR("\n Batery volts = %4.4f \n"),testain1);

      and got this error...

      Initialising APM...

      XError: AP_HAL_AVR::AVRAnalogIn out of channels

      the hal board is sure a pain.

      Pete

      • Hum,  I put that code in the version 3.1.3 (download is marked 3.1.2) in  arduCopter.pde, in setup(), right after init_ardupilot();  and it compiled fine and when upload, then use serial monitor to connect - the message shows up but the value testain1 is always 0.00    You are correct - a pain.  

        well, Matt has a workaround for now

    • I was able to come up with a solution to the problem but it is definitely not a conventional method.  Since A0 is already set up to read the sonar senor if enabled, I enabled the pin and used this code segment:

      int16_t temp_alt = sonar->read();
      if(temp_alt > 200) {
      do_loiter_time();

      I chose 200 (cm) after using the test terminal in MP and seeing that the output was ~31 cm when the RPi was connected to pin A0 outputting a low and ~257 cm when the RPi found the object and was outputting a high (3.3V).

      On a separate note, would you be able in assisting me in compiling and building any version (currently attempting to use v1.2.57) of Mission Planner using Visual Studio.  Once the the copter is loitering over the target I need to extract its GPS location from the tlog file and export it to a file that can be used while the copter is still in flight and connected to MP.  I believe in order to do this I need to modify the source code for MP.  Thanks.

      Matt

      • When I tested this code

        int16_t temp_alt = sonar->read();
        if(temp_alt > 200) {
        do_loiter_time();

        I got this error:

         error: base operand of '->' has non-pointer type 'AP_RangeFinder_analog'

        the hall board kills me again.

This reply was deleted.

Activity

DIY Robocars via Twitter
RT @chr1sa: Just a week to go before our next @DIYRobocars race at @circuitlaunch, complete with famous Brazilian BBQ. It's free, fun for k…
yesterday
DIY Robocars via Twitter
How to use the new @donkey_car graphical UI to edit driving data for better training https://www.youtube.com/watch?v=J5-zHNeNebQ
Nov 28
DIY Robocars via Twitter
RT @SmallpixelCar: Wrote a program to find the light positions at @circuitlaunch. Here is the hypothesis of the light locations updating ba…
Nov 26
DIY Robocars via Twitter
RT @SmallpixelCar: Broke my @HokuyoUsa Lidar today. Luckily the non-cone localization, based on @a1k0n LightSLAM idea, works. It will help…
Nov 25
DIY Robocars via Twitter
@gclue_akira CC @NVIDIAEmbedded
Nov 23
DIY Robocars via Twitter
RT @luxonis: OAK-D PoE Autonomous Vehicle (Courtesy of zonyl in our Discord: https://discord.gg/EPsZHkg9Nx) https://t.co/PNDewvJdrb
Nov 23
DIY Robocars via Twitter
RT @f1tenth: It is getting dark and rainy on the F1TENTH racetrack in the @LGSVLSimulator. Testing out the new flood lights for the racetra…
Nov 23
DIY Robocars via Twitter
RT @JoeSpeeds: Live Now! Alex of @IndyAChallenge winning @TU_Muenchen team talking about their racing strategy and open source @OpenRobotic…
Nov 20
DIY Robocars via Twitter
RT @DAVGtech: Live NOW! Alexander Wischnewski of Indy Autonomous Challenge winning TUM team talking racing @diyrobocars @Heavy02011 @Ottawa…
Nov 20
DIY Robocars via Twitter
Incredible training performance with Donkeycar https://www.youtube.com/watch?v=9yy7ASttw04
Nov 9
DIY Robocars via Twitter
RT @JoeSpeeds: Sat Nov 6 Virtual DonkeyCar (and other cars, too) Race. So bring any car? @diyrobocars @IndyAChallenge https://t.co/nZQTff5…
Oct 31
DIY Robocars via Twitter
RT @JoeSpeeds: @chr1sa awesomely scary to see in person as our $1M robot almost clipped the walls as it spun at 140mph. But it was also awe…
Oct 29
DIY Robocars via Twitter
RT @chr1sa: Hey, @a1k0n's amazing "localize by the ceiling lights" @diyrobocars made @hackaday! It's consistently been the fastest in our…
Oct 25
DIY Robocars via Twitter
RT @IMS: It’s only fitting that @BostonDynamics Spot is waving the green flag for today’s @IndyAChallenge! Watch LIVE 👉 https://t.co/NtKnO…
Oct 23
DIY Robocars via Twitter
RT @IndyAChallenge: Congratulations to @TU_Muenchen the winners of the historic @IndyAChallenge and $1M. The first autonomous racecar comp…
Oct 23
DIY Robocars via Twitter
RT @JoeSpeeds: 🏎@TU_Muenchen #ROS 2 @EclipseCyclone #DDS #Zenoh 137mph. Saturday 10am EDT @IndyAChallenge @Twitch http://indyautonomouschallenge.com/stream
Oct 23
More…