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
Sep 9
DIY Robocars via Twitter
RT @chr1sa: We've got another virtual @DIYRobocars race tomorrow at 9:00am PT. Two dozen autonomous cars will compete, four at a time. Ther…
Sep 4
DIY Robocars via Twitter
Sep 1
DIY Robocars via Twitter
Aug 31
DIY Robocars via Twitter
Aug 31
sam liked Jimmy Oliver's profile
Aug 25
DIY Robocars via Twitter
RT @ExplorerRobocar: Sometimes, I am really a big kid!! Having fun with my virtual RC car on the @diyrobocars track 😜😉, by using the « AR R…
Aug 24
DIY Robocars via Twitter
RT @grepLeigh: @donkey_car @unity3d @TensorFlow ~1050 episodes into training, my agent learned to erratically drive in the left lane. 🤖😆 ht…
Aug 24
DIY Robocars via Twitter
RT @EclipseCyclone: Sweet! http://Robotec.ai high performance #ROS 2 @unity3d #CycloneDDS bridge for @AutowareFdn @SVLSimulator now…
Aug 24
DIY Robocars via Twitter
RT @a1k0n: My car had a lot of trouble getting around the track at the last @diyrobocars event -- only one actual finished lap during the r…
Aug 24
DIY Robocars via Twitter
RT @SmallpixelCar: This is the run time map https://t.co/VzykOkUt2G
Aug 24
DIY Robocars via Twitter
RT @SmallpixelCar: Made a lot progress on Warm Spring Raceways track. Almost finished one lap. https://t.co/nUVpufZQyP
Aug 24
DIY Robocars via Twitter
RT @AntonioRobotics: Super fun time seeing these autonomous cars race at @circuitlaunch for the @diyrobocars quarterly meet up! The demolit…
Aug 15
DIY Robocars via Twitter
RT @a1k0n: I thought my dumb localization code was still working at the new @circuitlaunch track, but it was just *barely* working. I shoul…
Aug 14
DIY Robocars via Twitter
RT @DAVGtech: Recording of entire in person @diyrobocars race today @circuitlaunch. Fast forward a couple hours to go straight to the racin…
Aug 14
DIY Robocars via Twitter
RT @SmallpixelCar: This is the run time map. Very noisy Lidar signal https://t.co/bAbeVUMi10
Aug 14
More…