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
Replies
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
It kept saying that a float was used in case of a char in id 157
Weird, never seen that before. By the way i was using the console to do it. How do you build it from the eclipse?
-Rai Gohalwar
Rai, I use make both from the command line and from Eclipse. What is the error you are getting?