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

    • 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 :)

            • James, 

              I don't know if you have spent much time looking at ArduPlane, but there is no UserCode.pde for ArduPlane.  Is there somewhere else that ArduPlane users should put that code?  

              Thanks!

              • 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

            • Hi James, 

              I have finally managed to make the changes to the arducopter files and have the necessary tools to build the firmware. However, I didn't understand what you meant by "Don't forget to uncomment USERHOOK_INIT and USERHOOK_MEDIUMLOOP in APM_Config.h

              I see the file APM_Config.h, what change do i make.

              Thanks for the fast responses brother.

              - Rai Gohalwar

              • Rai,

                In the file APM_Config.h:

                Line 52:

                // Put your custom code into the UserCode.pde with function names matching those listed below and ensure the appropriate #define below is uncommented below

                //#define USERHOOK_INIT userhook_init(); // for code to be run once at startup

                Line 56:

                //#define USERHOOK_MEDIUMLOOP userhook_MediumLoop(); // for code to be run at 10hz

                These lines are prefixed with "//" which causes the compiler to ignore them as comments.

                You need to remove the "//" from the beginning of these two lines so the compiler includes them as code and calls the two functions at the appropriate time.

                • Hi James,

                  Thanks, all done with the code modification.

                  What method of building the firmware did you use?  Make or Microsoft visual basic?

                  reason I ask is because I am using make and it keeps giving me a variable error?

                  - Rai Gohalwar

                  • I will private message you my skype address

This reply was deleted.

Activity

DIY Robocars via Twitter
RT @donkey_car: Human-scale Donkey Car! Hope this makes it to a @diyrobocars race https://www.youtube.com/watch?v=ZMaf031U8jg
Saturday
DIY Robocars via Twitter
Saturday
DIY Robocars via Twitter
Jun 16
DIY Robocars via Twitter
RT @GrantEMoe: I won my first @diyrobocars @donkey_car virtual race! Many thanks to @chr1sa @EllerbachMaxime @tawnkramer and everyone who m…
Jun 13
DIY Robocars via Twitter
RT @gclue_akira: JetRacerで自動走行したコースを、InstantNeRFで再構築。データセットは別々に収集 #jetracer #instantNeRT https://t.co/T8zjg3MFyO
Jun 13
DIY Robocars via Twitter
RT @SmallpixelCar: SPC 3.0 Now the motor also works. This car is doable. I just need to design a deck to mount my compute and sensors. http…
Jun 13
DIY Robocars via Twitter
RT @SmallpixelCar: My new car SPC 3.0. https://t.co/CKtkZOxeNQ
Jun 7
DIY Robocars via Twitter
RT @SmallpixelCar: High speed at @diyrobocars thanks @EdwardM26321707 for sharing the video https://t.co/o4317Y2U1S
Jun 7
DIY Robocars via Twitter
RT @SmallpixelCar: Today at @RAMS_RC_Club for @diyrobocars. Used @emlid RTK GPS and @adafruit @BoschGlobal IMU. Lap time 28s https://t.co/R…
May 28
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
More…