refactor location_data check
parent
71e34593fb
commit
d9a79da520
|
@ -17,7 +17,7 @@ import {
|
|||
import { HotKeys } from "./hotkeys";
|
||||
import { ControlsPopup } from "./controls_popup";
|
||||
import { Content } from "./constants";
|
||||
import { catchErrors } from "./util";
|
||||
import { catchErrors, validBotLocationData } from "./util";
|
||||
import { Session } from "./session";
|
||||
import { BooleanSetting } from "./session_keys";
|
||||
import { getPathArray } from "./history";
|
||||
|
@ -101,6 +101,7 @@ export class App extends React.Component<AppProps, {}> {
|
|||
render() {
|
||||
const syncLoaded = this.isLoaded;
|
||||
const currentPage = getPathArray()[2];
|
||||
const { location_data, mcu_params } = this.props.bot.hardware;
|
||||
return <div className="app">
|
||||
<HotKeys dispatch={this.props.dispatch} />
|
||||
<NavBar
|
||||
|
@ -118,8 +119,8 @@ export class App extends React.Component<AppProps, {}> {
|
|||
<ControlsPopup
|
||||
dispatch={this.props.dispatch}
|
||||
axisInversion={this.props.axisInversion}
|
||||
botPosition={this.props.bot.hardware.location_data.position}
|
||||
mcuParams={this.props.bot.hardware.mcu_params} />}
|
||||
botPosition={validBotLocationData(location_data).position}
|
||||
mcuParams={mcu_params} />}
|
||||
</div>;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,12 @@ import { DirectionButton } from "./direction_button";
|
|||
import { homeAll } from "../devices/actions";
|
||||
import { JogMovementControlsProps } from "./interfaces";
|
||||
import { getDevice } from "../device";
|
||||
import { validBotLocationData } from "../util";
|
||||
|
||||
export class JogButtons extends React.Component<JogMovementControlsProps, {}> {
|
||||
render() {
|
||||
const { mcu_params } = this.props.bot.hardware;
|
||||
const { location_data, mcu_params } = this.props.bot.hardware;
|
||||
const botLocationData = validBotLocationData(location_data);
|
||||
const directionAxesProps = {
|
||||
x: {
|
||||
isInverted: this.props.x_axis_inverted,
|
||||
|
@ -15,7 +17,7 @@ export class JogButtons extends React.Component<JogMovementControlsProps, {}> {
|
|||
axisLength: (mcu_params.movement_axis_nr_steps_x || 0)
|
||||
/ (mcu_params.movement_step_per_mm_x || 1),
|
||||
negativeOnly: !!mcu_params.movement_home_up_x,
|
||||
position: this.props.bot.hardware.location_data.position.x
|
||||
position: botLocationData.position.x
|
||||
},
|
||||
y: {
|
||||
isInverted: this.props.y_axis_inverted,
|
||||
|
@ -24,7 +26,7 @@ export class JogButtons extends React.Component<JogMovementControlsProps, {}> {
|
|||
axisLength: (mcu_params.movement_axis_nr_steps_y || 0)
|
||||
/ (mcu_params.movement_step_per_mm_y || 1),
|
||||
negativeOnly: !!mcu_params.movement_home_up_y,
|
||||
position: this.props.bot.hardware.location_data.position.y
|
||||
position: botLocationData.position.y
|
||||
},
|
||||
z: {
|
||||
isInverted: this.props.z_axis_inverted,
|
||||
|
@ -33,7 +35,7 @@ export class JogButtons extends React.Component<JogMovementControlsProps, {}> {
|
|||
axisLength: (mcu_params.movement_axis_nr_steps_z || 0)
|
||||
/ (mcu_params.movement_step_per_mm_z || 1),
|
||||
negativeOnly: !!mcu_params.movement_home_up_z,
|
||||
position: this.props.bot.hardware.location_data.position.z
|
||||
position: botLocationData.position.z
|
||||
},
|
||||
};
|
||||
return <table className="jog-table" style={{ border: 0 }}>
|
||||
|
|
|
@ -9,12 +9,12 @@ import { StepSizeSelector } from "./step_size_selector";
|
|||
import { MustBeOnline } from "../devices/must_be_online";
|
||||
import { ToolTips } from "../constants";
|
||||
import { MoveProps, EncoderDisplay } from "./interfaces";
|
||||
import { Xyz, BotLocationData } from "../devices/interfaces";
|
||||
import { Xyz } from "../devices/interfaces";
|
||||
import { Popover, Position } from "@blueprintjs/core";
|
||||
import { AxisDisplayGroup } from "./axis_display_group";
|
||||
import { Session } from "../session";
|
||||
import { INVERSION_MAPPING, ENCODER_MAPPING } from "../devices/reducer";
|
||||
import { minFwVersionCheck } from "../util";
|
||||
import { minFwVersionCheck, validBotLocationData } from "../util";
|
||||
|
||||
export class Move extends React.Component<MoveProps, {}> {
|
||||
|
||||
|
@ -26,27 +26,23 @@ export class Move extends React.Component<MoveProps, {}> {
|
|||
(name: EncoderDisplay) => () => Session.invertBool(ENCODER_MAPPING[name]);
|
||||
|
||||
render() {
|
||||
const { firmware_version } = this.props.bot.hardware.informational_settings;
|
||||
const { x_axis_inverted, y_axis_inverted, z_axis_inverted } = this.props;
|
||||
const { raw_encoders, scaled_encoders } = this.props;
|
||||
const xBtnColor = x_axis_inverted ? "green" : "red";
|
||||
const yBtnColor = y_axis_inverted ? "green" : "red";
|
||||
const zBtnColor = z_axis_inverted ? "green" : "red";
|
||||
const rawBtnColor = raw_encoders ? "green" : "red";
|
||||
const scaledBtnColor = scaled_encoders ? "green" : "red";
|
||||
let locationData: BotLocationData;
|
||||
if (this.props.bot.hardware.location_data) {
|
||||
locationData = this.props.bot.hardware.location_data;
|
||||
} else {
|
||||
locationData = {
|
||||
position: { x: undefined, y: undefined, z: undefined },
|
||||
raw_encoders: { x: undefined, y: undefined, z: undefined },
|
||||
scaled_encoders: { x: undefined, y: undefined, z: undefined },
|
||||
};
|
||||
}
|
||||
const { location_data, informational_settings } = this.props.bot.hardware;
|
||||
const { firmware_version } = informational_settings;
|
||||
const { x_axis_inverted, y_axis_inverted, z_axis_inverted,
|
||||
raw_encoders, scaled_encoders } = this.props;
|
||||
|
||||
const btnColor = (flag: boolean) => { return flag ? "green" : "red"; };
|
||||
const xBtnColor = btnColor(x_axis_inverted);
|
||||
const yBtnColor = btnColor(y_axis_inverted);
|
||||
const zBtnColor = btnColor(z_axis_inverted);
|
||||
const rawBtnColor = btnColor(raw_encoders);
|
||||
const scaledBtnColor = btnColor(scaled_encoders);
|
||||
|
||||
const locationData = validBotLocationData(location_data);
|
||||
const motor_coordinates = locationData.position;
|
||||
const raw_encoders_data = locationData.raw_encoders;
|
||||
const scaled_encoders_data = locationData.scaled_encoders;
|
||||
|
||||
const scaled_encoder_label =
|
||||
minFwVersionCheck(firmware_version, "5.0.5")
|
||||
? "Scaled Encoder (mm)"
|
||||
|
|
|
@ -9,11 +9,13 @@ import { history } from "../../history";
|
|||
import { AxisInputBox } from "../../controls/axis_input_box";
|
||||
import { isNumber } from "lodash";
|
||||
import { Actions } from "../../constants";
|
||||
import { validBotLocationData } from "../../util/util";
|
||||
|
||||
export function mapStateToProps(props: Everything) {
|
||||
return {
|
||||
chosenLocation: props.resources.consumers.farm_designer.chosenLocation,
|
||||
currentBotLocation: props.bot.hardware.location_data.position,
|
||||
currentBotLocation:
|
||||
validBotLocationData(props.bot.hardware.location_data).position,
|
||||
dispatch: props.dispatch,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -6,10 +6,10 @@ import {
|
|||
joinToolsAndSlot,
|
||||
selectAllPeripherals
|
||||
} from "../resources/selectors";
|
||||
import { BotLocationData, StepsPerMmXY } from "../devices/interfaces";
|
||||
import { StepsPerMmXY } from "../devices/interfaces";
|
||||
import { isNumber } from "lodash";
|
||||
import * as _ from "lodash";
|
||||
import { minFwVersionCheck } from "../util";
|
||||
import { minFwVersionCheck, validBotLocationData } from "../util";
|
||||
|
||||
export function mapStateToProps(props: Everything) {
|
||||
|
||||
|
@ -21,17 +21,6 @@ export function mapStateToProps(props: Everything) {
|
|||
const { plantUUID } = props.resources.consumers.farm_designer.hoveredPlant;
|
||||
const hoveredPlant = plants.filter(x => x.uuid === plantUUID)[0];
|
||||
|
||||
const getBotLocationData = (): BotLocationData => {
|
||||
if (props.bot.hardware.location_data) {
|
||||
return props.bot.hardware.location_data;
|
||||
}
|
||||
return {
|
||||
position: { x: undefined, y: undefined, z: undefined },
|
||||
scaled_encoders: { x: undefined, y: undefined, z: undefined },
|
||||
raw_encoders: { x: undefined, y: undefined, z: undefined },
|
||||
};
|
||||
};
|
||||
|
||||
function stepsPerMmXY(): StepsPerMmXY {
|
||||
const {
|
||||
mcu_params, configuration, informational_settings
|
||||
|
@ -72,7 +61,7 @@ export function mapStateToProps(props: Everything) {
|
|||
toolSlots: joinToolsAndSlot(props.resources.index),
|
||||
hoveredPlant,
|
||||
plants,
|
||||
botLocationData: getBotLocationData(),
|
||||
botLocationData: validBotLocationData(props.bot.hardware.location_data),
|
||||
botMcuParams: props.bot.hardware.mcu_params,
|
||||
stepsPerMmXY: stepsPerMmXY(),
|
||||
peripherals,
|
||||
|
|
|
@ -13,7 +13,7 @@ import {
|
|||
} from "../resources/tagged_resources";
|
||||
import { edit } from "../api/crud";
|
||||
import { DropDownItem, NULL_CHOICE } from "../ui/index";
|
||||
import { BotPosition } from "../devices/interfaces";
|
||||
import { validBotLocationData } from "../util";
|
||||
|
||||
export function mapStateToProps(props: Everything): Props {
|
||||
const toolSlots = selectAllToolSlotPointers(props.resources.index);
|
||||
|
@ -67,13 +67,6 @@ export function mapStateToProps(props: Everything): Props {
|
|||
dispatch(edit(t, { tool_id }));
|
||||
};
|
||||
|
||||
const getBotPosition = (): BotPosition => {
|
||||
if (props.bot.hardware.location_data) {
|
||||
return props.bot.hardware.location_data.position;
|
||||
}
|
||||
return { x: undefined, y: undefined, z: undefined };
|
||||
};
|
||||
|
||||
return {
|
||||
toolSlots,
|
||||
tools,
|
||||
|
@ -84,7 +77,7 @@ export function mapStateToProps(props: Everything): Props {
|
|||
changeToolSlot,
|
||||
isActive,
|
||||
dispatch: _.noop,
|
||||
botPosition: getBotPosition()
|
||||
botPosition: validBotLocationData(props.bot.hardware.location_data).position
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import * as Util from "../util";
|
||||
import { times } from "lodash";
|
||||
import { validBotLocationData } from "../index";
|
||||
describe("util", () => {
|
||||
describe("safeStringFetch", () => {
|
||||
const data = {
|
||||
|
@ -153,4 +154,15 @@ describe("util", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("validBotLocationData()", () => {
|
||||
it("returns valid location_data object", () => {
|
||||
const result = validBotLocationData(undefined);
|
||||
expect(result).toEqual({
|
||||
position: { x: undefined, y: undefined, z: undefined },
|
||||
scaled_encoders: { x: undefined, y: undefined, z: undefined },
|
||||
raw_encoders: { x: undefined, y: undefined, z: undefined }
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -6,6 +6,7 @@ import { box } from "boxed_value";
|
|||
import { TaggedResource } from "../resources/tagged_resources";
|
||||
import { AxiosResponse } from "axios";
|
||||
import { history } from "../history";
|
||||
import { BotLocationData } from "../devices/interfaces";
|
||||
|
||||
// http://stackoverflow.com/a/901144/1064917
|
||||
// Grab a query string param by name, because react-router-redux doesn't
|
||||
|
@ -213,3 +214,15 @@ export function scrollToBottom(elementId: string) {
|
|||
// Wait for the new element height and scroll to the bottom.
|
||||
setTimeout(() => elToScroll.scrollTo(0, elToScroll.scrollHeight), 1);
|
||||
}
|
||||
|
||||
export function validBotLocationData(
|
||||
botLocationData: BotLocationData | undefined): BotLocationData {
|
||||
if (botLocationData) {
|
||||
return botLocationData;
|
||||
}
|
||||
return {
|
||||
position: { x: undefined, y: undefined, z: undefined },
|
||||
scaled_encoders: { x: undefined, y: undefined, z: undefined },
|
||||
raw_encoders: { x: undefined, y: undefined, z: undefined },
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue