Scripting
Overview
GWv4 features powerful scripting capabilities for automating calibration tasks and creating user interfaces.
This chapter provides a reference for scripting facilities.
// Inertial Measurement Unit
class ImuChannel {
constructor(name) {
this.channel = ecu.channel(name);
}
get value() {
return this.channel.value;
}
get squared() {
let v = this.value;
return v * v;
}
}
const imu = {
x: new ImuChannel("Acceleration x axis"),
y: new ImuChannel("Acceleration y axis"),
z: new ImuChannel("Acceleration z axis"),
get squaredMagnitude(){
return this.x.squared + this.y.squared + this.z.squared;
},
get magnitude() {
return Math.sqrt(this.squaredMagnitude);
},
};
// Label onGetValue event
function onGetValue() {
return `${imu.magnitude} [${imu.x.channel.units}]`;
}