Skip to content

Commit

Permalink
upgrade js packages; add flight data monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
bolandrm committed Jul 5, 2016
1 parent 58ed127 commit 5410c12
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ node_modules
dist
ui_js/.gitignore
.hgignore
npm-debug.log
1 change: 1 addition & 0 deletions src/battery_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void battery_monitor_update() {
battery_monitor_battery_voltage = battery_monitor_pin_voltage / (BATTERY_R2_VAL / (BATTERY_R1_VAL + BATTERY_R2_VAL));

if (battery_monitor_battery_voltage < 9.0) { // no battery connected
battery_monitor_battery_voltage = 0;
noTone(BATTERY_ALERT_BUZZER_PIN);
buzzer_on = false;

Expand Down
4 changes: 2 additions & 2 deletions src/flight_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#define RATE 0
#define STABILIZE 1

#define ARMED 1
#define UNARMED 0
#define ARMED 1

#define ANGLE_SAFETY_STOP false
#define ANGLE_SAFETY_STOP true
#define SAFE_ANGLE 60.0

void fc_init();
Expand Down
13 changes: 13 additions & 0 deletions src/serial_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define REQUEST_RC 3
#define REQUEST_MOTORS 4
#define REQUEST_RATE_PIDS 5
#define REQUEST_FLIGHT_DATA 6

#define SET_CONFIG 101

Expand All @@ -22,6 +23,7 @@
#include "flight_controller.h"
#include "motors.h"
#include "utils.h"
#include "battery_monitor.h"
#include <usb_serial.h>

void read_serial_data(uint8_t data);
Expand Down Expand Up @@ -262,6 +264,17 @@ void process_serial_data() {
break;
}

case REQUEST_FLIGHT_DATA:
packet_head(REQUEST_FLIGHT_DATA, 10);

output_uint8(fc_armed());
output_uint8(fc_mode());
output_uint32(imu_value_process_dt);
output_float32(battery_monitor_battery_voltage);

packet_tail();
break;

case SET_CONFIG:
if (data_received_length == sizeof(CONFIG)) {

Expand Down
4 changes: 2 additions & 2 deletions ui/app/components/MotorChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import _ from 'lodash'
import React from 'react'
import ReactDOM from 'react-dom'
import { observer } from 'mobx-react'
import { toJSON } from 'mobx'
import { toJS } from 'mobx'


@observer
class MotorChart extends React.Component {
render() {
const data = toJSON(this.props.data)
const data = toJS(this.props.data)
const motorPositions = ['fr', 'bl', 'fl', 'br']

return (
Expand Down
2 changes: 1 addition & 1 deletion ui/app/components/Toolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Toolbar extends React.Component {
render() {
return (
<div className='well toolbar'>
<ul className="nav nav-tabs">
<ul className={`nav nav-tabs ${serial.connected ? 'connected' : ''}`}>
{metaStore.tabData.map((tab, i) => {
return (
<li className={this.tabClass(tab.key)} key={i}>
Expand Down
31 changes: 24 additions & 7 deletions ui/app/components/TuningTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,40 @@ import serial from '../serial/serialManager'
@observer
class TuningTab extends React.Component {
componentDidMount() {
this.intervalID = setInterval(this.fetchData, 50)
}
this.intervalIDs = [
setInterval(() => {
serial.send(tuningTabStore.graph1.requestCode(), null, tuningTabStore.graph1.addSample)
serial.send(serial.codes.REQUEST_MOTORS, null, tuningTabStore.addMotorChartSample)
}, 50),

componentWillUnmount() {
clearInterval(this.intervalID)
setInterval(() => {
serial.send(serial.codes.REQUEST_FLIGHT_DATA, null, tuningTabStore.updateFlightControllerData)
}, 200),
]
}

fetchData = () => {
serial.send(tuningTabStore.graph1.requestCode(), null, tuningTabStore.graph1.addSample)
serial.send(serial.codes.REQUEST_MOTORS, null, tuningTabStore.addMotorChartSample)
componentWillUnmount() {
this.intervalIDs.forEach((id) => clearInterval(id))
}

render() {
return (
<div>
<LineGraph graph={tuningTabStore.graph1} />
<MotorChart data={tuningTabStore.motorChartValues} />
<div>
Mode: {tuningTabStore.flightData.mode}
<br />
{tuningTabStore.flightData.armed}
<br />
Battery: {tuningTabStore.flightData.batteryVoltage.toFixed(2)}v
<br />
Loop Time: {tuningTabStore.flightData.loopTime}μs
</div>
orientation,
calibration,
reboot,
test ping
</div>
)
}
Expand Down
1 change: 1 addition & 0 deletions ui/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'babel-polyfill'
import React from 'react'
import ReactDOM from 'react-dom'
import App from './components/app'
// import { useStrict } from 'mobx'

import './styles/app.scss'

Expand Down
15 changes: 14 additions & 1 deletion ui/app/serial/SerialReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,18 @@ class SerialReader {
case serialCodes.REQUEST_RATE_PIDS:
response = parseStruct(this.dataBuffer, structLayouts.ratePidData);
break;
case serialCodes.REQUEST_FLIGHT_DATA:
response = parseStruct(this.dataBuffer, structLayouts.flightData);
response = this.interpretFlightData(response)
break;
case serialCodes.INFO_SUCCESS:
console.log("controller responded with success!");
break;
case serialCodes.INFO_FAILURE:
console.log("controller responded with failure");
break;
default:
console.log(`unknown code ${this.code}`);
console.log(`unhandled code ${this.code}`);
}

this.dataReceived(this.code, response);
Expand All @@ -113,6 +117,15 @@ class SerialReader {
return;
console.log(text);
}

interpretFlightData(response) {
const FLIGHT_MODES = [ "rate", "stabilize" ]
const FLIGHT_ARMED_STATUS = [ "unarmed", "armed" ]

response.armed = FLIGHT_ARMED_STATUS[response.armed]
response.mode = FLIGHT_MODES[response.mode]
return response
}
}

export default SerialReader;
1 change: 1 addition & 0 deletions ui/app/serial/serialCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const REQUEST_GYRO_ACC = 2
export const REQUEST_RC = 3
export const REQUEST_MOTORS = 4
export const REQUEST_RATE_PIDS = 5
export const REQUEST_FLIGHT_DATA = 6

export const SET_CONFIG = 101

Expand Down
4 changes: 3 additions & 1 deletion ui/app/serial/serialManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SerialManager {
serialCodes.REQUEST_RC,
serialCodes.REQUEST_MOTORS,
serialCodes.REQUEST_RATE_PIDS,
serialCodes.REQUEST_FLIGHT_DATA,
]

constructor() {
Expand Down Expand Up @@ -106,7 +107,8 @@ class SerialManager {
}

_isDefaultDevice(device) {
return device.match(/usbmodem/)
//return device.match(/usbmodem/)
return device.match(/SLAB_USB/)
}

_findDefaultDevice(devices) {
Expand Down
2 changes: 1 addition & 1 deletion ui/app/serial/struct.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const dataTypes = {
int16: { type: 'Int16', byteSize: 2 },
uint16: { type: 'Uint16', byteSize: 2 },
int32: { type: 'Int32', byteSize: 4 },
// I uint32
uint32: { type: 'Uint32', byteSize: 4 },
// q int64
// Q uint64
f32: { type: 'Float32', byteSize: 4 },
Expand Down
7 changes: 7 additions & 0 deletions ui/app/serial/structLayouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ export const gyroAcc = [
[ "accelMaxValue", "f32" ]
]

export const flightData = [
[ "armed", "uint8" ],
[ "mode", "uint8" ],
[ "loopTime", "uint32" ],
[ "batteryVoltage", "f32" ],
]

export const motorData = [
[ "m1", "uint16" ],
[ "m2", "uint16" ],
Expand Down
4 changes: 2 additions & 2 deletions ui/app/stores/ConfigStore.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { observable, toJSON } from 'mobx'
import { observable, toJS } from 'mobx'
import serial from '../serial/serialManager'
import * as structLayouts from "../serial/structLayouts"
import { buildStruct } from '../serial/struct'
Expand All @@ -14,7 +14,7 @@ export default class ConfigStore {
}

plainData = () => {
return toJSON(this.data)
return toJS(this.data)
}

fetchConfig = () => {
Expand Down
6 changes: 6 additions & 0 deletions ui/app/stores/TuningTabStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { LineGraphStore } from './LineGraphStore'

export default class TuningTabStore {
@observable motorChartValues = { m1: 0, m2: 0, m3: 0, m4: 0 }
@observable flightData = {}

constructor() {
this.graph1 = new LineGraphStore()
this.flightData = { batteryVoltage: 0.0 }
}

addMotorChartSample = (sample) => {
Expand All @@ -22,4 +24,8 @@ export default class TuningTabStore {
this.motorChartValues[key] = value
})
}

updateFlightControllerData = (data) => {
this.flightData = data
}
}
6 changes: 6 additions & 0 deletions ui/app/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ button:focus {
.nav {
padding-left: 20px;
padding-top: 12px;

border-top: 2px solid $brand-primary;

&.connected {
border-top-color: $brand-success;
}
}
}

Expand Down
1 change: 0 additions & 1 deletion ui/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const appName = argv.name || argv.n || pkg.productName;
const shouldUseAsar = argv.asar || argv.a || false;
const shouldBuildAll = argv.all || false;


const DEFAULT_OPTS = {
dir: './',
name: appName,
Expand Down
12 changes: 6 additions & 6 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"babel-polyfill": "^6.3.14",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-react-hmre": "^1.0.1",
"babel-preset-react-hmre": "^1.1.1",
"chromedriver": "^2.19.0",
"cross-env": "^1.0.7",
"css-loader": "^0.23.1",
Expand All @@ -49,7 +49,7 @@
"minimist": "^1.2.0",
"node-libs-browser": ">= 0.4.0 <=0.6.0",
"node-sass": "^3.4.2",
"react-addons-test-utils": "^0.14.2",
"react-addons-test-utils": "^15.2.0",
"sass-loader": "^3.1.2",
"selenium-webdriver": "^2.48.2",
"sinon": "^1.17.2",
Expand All @@ -67,11 +67,11 @@
"electron-debug": "^0.5.1",
"font-awesome": "^4.4.0",
"lodash": "^4.5.0",
"mobx": "^2.0.0",
"mobx-react": "^3.0.0",
"mobx": "^2.3.3",
"mobx-react": "^3.4.0",
"moment": "^2.11.2",
"react": "^0.14.2",
"react-dom": "^0.14.2",
"react": "^15.2.0",
"react-dom": "^15.2.0",
"serialport": "^2.0.6"
},
"devEngines": {
Expand Down

0 comments on commit 5410c12

Please sign in to comment.