path-generator
Version:
A easy motion profile path generator
76 lines (75 loc) • 3.09 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var util_1 = require("../util");
var setpoint_1 = require("../motionProfiling/setpoint");
var HolonomicModifier = /** @class */ (function () {
function HolonomicModifier(pathConfig, trajectory) {
var _this = this;
this._xSetpoints = [];
this._ySetpoints = [];
this._zSetpoints = [];
this._coords = [];
this.pathConfig = pathConfig;
trajectory.splinesTrajectory.forEach(function (spline) {
var _a;
return (_a = _this._coords).push.apply(_a, spline.coords);
});
trajectory.turnsTrajectory.forEach(function (turn) {
var _a;
return (_a = _this._zSetpoints).push.apply(_a, turn.setpoints);
});
this.updateCoordAngle(0);
this._xSetpoints.push(new setpoint_1.default(this._coords[0].x));
this._ySetpoints.push(new setpoint_1.default(this._coords[0].y));
var length = Math.min(this._zSetpoints.length, this._coords.length);
for (var index = 1; index < length; index++) {
this._xSetpoints.push(this.getSetpoint(index, 'x', this._xSetpoints[index - 1].velocity));
this._ySetpoints.push(this.getSetpoint(index, 'y', this._ySetpoints[index - 1].velocity));
this.updateCoordAngle(index);
}
this._zSetpoints.splice(length);
this._coords.splice(length);
}
HolonomicModifier.prototype.updateCoordAngle = function (index) {
var robotAngle = util_1.distance2Angle(this._zSetpoints[index].position, this.pathConfig.radios);
this._coords[index].angle = this._zSetpoints[index].position = robotAngle;
};
HolonomicModifier.prototype.getSetpoint = function (index, key, lastVelocity) {
var setpoint = new setpoint_1.default();
var distance = this._coords[index][key] - this._coords[index - 1][key];
setpoint.position = this._coords[index][key];
setpoint.velocity = distance / this.pathConfig.robotLoopTime;
setpoint.acceleration = (setpoint.velocity - lastVelocity) / this.pathConfig.robotLoopTime;
return setpoint;
};
Object.defineProperty(HolonomicModifier.prototype, "xSetpoints", {
get: function () {
return this._xSetpoints;
},
enumerable: false,
configurable: true
});
Object.defineProperty(HolonomicModifier.prototype, "ySetpoints", {
get: function () {
return this._ySetpoints;
},
enumerable: false,
configurable: true
});
Object.defineProperty(HolonomicModifier.prototype, "zSetpoints", {
get: function () {
return this._zSetpoints;
},
enumerable: false,
configurable: true
});
Object.defineProperty(HolonomicModifier.prototype, "coords", {
get: function () {
return this._coords;
},
enumerable: false,
configurable: true
});
return HolonomicModifier;
}());
exports.default = HolonomicModifier;