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?