Editing Ardupilot code for PWM RSSI input.

This is a tutorial on how to edit the Ardupilot source code to support PWM RSSI input. Keep in mind that this will take up one of the PWM input channels of the ardupilot, (Also works with a PPM channel if your Receiver supports it [OpenLRS for the win!])

NOTE: THIS WILL ONLY WORK WITH SERVO-TYPE PWM, most RSSI PWM output is not designed for servos, do your research!

Here are a few things you need to download first:
- Arduino Environment for APM:  https://code.google.com/p/ardupilot-mega/downloads/list/ (download the ArduPilot-Arduino-1.0.3-Mac.zip [or windows for windows pc's]) This is a special version of the arduino software that allows you to upload the code to the ardupilot. This tutorial may work with the regular version of the Arduino Environment but I have not tested it.


- Ardupilot source code: https://code.google.com/p/ardupilot-mega/downloads/list/ (download the ArduPlane-2.74b.zip) The source code of the Ardupilot.

A few quick definitions:
Arduino environment: The window that pops up and says "Arduino", also has the Arduino logo on your task bar.

I assume:
- You have basic knowledge of the Mission planner software
- You know how to install a program
- You know how to copy/create files/folders
- You know how to extract .zip files


Step 1: Setup the APM Library. (If you are on mac or PC this step is the same.)

Step 1.A:
First navigate to your "Documents" or "My Documents" folder. If there is a folder called Arduino look inside of it. If there is no "Arduino" folder create a new folder called "Arduino".

Step 1.B
Unzip the Ardupilot source code, inside you should find a folder called "Library" drag this to the "Arduino" folder inside the documents folder. If there is already a "Library" folder do not erase it's contents, just merge the two and keep everything.

Step 2: Open Arduino

Step 2.A
Extract the "Ardupilot-Arduino-1.x.x" File. And open up the Arduino environment. 

Step 2.B
Open the ardupilot source code. It should be back in the "ardupilot-master" folder. Find your chosen source (either arducopter, arduplane or APMrover). 
To do this go to the Arduino environment and hit File>Open, browse to the right file. (make sure to open the .pde file that is named after the type of craft. For example for airplanes open the /ardupilot-master/ArduPlane/ArduPlane.pde file

Step 3: Edit the code.

Step 3.A
From the Arduino environment find the "sensors.pde" file. If you can't see it in the tabs hit the down arrow on the top right hand side of the Arduino Environment. This will give you a drop down menu of other files in the project.

Step 3.B
Change the "void read_receiver_rssi(void)" function from:

rssi_analog_source->set_pin(g.rssi_pin);
float ret = rssi_analog_source->voltage_average() * 50;
receiver_rssi = constrain_int16(ret, 0, 255);

To:

receiver_rssi = constrain_int16((g.rc_4.radio_in-900)/4.3, 0, 255);

This will set the receiver_rssi based on the PWM from channel 4 (rudder). In my case I am flying a wing so I used the rudder channel. But you can change the number in "rc_4" to the channel you would like to monitor. (1-8, Be warned channels 1-4 are usually used for aileron, elevator, throttle, and rudder) NOTE: make sure that your RSSI channel does not do anything else. (Browse through the basic/advanced settings in the Mission Planner to check)

Keep in mind depending on the Calibration of your PWM output some information may be lost. In my case the PWM went up to 1998. Therefore we have (1998-900)/4.3 = 255.34. The "constrain_int16" limits this value to 255. so you may loose a bit of resolution You can find out what divisor you should use (in my case it was 4.3) like this:

divisor = (maxPWM-900)/255

If you wanted to get even more accurate you could change "900" to the minimum PWM value outputted by the RX. (In my case this value was 900)

That way you will get the most resolution possible. If you don't know how to find the maxPWM or minPWM don't worry. 4.3 is what most systems will need. 


Step 4: Upload the new Firmware to the APM

Step 4.A: Select your board and serial port from the Arduino Environment. 
Beside the "File" and "Edit" buttons you should see a "Tools" Section.
Inside of "Tools":
Change the "Board" to "Arduino Mega 2560 or Mega ADK"
Change the "Serial port" to the serial port of the APM 
On MAC this will be something like "/dev/cu.usbmodemfaXXX" where XXX are numbers.
On PC it will be something like "COMXX" Where XX are numbers (check the device manager to verify the com port)
Beside "Tools" you should see "ArduPilot"
Inside of ArduPilot>HAL Board> select your board (APM 1 or APM 2.X)

Step 4.B: Backup your APM settings
For me the settings all stayed when I flashed the chip, but I also backed them up first. To do this first open Mission Planner and connect to the APM. Navigate to the "Full Parameter List" (it is under the "Config/Tuning" tab) On the right there are a bunch of green buttons, hit save and name the file accordingly.

Step 4.C: Upload the firmware NOTE: you will have to disconnect the APM from mission planner first.
In the Arduino Environment click File>Upload to begin the upload. NOTE: It may take a while to compile and upload, this is NORMAL.

Step5: Verify
If it worked you should see the "rxrssi" value in the "status" tab of the "flight data" page change when you turn on/off your radio.

If it DID NOT WORK and you want to revert to the original APM code, simply open Mission planner, go to the initial setup page, and reinstall the firmware from there.

Hopefully this helped, If you have any questions feel free to ask.

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

Join diydrones

Email me when people reply –

Replies

  • There's now an official RSSI library in ArduPilot that covers this uniformly. Thanks for making this available in the meantime!

    https://github.com/diydrones/ardupilot/pull/2770

    This should be showing up in ArduPlane 3.4 and ArduCopter 3.4. Rover as well, unsure of version.

  • Hi,

    Nice!

    Can you tell me which radio works with this?

    Many have PWM RSSI allright, but for example my FrSky TFR4s' RSSI signals are not the same kind of PWM as the servo channels. The pulses come much more frequently and they are up to 90% wide (an RC pulse is about 10% max.). A standard RC input software or PWM to PPM coder may have some trouble trying to decode that?

    Regards

    Soren

This reply was deleted.

Activity

DIY Robocars via Twitter
RT @chr1sa: Donkeycar 4.4 released with tons of new features, including path learning (useful with GPS outdoors), better Web and Lidar supp…
yesterday
DIY Robocars via Twitter
RT @NXP: We are already biting our nails in anticipation of the #NXPCupEMEA challenge! 😉 Did you know there are great cash prizes to be won…
Friday
DIY Robocars via Twitter
RT @gclue_akira: レースまであと3日。今回のコースは激ムズかも。あと一歩 #jetracer https://t.co/GKcEjImQ3t
Friday
DIY Robocars via Twitter
UC Berkeley's DIY robocar program https://roar.berkeley.edu/
Friday
DIY Robocars via Twitter
RT @chr1sa: The next @DIYRobocars autonomous car race at @circuitlaunch will be on Sat, Dec 10. Thrills, spills and a Brazilian BBQ. Fun…
Friday
DIY Robocars via Twitter
RT @arthiak_tc: Donkey car platform ... Still training uses behavioral cloning #TCXpo #diyrobocar @OttawaAVGroup https://t.co/PHBYwlFlnE
Nov 20
DIY Robocars via Twitter
RT @emurmur77: Points for style. @donkeycar racing in @diyrobocars at @UCSDJacobs thanks @chr1sa for taking the video. https://t.co/Y2hMyj1…
Nov 20
DIY Robocars via Twitter
RT @SmallpixelCar: Going to @diyrobocars race at @UCSDJacobs https://t.co/Rrf9vDJ8TJ
Nov 8
DIY Robocars via Twitter
RT @SmallpixelCar: Race @diyrobocars at @UCSDJacobs thanks @chr1sa for taking the video. https://t.co/kK686Hb9Ej
Nov 8
DIY Robocars via Twitter
RT @PiWarsRobotics: Presenting: the Hacky Racers Robotic Racing Series in collaboration with #PiWars. Find out more and register your inter…
Oct 23
DIY Robocars via Twitter
RT @Hacky_Racers: There will be three classes at this event: A4, A2, and Hacky Racer! A4 and A2 are based around UK paper sizing and existi…
Oct 23
DIY Robocars via Twitter
Oct 23
DIY Robocars via Twitter
Oct 19
DIY Robocars via Twitter
Oct 18
DIY Robocars via Twitter
RT @NeaveEng: Calling all UK based folks interested in @diyrobocars, @f1tenth, @donkey_car, and similar robot racing competitions! @hacky_r…
Oct 13
DIY Robocars via Twitter
RT @araffin2: 🏎️ After hours of video editing, I'm happy to share a best of my Twitch videos on learning to race with RL. 🏎️ Each part is…
Oct 13
More…