Skip to content

Commit

Permalink
rename executable to indiflight. Added position forwarding over MSP
Browse files Browse the repository at this point in the history
  • Loading branch information
tblaha committed May 13, 2024
1 parent 57c0f5c commit 2cd1922
Show file tree
Hide file tree
Showing 9 changed files with 282 additions and 9 deletions.
4 changes: 2 additions & 2 deletions assets/linux/betaflight-configurator.desktop
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[Desktop Entry]
Name=Indiflight Configurator
Comment=Crossplatform configuration tool for the Indiflight flight control system
Exec=/opt/betaflight/betaflight-configurator/betaflight-configurator
Icon=/opt/betaflight/betaflight-configurator/icon/if_icon_128.png
Exec=/opt/indiflight/indiflight-configurator/indiflight-configurator
Icon=/opt/indiflight/indiflight-configurator/icon/if_icon_128.png
Terminal=false
Type=Application
Categories=Utility
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const RELEASE_DIR = './release/';
const CORDOVA_DIR = './cordova/';
const CORDOVA_DIST_DIR = './dist_cordova/';

const LINUX_INSTALL_DIR = '/opt/betaflight';
const LINUX_INSTALL_DIR = '/opt/indiflight';

const NODE_ENV = process.env.NODE_ENV || 'production';

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "betaflight-configurator",
"name": "indiflight-configurator",
"productName": "Indiflight Configurator",
"description": "Crossplatform configuration tool for Betaflight flight control system.",
"version": "10.10.1-indi",
Expand Down Expand Up @@ -28,7 +28,7 @@
},
"repository": {
"type": "git",
"url": "github.com/tblaha/betaflight-configurator"
"url": "github.com/tblaha/indiflight-configurator"
},
"webview": {
"partitions": [
Expand Down
27 changes: 27 additions & 0 deletions src/js/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const FC = {
GPS_CONFIG: null,
GPS_DATA: null,
GPS_RESCUE: null,
INDI_CONFIG: null,
LED_COLORS: null,
LED_MODE_COLORS: null,
LED_STRIP: null,
Expand Down Expand Up @@ -533,6 +534,32 @@ const FC = {
};
this.ADVANCED_TUNING_ACTIVE = { ...this.ADVANCED_TUNING };

this.INDI_CONFIG = {
attGains: [0,0,0],
rateGains: [0,0,0],
maxNegativeSpfZ: 0,
maxBankDegreeManual: 0,
maxBankDegreeAuto: 0,
omegaHover: 0,
actTimeConstants: [0,0,0,0,0,0,0,0],
kThrust: [0,0,0,0,0,0,0,0],
Tmax: [0,0,0,0,0,0,0,0],
wlsEnable: false,
wlsAlgorithmChoice: 0,
wlsUsewarmstart: false,
wlsMaxIter: 0,
wlsCondBound: 0,
wlsTheta: 0,
wlsWv2: [0,0,0,0,0,0],
wlsWu2: [0,0,0,0,0,0],
uPref: [0,0,0,0,0,0,0,0],

Check failure on line 556 in src/js/fc.js

View workflow job for this annotation

GitHub Actions / CI / Test

Trailing spaces not allowed
useIncrement: false,
useOmegaFeedback: false,
useOmegaDotFeedback: false,
useConstantG2: false,
};

this.SENSOR_CONFIG = {
acc_hardware: 0,
baro_hardware: 0,
Expand Down
10 changes: 10 additions & 0 deletions src/js/msp/MSPCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ const MSPCodes = {
// MSPv2 Common
MSP2_COMMON_SERIAL_CONFIG: 0x1009,
MSP2_COMMON_SET_SERIAL_CONFIG: 0x100A,
MSP2_SENSOR_GPS: 0x1F03,

// MSPv2 Betaflight specific
MSP2_BETAFLIGHT_BIND: 0x3000,
Expand All @@ -197,6 +198,15 @@ const MSPCodes = {
MSP2_GET_TEXT: 0x3006,
MSP2_SET_TEXT: 0x3007,

// MSPv2 Indiflight specific
MSP2_INDI_CONFIG: 0x4000,
MSP2_SET_INDI_CONFIG: 0x4001,
MSP2_INDI_PROFILE: 0x4002,
MSP2_SET_INDI_PROFILE: 0x4003,
MSP2_LEARNING_CONFIG: 0x4004,
MSP2_SET_LEARNING_CONFIG: 0x4005,
MSP2_SET_POSITION_SETPOINT: 0x4006,

// MSP2_GET_TEXT and MSP2_SET_TEXT variable types
PILOT_NAME: 1,
CRAFT_NAME: 2,
Expand Down
57 changes: 57 additions & 0 deletions src/js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { showErrorDialog } from "../utils/showErrorDialog";
import GUI, { TABS } from "../gui";
import { OSD } from "../tabs/osd";
import { reinitializeConnection } from "../serial_backend";
import { gps, pos_set } from "../tabs/gps";

// Used for LED_STRIP
const ledDirectionLetters = ['n', 'e', 's', 'w', 'u', 'd']; // in LSB bit order
Expand Down Expand Up @@ -1590,6 +1591,14 @@ MspHelper.prototype.process_data = function(dataHandler) {
console.log('DSHOT command sent');
break;

case MSPCodes.MSP2_SENSOR_GPS:
console.log('GPS sent');
break;

case MSPCodes.MSP2_SET_POSITION_SETPOINT:
console.log('Position Setpoint sent');
break;

case MSPCodes.MSP_MULTIPLE_MSP:

let hasReturnedSomeCommand = false; // To avoid infinite loops
Expand Down Expand Up @@ -2238,6 +2247,54 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) {
buffer.push8(1);
break;

case MSPCodes.MSP2_SENSOR_GPS:
buffer.push8(0); // instance
buffer.push16(0); // gps week
buffer.push32(gps.time_ms); // ms_tow
buffer.push8(1); // fix_type
buffer.push8(20); // num sats
buffer.push16(1); // horizontal pos accuracy in cm
buffer.push16(1); // vertical pos accuracy in cm
buffer.push16(1); // horizontal vel accuracy in cm/s
buffer.push16(150); // dilusion of precision * 100
//buffer.push32(40_000_000); // longitude deg * 1e7
//buffer.push32(520_000_000); // latitude deg * 1e7
buffer.push32(gps.lon*1e7); // longitude deg * 1e7
buffer.push32(gps.lat*1e7); // latitude deg * 1e7
buffer.push32(gps.alt*100); // altitude in cm
buffer.push32(gps.vn*100); // ned vel north cm/s
buffer.push32(gps.ve*100); // ned vel east cm/s
buffer.push32(gps.vd*100); // ned vel down, unused
buffer.push16(0); // ground course, deg*10
buffer.push16(gps.yaw*10); // true yaw, deg*10, unused
buffer.push16(0); // year
buffer.push8(0); // month
buffer.push8(0); // day
buffer.push8(0); // hour
buffer.push8(0); // min
buffer.push8(0); // sec
break;

case MSPCodes.MSP2_SET_INDI_CONFIG:
break;

case MSPCodes.MSP2_SET_INDI_PROFILE:
buffer.push8(FC.INDI_CONFIG.PROFILE_ID);
break;

case MSPCodes.MSP2_SET_LEARNING_CONFIG:
break;

case MSPCodes.MSP2_SET_POSITION_SETPOINT:
buffer.push32(pos_set.time_ms);
buffer.push8(pos_set.mode);
buffer.push32(1000*pos_set.x);
buffer.push32(1000*pos_set.y);
buffer.push32(1000*pos_set.z);
buffer.push16(10*pos_set.yaw);
buffer.push32(100*pos_set.vtraj);
break;

case MSPCodes.MSP_SET_SIMPLIFIED_TUNING:
MspHelper.writePidSliderSettings(buffer);
MspHelper.writeDtermFilterSliderSettings(buffer);
Expand Down
142 changes: 140 additions & 2 deletions src/js/tabs/gps.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,33 @@ import MSPCodes from "../msp/MSPCodes";
import { have_sensor } from "../sensor_helpers";
import { mspHelper } from '../msp/MSPHelper';
import { updateTabList } from '../utils/updateTabList';
//import { checkChromeRuntimeError } from "./utils/common";

const gps = {
time_ms: 0,
lat: 0,
lon: 0,
alt: 0,
vn: 0,
ve: 0,
vd: 0,
yaw: 0,
groundCourse: 0,
MSPrelay: false,
};

const gps = {};
const pos_set = {
time_ms: 0,
mode: 0,
x: 0,
y: 0,
z: -1.5,
lat: 0,
lon: 0,
alt: 0,
yaw: 0,
vtraj: 0,
};

gps.initialize = async function (callback) {

Expand All @@ -20,6 +45,85 @@ gps.initialize = async function (callback) {

const hasMag = have_sensor(FC.CONFIG.activeSensors, 'mag');

var HOME_LAT = 51.99071002805145;

Check failure on line 48 in src/js/tabs/gps.js

View workflow job for this annotation

GitHub Actions / CI / Test

Unexpected var, use let or const instead
var HOME_LON = 4.376727452462819;

Check failure on line 49 in src/js/tabs/gps.js

View workflow job for this annotation

GitHub Actions / CI / Test

Unexpected var, use let or const instead
var RE = 6378137.;

Check failure on line 50 in src/js/tabs/gps.js

View workflow job for this annotation

GitHub Actions / CI / Test

Unexpected var, use let or const instead

pos_set.time_ms = 0;
pos_set.mode = 0; // 0: pos control, 1: trajectory start point, 2: trajectory run
pos_set.lat = HOME_LAT + 180. / 3.1415 * (pos_set.x / RE);
pos_set.lon = HOME_LON + 180. / 3.1415 * (pos_set.y / RE) / Math.cos(HOME_LON * 3.1415/180.);
//pos_set.alt = pos_set.alt;
pos_set.yaw = 0;
pos_set.vtraj = 0; // if mode == 2: speed of the trajectory

if (gps.MSPrelay == false) {
chrome.sockets.udp.create({}, function(socketInfo) {
var socketId = socketInfo.socketId;

Check failure on line 62 in src/js/tabs/gps.js

View workflow job for this annotation

GitHub Actions / CI / Test

Unexpected var, use let or const instead

// Bind the socket to a local address and port
chrome.sockets.udp.bind(socketId, "127.0.0.1", 5769, function(result) {
if (result < 0) {
console.log("Error binding socket: " + result);

Check failure on line 67 in src/js/tabs/gps.js

View workflow job for this annotation

GitHub Actions / CI / Test

Unexpected string concatenation
gps.MSPrelay = false;
return;
}
gps.MSPrelay = true;
console.log("Socket bound");
});

// Listen for incoming packets
chrome.sockets.udp.onReceive.addListener(function(info) {
var data = new Uint8Array(info.data);

Check failure on line 77 in src/js/tabs/gps.js

View workflow job for this annotation

GitHub Actions / CI / Test

Unexpected var, use let or const instead
//var message = String.fromCharCode.apply(null, data);
//console.log("Received message: " + message);

// Assuming each data type has fixed byte sizes
var id = new Uint32Array(data.buffer, 0, 1)[0];

Check failure on line 82 in src/js/tabs/gps.js

View workflow job for this annotation

GitHub Actions / CI / Test

Unexpected var, use let or const instead
var arr = new Uint32Array(data.buffer, 4, 2);

Check failure on line 83 in src/js/tabs/gps.js

View workflow job for this annotation

GitHub Actions / CI / Test

Unexpected var, use let or const instead
var timeUs1 = ((BigInt)(arr[1]) << 32n) + (BigInt)(arr[0]);

Check failure on line 84 in src/js/tabs/gps.js

View workflow job for this annotation

GitHub Actions / CI / Test

Unexpected var, use let or const instead
var timeMs1 = (Number)(timeUs1 / 1000n);

var x = new Float32Array(data.buffer, 12, 1)[0];
var y = new Float32Array(data.buffer, 16, 1)[0];
var z = new Float32Array(data.buffer, 20, 1)[0];
var qx = new Float32Array(data.buffer, 24, 1)[0];
var qy = new Float32Array(data.buffer, 28, 1)[0];
var qz = new Float32Array(data.buffer, 32, 1)[0];
var qw = new Float32Array(data.buffer, 36, 1)[0];
//var arr = new Uint32Array(data.buffer, 40, 2);
//var timeUs2 = new BigUint64Array(arr.buffer, 0, 1)[0];
var vx = new Float32Array(data.buffer, 48, 1)[0];
var vy = new Float32Array(data.buffer, 52, 1)[0];
var vz = new Float32Array(data.buffer, 56, 1)[0];
//var wx = new Float32Array(data.buffer, 60, 1)[0];
//var wy = new Float32Array(data.buffer, 64, 1)[0];
//var wz = new Float32Array(data.buffer, 68, 1)[0];

gps.time_ms = timeMs1;
gps.lat = HOME_LAT + 180. / 3.1415 * (x / RE);
gps.lon = HOME_LON + 180. / 3.1415 * (y / RE) / Math.cos(HOME_LON * 3.1415/180.);
gps.alt = -z;
gps.vn = vx;
gps.ve = vy;
gps.vd = vz;
gps.yaw = 180. / 3.1415 * Math.atan2( 2. * (qw*qz + qx*qy), 1. - 2. * (qy*qy+qz*qz) );
gps.groundCourse = 180. / 3.1415 * Math.atan2(vx, vy);

MSP.send_message(MSPCodes.MSP2_SENSOR_GPS,
mspHelper.crunch(MSPCodes.MSP2_SENSOR_GPS), false, false, false);
//MSP.send_message(MSPCodes.MSP2_SET_POSITION_SETPOINT,
// mspHelper.crunch(MSPCodes.MSP2_SET_POSITION_SETPOINT), false, false, false);
});

// Error listener
chrome.sockets.udp.onReceiveError.addListener(function(error) {
console.log("Error receiving data: " + error.resultCode);
gps.MSPrelay = false;
});
});
}

load_html();

function load_html() {
Expand Down Expand Up @@ -177,6 +281,40 @@ gps.initialize = async function (callback) {

// End GPS Configuration

// Setpoint configuration
const setpointModes = [
"position",
"trajectory",
];

const setpointModeElement = $('select.pos_set_mode');
for (const mode of setpointModes) {
setpointModeElement.append(`<option value="${mode}">${mode}</option>`);
}
console.log("setup done");

function sendSetpoint(mode) {
pos_set.time_ms = gps.time_ms;
pos_set.x = $('input[name="pos_set_x"]').val();
pos_set.y = $('input[name="pos_set_y"]').val();
pos_set.lat = HOME_LAT + 180. / 3.1415 * (pos_set.x / RE);
pos_set.lon = HOME_LON + 180. / 3.1415 * (pos_set.y / RE) / Math.cos(HOME_LON * 3.1415/180.);
pos_set.z = $('input[name="pos_set_z"]').val();
pos_set.mode = mode;
pos_set.vtraj = $('input[name="pos_set_vtraj"]').val();
pos_set.yaw = $('input[name="pos_set_yaw"]').val();
MSP.send_message(MSPCodes.MSP2_SET_POSITION_SETPOINT,
mspHelper.crunch(MSPCodes.MSP2_SET_POSITION_SETPOINT), false, false, false);
}

$('input[name="pos_set_vtraj"]').on('change', function() { sendSetpoint(2); })
$('a.sendSetpoint').on('click', function() { sendSetpoint(0); })
$('a.traj_start').on('click', function() { sendSetpoint(1); })
$('a.traj_pause').on('click', function() {
$('input[name="pos_set_vtraj"]').val(0);
sendSetpoint(2);
})

function update_ui() {
const lat = FC.GPS_DATA.lat / 10000000;
const lon = FC.GPS_DATA.lon / 10000000;
Expand Down Expand Up @@ -385,5 +523,5 @@ gps.cleanup = function (callback) {

TABS.gps = gps;
export {
gps,
gps, pos_set
};
3 changes: 2 additions & 1 deletion src/js/tabs/onboard_logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ onboard_logging.initialize = function (callback) {
} else {
buffer.push(mspHelper.REBOOT_TYPES.MSC);
}
MSP.send_message(MSPCodes.MSP_SET_REBOOT, buffer, false);
MSP.send_message(MSPCodes.MSP_SET_REBOOT, buffer, false); // stuff happening here
});
}

Expand Down Expand Up @@ -370,6 +370,7 @@ onboard_logging.initialize = function (callback) {
{ text: "INDI" },
{ text: "Position"},
{ text: "EKF"},
{ text: "Learner"},
];

let fieldsMask = FC.BLACKBOX.blackboxDisabledMask;
Expand Down
Loading

0 comments on commit 2cd1922

Please sign in to comment.