Skip to content

Commit

Permalink
Satisfy xo
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthijsBurgh committed Sep 12, 2024
1 parent 2cd798c commit ad6b584
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 27 deletions.
11 changes: 6 additions & 5 deletions lib/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ class Body {
this.grippers = {};

for (const [partName, part] of Object.entries(parameter_)) {
if (Object.prototype.hasOwnProperty.call(part, 'joint_names')) {
if (Object.hasOwn(part, 'joint_names')) { // eslint-disable-line no-use-extend-native/no-use-extend-native
this.jointNames[partName] = part.joint_names;
}

if (Object.prototype.hasOwnProperty.call(part, 'default_configurations')) {
if (Object.hasOwn(part, 'default_configurations')) { // eslint-disable-line no-use-extend-native/no-use-extend-native
this.defaultConfigurations[partName] = part.default_configurations;
}

if (Object.prototype.hasOwnProperty.call(part, 'ac_gripper')) {
if (Object.hasOwn(part, 'ac_gripper')) { // eslint-disable-line no-use-extend-native/no-use-extend-native
this.grippers[partName] = new ActionClient({
ros,
serverName: part.ac_gripper,
Expand Down Expand Up @@ -93,7 +93,7 @@ class Body {
sendGripperGoal(cmd) {
console.log('Robot body: gripper goal:', cmd);

if (!Object.prototype.hasOwnProperty.call(this.grippers, cmd.side)) {
if (!Object.hasOwn(this.grippers, cmd.side)) { // eslint-disable-line no-use-extend-native/no-use-extend-native
console.error(`Gripper command side must be one of [${Object.keys(this.grippers)}]. Right now, it is '${cmd.side}'`);
return;
}
Expand All @@ -120,7 +120,8 @@ class Body {
command: {
/* eslint camelcase:0 */
direction,
max_torque: 10},
max_torque: 10,
},
},
});

Expand Down
2 changes: 1 addition & 1 deletion lib/ed-robocup.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default class EdRobocup extends Ed {
}

create_walls(callback) {
callback = callback || _.noop;
callback ||= _.noop;
this.createWallsService.callService({}, () => {
callback();
});
Expand Down
24 changes: 12 additions & 12 deletions lib/ed.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Ed extends EventEmitter2 {
// update object
const oldObject = this.entities.get(id);

if (Object.prototype.hasOwnProperty.call(entity, 'pose')) {
if (Object.hasOwn(entity, 'pose')) { // eslint-disable-line no-use-extend-native/no-use-extend-native
const {position, quaternion} = parseEdPosition(entity.pose);
newObject.position = position;
newObject.quaternion = quaternion;
Expand All @@ -99,11 +99,11 @@ class Ed extends EventEmitter2 {
oldObject.quaternion && (newObject.quaternion = oldObject.quaternion);
}

if (Object.prototype.hasOwnProperty.call(entity, 'mesh')) {
if (Object.hasOwn(entity, 'mesh')) { // eslint-disable-line no-use-extend-native/no-use-extend-native
const {vertices, faces} = parseEdMesh(entity.mesh);
newObject.vertices = vertices;
newObject.faces = faces;
} else if (Object.prototype.hasOwnProperty.call(entity, 'convex_hull')) {
} else if (Object.hasOwn(entity, 'convex_hull')) { // eslint-disable-line no-use-extend-native/no-use-extend-native
const {vertices, faces} = parseEdConvexHull(entity.convex_hull);
newObject.vertices = vertices;
newObject.faces = faces;
Expand All @@ -116,24 +116,24 @@ class Ed extends EventEmitter2 {
this.entities.set(id, newObject);

// only queue full objects for update
const props = ['position', 'quaternion', 'vertices', 'faces'];
if (props.every(key => key in newObject)) {
const properties = ['position', 'quaternion', 'vertices', 'faces'];
if (properties.every(key => key in newObject)) {
update.push([newObject, oldObject]);
}
} else {
// add object

if (Object.prototype.hasOwnProperty.call(entity, 'pose')) {
if (Object.hasOwn(entity, 'pose')) { // eslint-disable-line no-use-extend-native/no-use-extend-native
const {position, quaternion} = parseEdPosition(entity.pose);
newObject.position = position;
newObject.quaternion = quaternion;
}

if (Object.prototype.hasOwnProperty.call(entity, 'mesh')) {
if (Object.hasOwn(entity, 'mesh')) { // eslint-disable-line no-use-extend-native/no-use-extend-native
const {vertices, faces} = parseEdMesh(entity.mesh);
newObject.vertices = vertices;
newObject.faces = faces;
} else if (Object.prototype.hasOwnProperty.call(entity, 'convex_hull')) {
} else if (Object.hasOwn(entity, 'convex_hull')) { // eslint-disable-line no-use-extend-native/no-use-extend-native
const {vertices, faces} = parseEdConvexHull(entity.convex_hull);
newObject.vertices = vertices;
newObject.faces = faces;
Expand All @@ -142,8 +142,8 @@ class Ed extends EventEmitter2 {
this.entities.set(id, newObject);

// only queue full objects for update
const props = ['position', 'quaternion', 'vertices', 'faces'];
if (props.every(key => key in newObject)) {
const properties = ['position', 'quaternion', 'vertices', 'faces'];
if (properties.every(key => key in newObject)) {
add.push(newObject);
}
}
Expand Down Expand Up @@ -192,8 +192,8 @@ function parseEdConvexHull(chull) {

// Calculate side triangles
for (let i = 0; i < chull.points.length; i++) {
const j = (i + 1) % chull.points.length;
faces.push([j * 2, (i * 2) + 1, i * 2], [j * 2, (j * 2) + 1, (i * 2) + 1]);
const i2 = (i + 1) % chull.points.length;
faces.push([i2 * 2, (i * 2) + 1, i * 2], [i2 * 2, (i2 * 2) + 1, (i * 2) + 1]);
}

return {vertices, faces};
Expand Down
22 changes: 14 additions & 8 deletions lib/hardware.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class Hardware extends EventEmitter2 {
* Public status API
*/
_status = defaultStatus;

get status() {
return this._status;
}
Expand All @@ -106,6 +107,7 @@ class Hardware extends EventEmitter2 {
}

_resetHardwareLater = debounce(this._resetHardware, HARDWARE_TIMEOUT);

_resetHardware() {
console.log('hardware message timeout');
this.status = defaultStatus;
Expand All @@ -118,11 +120,11 @@ class Hardware extends EventEmitter2 {
* > hardware.send_command('head', 'start')
*/
send_command(part, command) {
if (!Object.prototype.hasOwnProperty.call(hardwareIds, part)) {
if (!Object.hasOwn(hardwareIds, part)) { // eslint-disable-line no-use-extend-native/no-use-extend-native
throw new RangeError('Invalid part');
}

if (!Object.prototype.hasOwnProperty.call(commands, command)) {
if (!Object.hasOwn(commands, command)) { // eslint-disable-line no-use-extend-native/no-use-extend-native
throw new RangeError('Invalid command');
}

Expand All @@ -141,6 +143,7 @@ class Hardware extends EventEmitter2 {
* Public battery API
*/
_battery = null;

get battery() {
return this._battery;
}
Expand All @@ -160,6 +163,7 @@ class Hardware extends EventEmitter2 {
}

_resetBatteryLater = debounce(this._resetBattery, BATTERY_TIMEOUT);

_resetBattery() {
console.log('battery message timeout');
this.battery = null;
Expand All @@ -169,6 +173,7 @@ class Hardware extends EventEmitter2 {
* Public ebutton status API
*/
_ebuttons = null;

get ebuttons() {
return this._ebuttons;
}
Expand All @@ -189,6 +194,7 @@ class Hardware extends EventEmitter2 {
}

_resetEbuttonsLater = debounce(this._resetEbuttons, EBUTTONS_TIMEOUT);

_resetEbuttons() {
console.log('ebuttons message timeout');
this.ebuttons = null;
Expand Down Expand Up @@ -222,8 +228,8 @@ function diagnosticMessageToStatus(message) {

// return all possible actions for a hardware part
function getActions(name, part) {
const props = properties[name];
if (!props) {
const properties_ = properties[name];
if (!properties_) {
return null;
}

Expand All @@ -233,7 +239,7 @@ function getActions(name, part) {
const actions = {};

// only show the home action if homeable
if (props.homeable) {
if (properties_.homeable) {
actions.home = {
enabled: level === levels.IDLE,
warning: homed
Expand All @@ -243,8 +249,8 @@ function getActions(name, part) {

// always show start action
actions.start = {
enabled: level === levels.IDLE && (homed || !props.homeable_mandatory),
warning: props.homeable && !homed
enabled: level === levels.IDLE && (homed || !properties_.homeable_mandatory),
warning: properties_.homeable && !homed
? 'This part is not yet homed, Are you sure you want to proceed?' : false,
};

Expand All @@ -260,7 +266,7 @@ function getActions(name, part) {
};

// only show reset action if resetable
if (props.resetable) {
if (properties_.resetable) {
actions.reset = {
enabled: level === levels.ERROR,
};
Expand Down
4 changes: 3 additions & 1 deletion test/initialization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import chai from 'chai';
import sinonChai from 'sinon-chai';
import {stub} from 'sinon';
import {Ros} from 'roslib';
import {Base, Ed, Hardware, Head, Robot} from '../lib/index.js';
import {
Base, Ed, Hardware, Head, Robot,
} from '../lib/index.js';

chai.use(sinonChai);
chai.should();
Expand Down

0 comments on commit ad6b584

Please sign in to comment.