Custom sensors and Real-Time logging

Hi everyone,

Does anyone have experience with configuring their own sensors onto the Pixhawk (I have an IRIS)? I purchased a gas sensor that I'd like to wire to it, does anyone know of any good resources to help me get started? I've downloaded the PX4 development environment from the Pixhawk developers website and have gone through some of the "getting started" instructions on there, I have been able to install the firmware through Eclipse as opposed to the Mission Planner. I also purchased 3-position and 5-position connectors for the analog inputs.

I was also wondering if there is a way to view the telemetry log data on Mission Planner during flight? If I did add this sensor, would data be saved through the telemetry logs or dataflash logs?

I appreciate whatever help I can get, thank you!

Kate

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

Join diydrones

Email me when people reply –

Replies

  • I had a bit of a play on the Pixhawk and managed to view live data from the ADC pins (13 in example) via telemetry. I simply read the adc pin and assigned the value to sonar_alt. I also altered the mavlink code to transmit sonar_alt even when it is disabled in the parameters. I could view the value live in MP as sonarrange and it is also available as mavlink_rangefinder_t.distance in the tlog. I note that the same message records the sonarvoltage parameter as well so you could potentially pass two separate readings by overriding this message.

    GCS_Mavlink.pde (starting at line 486 in current master):

    #if CONFIG_SONAR == ENABLED
    static void NOINLINE send_rangefinder(mavlink_channel_t chan)
    {
    // exit immediately if sonar is disabled
    if (!g.sonar_enabled) {
    // return; commented out this line to force message to be sent
    }
    mavlink_msg_rangefinder_send(chan, sonar_alt * 0.01f, 0); // you can scale the parameters as you need. The 3rd param is supposed to be sonar voltage (not used in this code and is 0) and could potentially be another variable
    }
    #endif

    UserCode.pde:

    AP_HAL::AnalogSource *test_adc;

    #ifdef USERHOOK_INIT
    void userhook_init()
    {

    test_adc = hal.analogin->channel(13);

    }
    #endif

    #ifdef USERHOOK_MEDIUMLOOP
    void userhook_MediumLoop()
    {
    // put your 10Hz code here
    sonar_alt=test_adc->voltage_latest();
    }
    #endif

    Don't forget to uncomment USERHOOK_INIT and USERHOOK_MEDIUMLOOP in APM_Config.h

    • James,

      Does the above work? Even though you have commented out the return so that the message gets sent, if Sonar is not enabled, the whole section of code in GCS_Mavlink.pde will not run because of the #if CONFIG_SONAR == ENABLED.

      If you enable sonar, then you will also enable the sonar behaviors. I would have thought that you would have been better off leaving Sonar disabled and modifying the code to be;

       //  #if CONFIG_SONAR == ENABLED
         static void NOINLINE send_rangefinder(mavlink_channel_t chan)
         {
         // exit immediately if sonar is disabled
        // if (!g.sonar_enabled) {
         // return; commented out this line to force message to be sent
        // }
         mavlink_msg_rangefinder_send(chan, sonar_alt * 0.01f, 0);
        }
       // #endif

      • Hi ausdroid, the #if statement is a compiler directive and has no effect on the running code. It determines if the enclosed code is compiled or not. In this case CONFIG_SONAR was used to reduce the size of the executable binary when sonar was not required. 'sonar_enabled' is the parameter that is typically set in MP to dynamically enable/disable sonar.
        • Yep. Copy that. Soooo...it would be enabled by default.

          Thanks.

          J

    • Good stuff James. Q: is this "how to" documented anywhere besides your posts? I've been building and reading the APM code for a few days and had no clue this existed. I would eventually have run across this in the code once I got to these files, but the timing would have been much farther out. Thx! Tim
      • Hi Tim, not that I know of. It is a bit of a 'hack' overriding existing variables that could potentially be in use so it is not really appropriate for any official documentation. I put it out there as the shortest route to achieve the goal of logging from the adc pins. Given the interest I am thinking that there should be options to log at least some analog pins as standard. I might work on this and make an attempt to contribute...
        • Agreed that some documented sanctioned option should exist to access the analog pins outside of your, um, shortcut. In the meantime, your posts on this have been very useful. :-) - Tim
    • Any idea if this could be done on an APM?

      • Hi Ben,

        This code should work fine on the APM - just use the appropriate ADC pin.

        • Thanks, we will give it a try.

This reply was deleted.

Activity

DIY Robocars via Twitter
Sunday
DIY Robocars via Twitter
Saturday
DIY Robocars via Twitter
Saturday
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…
Saturday
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…