Where to add custom throttle input in code?

This forum is dedicated to all issues and questions related to your individual setups and configurations
Post Reply
Argosse
Posts: 4
Joined: Mon May 02, 2016 9:09 am

Where to add custom throttle input in code?

Post by Argosse »

I'm building a quadcopter using an Arduino Mega, and a 'Yun'-type shield, so pretty much an arduino yun. I currently have an android app Ive written sending throttle commands to a python tcp server running on the Arduino/YunShield over wifi. I have a working method and can arm motors now looking into MultiWii to integrate my gy-521/mpu6050 and hmc5883. I've looked and looked through the MultiWii source but am not sure where/how to insert my throttle that is read from the bridge. Here is my arduino sketch.

Code: Select all


#include <Bridge.h>
#include <BridgeServer.h>
#include <BridgeClient.h>

#include <Servo.h>

//****************************************************//////
// Listen to the default port 5555, the Yún webserver
// will forward there all the HTTP requests you send
BridgeServer server;

// Testing the first speed controller,
// uses 'Servo' library to control ESC
Servo esc1,esc2,esc3,esc4;

// Variables to hold values from Bridge
char brThrottleData[3];
char brMotorsActive[2];

const int TESTLED = 12;

int new_led_pwr = 0;
int old_led_pwr = 0;

int DEBUGINT = 0;
int D13int = 0;

int newThrottle = 0;
int currentThrottle = 0;
boolean MOTORSSETUP = false;

int mESCPin1 = 44;
int mESCPin2 = 45;
int mESCPin3 = 46;
int mESCPin4 = 10;

void setupMotors()
{
  esc1.attach(mESCPin1);
  esc2.attach(mESCPin2);
  esc3.attach(mESCPin3);
  esc4.attach(mESCPin4);

  MOTORSSETUP = true;
}

void setup()
{
  pinMode(TESTLED, OUTPUT);
  pinMode(esc1Pin, OUTPUT);

  // Bridge startup
  Bridge.begin();



  memset( D13value, 0, 2);
  memset( brMotorsActive, 0, 2);
  memset( brMsg, 0 , 50);
  memset( brThrottleData, 0, 3);

  // Listen for incoming connection only from localhost
  // (no one from the external network could connect)
  server.listenOnLocalhost();
  server.begin();

  setupMotors();
}

bool motorsActive = true;
bool throttleChanged = false;

// ------- LOOP ---------- //
void loop()
{

  if ( MOTORSSETUP )
  {
    if ( (Bridge.get( "THROTTLE", brThrottleData, 3)) > 0 )
    {
      int recvdThrottle = atoi(brThrottleData);
      if ( motorsActive )
      {
        newThrottle = map(recvdThrottle, 0, 100, 0, 179);
        if ( newThrottle != currentThrottle )
        {
          throttleChanged = true;
          esc1.write(newThrottle);
          esc2.write(newThrottle);
          esc3.write(newThrottle);
          esc4.write(newThrottle);
          currentThrottle = newThrottle;
 
        }
        else
        {
          throttleChanged = false;
        }
      }

      new_led_pwr = map(recvdThrottle, 0, 200, 0, 255);
      if ( new_led_pwr != old_led_pwr )
      {
        old_led_pwr = new_led_pwr;
        analogWrite(TESTLED, new_led_pwr);
   
      }
    }

    if ( (Bridge.get("MOTORSACTIVE", brMotorsActive, 2)) > 0 )
    {
      int newMotActiveState = atoi(brMotorsActive);

      if ( newMotActiveState == 1 )
      {
        motorsActive = true;

      }
      else if ( newMotActiveState == 0 )
      {
        motorsActive = false;

      }
    }

  }

  if ( throttleChanged )
  {
    memset(brThrottleData, 0, 3);
    delay(5);
  }
  else
  {
    delay(50);
  }
}



The python tcp server receives the 0-100 from wifi then puts it in Bridge. The bridge gets checked/read and then that 0-100 gets mapped to 0-179, Im currently coding a joystick in android to send roll/yaw/pitch 0-100% each over the tcp connection also. Where can I insert this 0-100 and into multiwii, is it possible? So if anyone could point me to a file/files to take a closer look at or any advice at all, I thank you in advance. Also I could use the my wifi setup to just output analog signals to another uno i have, if the uno could run multiwii and take in inputs?
Last edited by Argosse on Mon May 02, 2016 11:56 pm, edited 1 time in total.

gregd72002
Posts: 103
Joined: Fri Dec 12, 2014 5:16 pm

Re: Where to add custom throttle input in code?

Post by gregd72002 »

why arent you using MSP to feed throttle and all the other commands?

Argosse
Posts: 4
Joined: Mon May 02, 2016 9:09 am

Re: Where to add custom throttle input in code?

Post by Argosse »

I did not know about MSP until now. Thank you it looks like it should work.

When using MSP, how do I configure MultiWii to listen for a Serial connection over i/o pins? I will use Uno with MultiWii and Mega with tcp, then connect them through software serial using digital pins. I already know how to send the serial messages. Can you help with config and connections?

gregd72002
Posts: 103
Joined: Fri Dec 12, 2014 5:16 pm

Re: Where to add custom throttle input in code?

Post by gregd72002 »

you just need to enable MSP in config.h. This is all you need.

For the communication bit you will need to use the RX/TX on your uno and whatever you configure on your mega

Argosse
Posts: 4
Joined: Mon May 02, 2016 9:09 am

Re: Where to add custom throttle input in code?

Post by Argosse »

Awesome! Thank you, I have been reading about MSP and the serial message protocol/message format and now that I know how to connect I can start writing/testing.
Thank you again. Ill try to post updates soon so anyone in future can look here, not a lot of info on working with the yun and a wifi or tcp connection.

gregd72002
Posts: 103
Joined: Fri Dec 12, 2014 5:16 pm

Re: Where to add custom throttle input in code?

Post by gregd72002 »

A good alternative to yun would be a fully featured SoC - odroid, rpi, beagleboard, etc some of them have really small boards that are easy to mount (ie. odroid-w, rpi zero).
You then could use mw-service to do the UART communication for you and then write a bridge on top of it. Or alternatively use mw-mavlink for mavlink communication over udp which works with qgroundcontrol.

https://github.com/rpicopter

Argosse
Posts: 4
Joined: Mon May 02, 2016 9:09 am

Re: Where to add custom throttle input in code?

Post by Argosse »

Now that I know about MSP I may be able to use just the mega w/yun-shield or an arduino yun to run MW and python on linux side can create serial/tcp bridge. I would really like this configuration so I could use MW gui on laptop or a similar android app, instead of coding my own app. I am looking at beagleboards etc, that may be near future, I have everything in hand now and limited budget. Working on configuring now, will keep posted, thanks again to everyone.

Post Reply