I've been fighting for the last 4 days with changing my program to cope with new Serial Protocol.
You can check the code here https://github.com/luisfcorreia/bi-copter-wii-remote.
The relevant file is Controller.java.
(this is part on an Android app and a lot of stuff is ommited)
Code: Select all
/*
* Values now go from 0-100 for Throttle All others go from -50
* +50
*/
mt = mThr;
my = mYaw - 50;
mr = mRol - 50;
mp = mPit - 50;
ma = (arm * 100) - 50;
/*
* factor in the influence in percentage
*/
mr = (int) (mr * aaRol);
mp = (int) (mp * aaPit);
my = (int) (my * aaYaw);
/*
* translate values to pulse data
*/
THROTTLE = THROTTLE + (mt * 6);
ROLL = ROLL + (mr * 6);
PITCH = PITCH + (mp * 6);
YAW = YAW + (my * 6);
AUX1 = AUX1 + (ma * 6);
Log.i(TAG, "r " + ROLL);
Log.i(TAG, "p " + PITCH);
Log.i(TAG, "y " + YAW);
Log.i(TAG, "t " + THROTTLE);
Log.i(TAG, "a " + AUX1);
/*
* MultiWii header
*/
/*
* comando[0] = '$'; comando[1] = 'M'; comando[2] = '<';
*/
mw[0] = 0x10;
mw[1] = 0xc8;
/*
* #define ROLL 0
*/
mw[2] = (char) (ROLL & 0xff);
mw[3] = (char) (ROLL >> 8);
/*
* #define PITCH 1
*/
mw[4] = (char) (PITCH & 0xff);
mw[5] = (char) (PITCH >> 8);
/*
* #define YAW 2
*/
mw[6] = (char) (YAW & 0xff);
mw[7] = (char) (YAW >> 8);
/*
* #define THROTTLE 3
*/
mw[8] = (char) (THROTTLE & 0xff);
mw[9] = (char) (THROTTLE >> 8);
/*
* #define AUX1 4
*/
mw[10] = (char) (AUX1 & 0xff);
mw[11] = (char) (AUX1 >> 8);
/*
* #define AUX2 5
*/
mw[12] = (char) (AUX2 & 0xff);
mw[13] = (char) (AUX2 >> 8);
/*
* #define AUX3 6
*/
mw[14] = (char) (AUX3 & 0xff);
mw[15] = (char) (AUX3 >> 8);
/*
* #define AUX4 7
*/
mw[16] = (char) (AUX4 & 0xff);
mw[17] = (char) (AUX4 >> 8);
/*
* calculate checksum
*/
checksum = 0;
for (int i = 0; i < 17; i++) {
checksum ^= (mw[i] & 0xFF);
}
mw[17] = (char) checksum;
/*
* Send string to MultiWii device
*/
comms = String.valueOf(mw);
bt.write("$M<" + comms);
Log.i(TAG, "$M<" + comms);
It is using the 2.1 MultiWii Release code with no changes except config.h
I've read back and forth the multiwiiconf gui code to learn how to create a proper checksum and I'm out of ideas.
I really don't want to dumb down multiwii code to use my old version.
Any help will be apreciated.
Thanks,
Luis