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
May 15
DIY Robocars via Twitter
May 14
DIY Robocars via Twitter
May 13
DIY Robocars via Twitter
RT @f1tenth: Say hi to our newest #F1TENTH creation for @ieee_ras_icra next week in Philly. It’s going to be huge! 😎 🔥 @AutowareFdn @PennEn…
May 13
DIY Robocars via Twitter
May 11
DIY Robocars via Twitter
May 8
DIY Robocars via Twitter
RT @SmallpixelCar: Noticed my car zigzagged in last run. It turned out to be the grass stuck in the wheel and made the odometry less accura…
May 8
DIY Robocars via Twitter
RT @SmallpixelCar: Test my car. RTK GPS worked great. Thanks @emlid for their support. https://t.co/EkQ6qmjmWR
May 8
DIY Drones via Twitter
RT @chr1sa: @kane That's @diydrones circa 2009. Still have a box of those Canon cameras that we used to strap into planes, just like this.…
May 3
DIY Robocars via Twitter
RT @chr1sa: Our next @diyrobocars race is going to be outside at a real RC racetrack in Fremont on May 28. Fully autonomous racing, head-to…
Apr 30
DIY Robocars via Twitter
RT @f1tenth: Our Spring 2022 F1TENTH course @PennEngineers is coming to an end with a head-to-head race as a big finale. So proud of our st…
Apr 26
DIY Robocars via Twitter
RT @DanielChiaJH: I wrote a thing! Throughout the development of my @diyrobocars car I've been using @foxglovedev Studio to visualize and d…
Apr 23
DIY Robocars via Twitter
RT @SmallpixelCar: My new car for high speed. Low body, everything ( @NVIDIAEmbedded Jetson Xavier NX, @emlid RTK GPS, IMC) under the deck…
Apr 23
DIY Robocars via Twitter
Apr 21
DIY Robocars via Twitter
RT @f1tenth: F1TENTH Race training setup @PennEngineers for our upcoming ICRA2022 @ieee_ras_icra competition. @OpenRoboticsOrg @IndyAChalle…
Apr 21
DIY Robocars via Twitter
RT @fatcatFABLAB: Proud to be hosting a restarted DIY Robocars NYC Meetup April 26. Come by if you want to talk about and race self-driving…
Apr 17
More…