Any tips on how to code this?

Currently I am in the midst of building a college project that is to build a custom system that includes two propellers faced in opposite directions that rotate a platform two motors sit on, and that platform is rotated by a servo. Now my team is trying to operate preloaded vehicles and is trying to figure out the ability to customize an existing build or if we can create one from scratch. We would really appreciate any tips. We are using a Pixhawk 4 2 brushless motors and 1 servo. We need to be able to rotate the servo dependent on compass information, and also operate propellers dependent on compass direction.

I think you’re in the wrong place.

This has nothing to do with ArduPilot and even less to do with QGroundControl, where you posted it.

I think you’d best look into a Pixhawk hardware forum or maybe just an STM32 programming discussion.

I don’t think ArduPilot firmware will get you anywhere with this, and it doesn’t even seem that you need IMUs, barometers, or any of the other sensor array available on the Pixhawk board. A microcontroller breakout board might be best for this.

Forgive me if I am mistaken, and somehow that thing is supposed to fly, in which case you should search here for custom frame types and possibly even custom controller implementation.

1 Like

Here is some AI assistance:

Making a smoker fly using two brushless motors and a servo would be quite challenging, but it is possible to design and build a basic flying machine with these components. Here are some general steps to follow:

  1. Determine the weight of the smoker and the payload it is carrying. This will help you select the appropriate brushless motors and propellers.
  2. Choose two brushless motors that are powerful enough to lift the smoker off the ground. Make sure they have matching specifications, such as KV rating and maximum thrust.
  3. Mount the motors onto the smoker, one on either side, with the propellers facing upwards. You may need to use brackets or other hardware to secure them in place.
  4. Connect the motors to an electronic speed controller (ESC) that can regulate their speed. This will allow you to control the lift and thrust of the smoker.
  5. Attach a servo to the back of the smoker, which can be used to adjust the pitch and roll of the smoker in flight. This will be necessary for steering and stability.
  6. Use a flight controller or radio transmitter to send signals to the ESC and servo, controlling the speed and direction of the motors and the angle of the smoker.
  7. Test your smoker in a safe, open area to ensure that it is stable and controllable. You may need to make adjustments to the motor speed or servo angle to achieve stable flight.

Impressively, ChatGPT writes nearly intelligible code for a nearly unflyable object. If you actually make something fly with this code, I want to see video!

Flying a drone with opposing horizontal propellers can be challenging due to the inherent instability caused by the opposing torques generated by each pair of propellers. To fly such a drone in a stable manner, we need to implement a control system that can adjust the speed and orientation of the propellers in response to changes in the drone’s orientation and velocity.

Here’s an example C++ code for an ArduPilot library that implements a basic control system for a drone with opposing horizontal propellers:

#include <AP_Motors.h>
#include <AP_AHRS.h>

// Define constants for control gains
const float ROLL_GAIN = 0.2;
const float PITCH_GAIN = 0.2;
const float YAW_GAIN = 0.1;

// Define motor object with 2 pairs of opposing propellers
AP_Motors motors(2, 2, 1);

// Define AHRS object for attitude estimation
AP_AHRS ahrs;

void setup()
  // Initialize motor object with pin numbers
  motors.init(10, 11, 12, 13, 6, 7, 8, 9);
  // Initialize AHRS object with IMU

void loop()
  // Read current drone orientation from AHRS
  float roll = ahrs.roll;
  float pitch = ahrs.pitch;
  float yaw = ahrs.yaw;
  // Compute control signals based on orientation
  float roll_control = -ROLL_GAIN * roll;
  float pitch_control = -PITCH_GAIN * pitch;
  float yaw_control = -YAW_GAIN * yaw;
  // Apply control signals to motors

In this code, we first define the control gains for roll, pitch, and yaw stabilization. These gains can be adjusted to achieve the desired level of stability. We then define the motor object with 2 pairs of opposing propellers and initialize it with the appropriate pin numbers. We also initialize the AHRS object with the IMU sensor to estimate the drone’s attitude.

In the loop function, we first read the current orientation of the drone from the AHRS object. We then compute the control signals based on the orientation using the defined control gains. Finally, we apply the control signals to the motors using the set_roll, set_pitch, and set_yaw functions of the motor object.

This basic control system should be able to stabilize the drone in the air, but more advanced control algorithms may be required for more precise and responsive control. Additionally, other sensors such as a barometer or GPS may be necessary for altitude and position control.


I have been asking that Bot about a wide variety of subject matter and it’s uncanny how well it responds.