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

        • 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
    • This reply was deleted.
      • Hi Ben,

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

    • Hi,

      Where is sonar_alt defined?

      • ArduCopter.pde line 571 (current master):

        static int16_t sonar_alt;

        I chose sonar_alt as sonar is not so commonly used. Obviously if you attempted to use this code  with SONAR_ENABLE=1 then there would be problems. I think a better approach would be to declare a separate variable and then substitute this in the send_rangefinder() mavlink function. This would ensure that no other code was relying  on sonar_alt being any particular value when  SONAR_ENABLE=0.

        • Hi James, 

          Firstly, I must say that this simple example is so helpful. I would greatly appreciate if you could answer a couple of my questions. 

          1. I understand your GCS_Mavlink.pde code, however could you explain what your UserCode.pde does?

          2. Noob question, How do you make these changes in the code? (Where can these files be accessed?) 

          3. What baud rare is the bata being sent back and recorder? can it be changed?

          Thank you in advance :)

          - Rai Gohalwar

          • Hi Raibrinder, I am glad that you find this helpful. 

            1. UserCode.pde is a a place set aside in the Ardupilot code for users to add their code to extend functionality. To enable this you have to uncomment the calls to both the init code and loop code in APM_config.h. In this example in the init code I simply declare an instance of AnalogSource named test_adc setup to look at pin 13. The loop code is called at 10Hz by the system and here I read the voltage on pin 13 and assign it to sonar_alt. 

            2. See http://dev.ardupilot.com/

            3. The data is transmitted via Mavlink and you can view it live at approx 2hz by default. You can alter the rate at which this data is requested by MP in the 'Planner' config under 'Config/Tuning'. Obviously you need to be mindful of the total bandwidth available. 50Hz is the max telemetry rate and this will be fine while connected via USB at 1.5Mbps but at the much lower rate used by the radios, would prove problematic. In this example to make things simple, I have overridden the use of the sonar_alt variable so it also gets written to the dataflash log in the CTUN entry at 10Hz. If you follow the first example in this thread, you will see how to create your own custom dataflash log entry which will allow you to log at up to 100Hz (using userhook_FastLoop)

            You are welcome :)

            • This reply was deleted.
              • Hi Evan, Unfortunately I have not worked with Arduplane at all. UserCode.pde can just be created in the ArduPlane directory however it seems that the userhook loop functions are not used in Plane. You would have to add userhook_MediumLoop() to the scheduler in ArduPlane.pde (or simply call from another task scheduled at 10Hz like update_logging1(). It also seems that unless you wanted to recreate the entire userhook setup in Plane, you will have to put your USERHOOK_VARIABLES in ArduPlane.pde and USERHOOK_INIT code in the init_ardupilot() function in system.pde.

                If you think this might be useful I could put together an example for you

This reply was deleted.

Activity

Jose Araujo liked Jose Araujo's profile
Aug 29
spencer harvey liked spencer harvey's profile
Jul 9
More…