dRehmFlight VTOL - Teensy (Arduino) Flight Controller and Stabilization

NickRehm

Member
Gonna be stationed up at Flite Fest with a couple hardware kits for sale--first come first serve.

Kits include:
  • Teensy 4.0
  • IMU
  • Angled male header pins
  • Straight male header pins
  • Female header pins
  • Wire
  • Shrink tube
  • Sticker :)

Basically everything for plug-and-play setup after soldering everything up. If you promise to put it in one of your Flite Fest builds, I'll solder it up for you on the spot and help you through the code setup myself. I'll let you take the F-35 up for a spin as well:

 

Jesse Dupreez

Active member
Hi all,

I'm sharing my custom flight controller code written for the Teensy 4.0 and MPU6050 IMU. The best summary I've been able to prepare thus far:

"dRehmFlight VTOL is a bare-bones flight controller for hobbyists or researchers wanting to get something flying fast with the ability to quickly and intuitively adapt to unique configurations. The Arduino environment makes it easy to make your additions--from basic functionality to sensor integration to custom inner-loop control--without the hassle of dealing with spaghetti code cluttered by features you'll never use."


Download: https://github.com/nickrehm/dRehmFlight

Features:
  • Code modifications and compiling done within the Arduino IDE with Teensyduino add-on.
  • Default code supports 6 ESC outputs using OneShot125 Protocol, and 7 conventional PWM outputs for ESCs or servos, with the ability to modify the code for extra outputs for custom setups.
  • Support for conventional PWM, PPM, or SBUS receivers.
  • MPU6050 and MPY9250 IMUs supported.
  • Easy to use control mixer with stabilized axis variables and ability to pass direct, unstabilized commands to the motors or servos direct from the transmitter.
  • Three PID controller types including rate and angle-based setpoint.
  • Simple variable fading, with support for more advanced options planned in the future.
  • Default hardware setup (Teensy 4.0 and MPU6050 IMU) costs less than $30 and weighs less than 15 grams.
  • Comprehensive documentation with explanation of every function and variable, as well as tutorials for setting up the hardware and modifying the code for your application.

This is not just meant to stabilize multirotors (though it does that really well). Here is an example of what you can do with the stock code after adding ~20 additional lines of code in the provided control mixer:


So, if you know a little bit about Arduino, this project may be for you to get practically any vehicle type stabilized in the air. If you don't know about Arduino--don't worry. Check out the provided documentation (GitHub download) which includes a complete overview of the code as well as detailed tutorials for setting up the hardware and modifying the code for your application. I'm also releasing a video series covering everything (+more) in the documentation:




Code Walkthrough Video: https://www.youtube.com/watch?v=_n5GBudUf5Q&feature=youtu.be

Hope some of you tinkerers find this project useful,

Nick
Two things rcjetflier
one can i use a arduino pro mini instead of the Teensy 4.0?
second can i use the code for a rc helicopter
 

tamuct01

Well-known member
Two things rcjetflier
one can i use a arduino pro mini instead of the Teensy 4.0?
second can i use the code for a rc helicopter

I doubt that the Arduino has enough speed to run the realtime calculations necessary. The Pro Mini runs at 8/16MHz where the Teensy 4.0 is at 600MHz. It could be used in a helicopter to handle the swashplate mixing. You'd need to write the mixing code yourself in the controlMixer() function. Each swashplate servo output would be a combination of collective, roll, and pitch inputs.
 

Jesse Dupreez

Active member
I doubt that the Arduino has enough speed to run the realtime calculations necessary. The Pro Mini runs at 8/16MHz where the Teensy 4.0 is at 600MHz. It could be used in a helicopter to handle the swashplate mixing. You'd need to write the mixing code yourself in the controlMixer() function. Each swashplate servo output would be a combination of collective, roll, and pitch inputs.
thanks,i know that i can use a promini as a auto stabilize for a glider
 

Mohamed

New member
if anyone's still here, i would like to know if you've read the code and found the lines where the IMU pins are defined because I can't find them.
I've looked in the main code and the mpu6050 code too
 

NickRehm

Member
The wire.begin() call to initialize the i2c bus is associated with sda0 scl0, pins 18 and 19. Wire1.begin() would be associated with sda1, scl1 pinouts on teensy. But I think the 6050 library defaults to i2c 0...might need to specify i2c bus # when you initialize the 6050 object

What are you trying to do?
 

Mohamed

New member
The wire.begin() call to initialize the i2c bus is associated with sda0 scl0, pins 18 and 19. Wire1.begin() would be associated with sda1, scl1 pinouts on teensy. But I think the 6050 library defaults to i2c 0...might need to specify i2c bus # when you initialize the 6050 object

What are you trying to do?
so happy you replied. I'm the same guy that asked the question about the raspberry pi Pico the other day
I have remapped all the pins expect for the IMU pins( because I'm using a different board). That's why I was looking for the lines where it was defined
 

Mohamed

New member
I'll try to find the pins that would correspond to these functions on the raspberry pi Pico

also I'm getting this error when compiling
" multiple definition of `dt' "
do you have an idea of why it happens ?
 

NickRehm

Member
1663605727502.png

You're interested in i2c0
 

Mohamed

New member
apparently there is a pins_arduino.h file witch include all of the pin definitions for pico. It is found in

C:\Users\Arby Mohamed\AppData\Local\Arduino15\packages\arduino\hardware\mbed_rp2040\3.3.0\variants\RASPBERRY_PI_PICO

(for anyone interested )
it can also be modified

so I think the remap of the pins is done now. but the " multiple definition of `dt' " error is still there
 

Attachments

  • pico.png
    pico.png
    24 KB · Views: 0

Mohamed

New member
axx.png gyro.png rollpitchyaw.png

i think the IMU might have a problem. Just like in the video, I ensured that the connections were good with the help of a multimeter and it's still the same
 

NickRehm

Member
Looks uncalibrated. There's a new procedure not covered in the video that is covered in the docs to save the IMU calibration. Tutorial 9.4
 

Mohamed

New member
Looks uncalibrated. There's a new procedure not covered in the video that is covered in the docs to save the IMU calibration. Tutorial 9.4
the gyro is calibrated now,

but the signals from the receiver is not being read by the board. I'm using the expresslrs pwm receiver for this. all the connections were checked, I even connected a servo to verify that the receiver was really outputting a signal. the radiodata in the serial monitor display the failsafe values regardless.

I had to replace the PWMservo library with servo.h because PWMservo does not support the raspberry pi Pico!!:ROFLMAO: or else I couldn't compile. I haven't tested servo outputs yet
 

NickRehm

Member
Did you use interrupt-capable pins to read the pwm channels? You can comment out the failsafe() function in the void loop to see what, if any, values are coming through to the pins
 

Mohamed

New member
after commenting out the failsafe() function, I could see the data change when the sticks were moved.
 
Last edited:

Mohamed

New member
Did you use interrupt-capable pins to read the pwm channels? You can comment out the failsafe() function in the void loop to see what, if any, values are coming through to the pins

is there a possibility that the failsafe values are displayed because I'm not using ch6
I am using a 5ch receiver and when the failsafe function is commented I can see that my values are within the range of 800 to 2200 that is set in the code
 
Last edited: