PID support (#242)
* updated block definitions * updated dependency on common packages
This commit is contained in:
parent
5ddfcd5508
commit
057a1d66dc
25
libs/automation/_locales/automation-jsdoc-strings.json
Normal file
25
libs/automation/_locales/automation-jsdoc-strings.json
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
"automation": "Automation, process control and robotic controllers\r\n\nProcess control, automation, robotics AI",
|
||||||
|
"automation.Behavior": "A behavior",
|
||||||
|
"automation.Behavior.update": "Called on each behavior iteration even for suppresed behaviors",
|
||||||
|
"automation.Behavior.update|param|elapsed": "milli seconds since last call",
|
||||||
|
"automation.BehaviorManager": "A manager for behaviors",
|
||||||
|
"automation.BehaviorManager.add": "Adds a new behavior to the behavior manager",
|
||||||
|
"automation.BehaviorManager.add|param|behavior": "the behavior to add",
|
||||||
|
"automation.BehaviorManager.start": "Starts the behavior control loop",
|
||||||
|
"automation.BehaviorManager.stop": "Stops the execution loop",
|
||||||
|
"automation.PIDController.compute": "Computes the output based on the system state",
|
||||||
|
"automation.PIDController.setControlSaturation": "Sets the control saturation values",
|
||||||
|
"automation.PIDController.setControlSaturation|param|high": "highest control value, eg: 100",
|
||||||
|
"automation.PIDController.setControlSaturation|param|low": "lowest control value, eg: -100",
|
||||||
|
"automation.PIDController.setDerivativeFilter": "Sets the derivative filter gain",
|
||||||
|
"automation.PIDController.setDerivativeFilter|param|N": "the filter gain, eg:10",
|
||||||
|
"automation.PIDController.setGains": "Sets the PID gains",
|
||||||
|
"automation.PIDController.setGains|param|b": "setpoint weight, eg: 0.9",
|
||||||
|
"automation.PIDController.setGains|param|kd": "derivative gain",
|
||||||
|
"automation.PIDController.setGains|param|ki": "integral gain",
|
||||||
|
"automation.PIDController.setGains|param|kp": "proportional gain",
|
||||||
|
"automation.PIDController.setPoint": "Updates the desired setpoint",
|
||||||
|
"automation.addBehavior": "Adds the behavior and starts it",
|
||||||
|
"automation.addBehavior|param|behavior": "a behavior"
|
||||||
|
}
|
12
libs/automation/_locales/automation-strings.json
Normal file
12
libs/automation/_locales/automation-strings.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"automation.PIDController.compute|block": "%pid|compute for timestep %timestep|(s) at state %y",
|
||||||
|
"automation.PIDController.setControlSaturation|block": "set %pid|control saturation from %low|to %high",
|
||||||
|
"automation.PIDController.setDerivativeFilter|block": "set %pid|derivative filter %N",
|
||||||
|
"automation.PIDController.setGains|block": "set %pid|gains kp %kp|ki %ki|kd %kd",
|
||||||
|
"automation.PIDController.setPoint|block": "set %pid|point to %ysp",
|
||||||
|
"automation.addBehavior|block": "add behavior %behavior",
|
||||||
|
"automation|block": "automation",
|
||||||
|
"{id:category}Automation": "Automation",
|
||||||
|
"{id:group}Behaviors": "Behaviors",
|
||||||
|
"{id:group}PID": "PID"
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"additionalFilePath": "../../node_modules/pxt-common-packages/libs/behaviors",
|
"additionalFilePath": "../../node_modules/pxt-common-packages/libs/automation",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"core": "file:../ev3"
|
"ev3": "file:../ev3"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"behaviors": "Behavior drive blocks",
|
|
||||||
"behaviors.Behavior": "A behavior",
|
|
||||||
"behaviors.BehaviorManager": "A manager for behaviors",
|
|
||||||
"behaviors.BehaviorManager.add": "Adds a new behavior to the behavior manager",
|
|
||||||
"behaviors.BehaviorManager.add|param|behavior": "the behavior to add",
|
|
||||||
"behaviors.BehaviorManager.start": "Starts the behavior control loop",
|
|
||||||
"behaviors.BehaviorManager.stop": "Stops the execution loop",
|
|
||||||
"behaviors.addBehavior": "Adds the behavior and starts it",
|
|
||||||
"behaviors.addBehavior|param|behavior": "a behavior",
|
|
||||||
"behaviors.avoidCrash": "A behavior that stops all motors if the sensor distance get too short",
|
|
||||||
"behaviors.driveForward": "A behavior that turns on the motors to the specified speed",
|
|
||||||
"behaviors.driveForward|param|motors": "@param speed the desired speed, eg: 50"
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"behaviors.addBehavior|block": "add behavior %behavior",
|
|
||||||
"behaviors.avoidCrash|block": "avoid crash using %ultrasonic",
|
|
||||||
"behaviors.driveForward|block": "drive %motors|forward at %speed=motorSpeedPicker|%",
|
|
||||||
"behaviors|block": "behaviors",
|
|
||||||
"{id:category}Behaviors": "Behaviors"
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
namespace behaviors {
|
|
||||||
class AvoidCrashBehavior extends behaviors.Behavior {
|
|
||||||
private ultrasonic: sensors.UltraSonicSensor;
|
|
||||||
constructor(ultrasonic: sensors.UltraSonicSensor) {
|
|
||||||
super();
|
|
||||||
this.ultrasonic = ultrasonic;
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldRun(): boolean {
|
|
||||||
return this.ultrasonic.distance() < 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
run(): void {
|
|
||||||
motors.stopAllMotors();
|
|
||||||
this.active = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A behavior that stops all motors if the sensor distance get too short
|
|
||||||
*/
|
|
||||||
//% blockId=behaviorsAvoidCrash block="avoid crash using %ultrasonic"
|
|
||||||
export function avoidCrash(ultrasonic: sensors.UltraSonicSensor) : behaviors.Behavior {
|
|
||||||
return new AvoidCrashBehavior(ultrasonic);
|
|
||||||
}
|
|
||||||
|
|
||||||
class DriveForwardBehavior extends behaviors.Behavior {
|
|
||||||
private motors: motors.MotorBase;
|
|
||||||
private speed: number;
|
|
||||||
constructor(motors: motors.MotorBase, speed: number) {
|
|
||||||
super();
|
|
||||||
this.motors = motors;
|
|
||||||
this.speed = speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldRun(): boolean {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
run(): void {
|
|
||||||
this.motors.setSpeed(this.speed);
|
|
||||||
pauseUntil(() => !this.active);
|
|
||||||
this.motors.setSpeed(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A behavior that turns on the motors to the specified speed
|
|
||||||
* @param motors
|
|
||||||
* @param speed the desired speed, eg: 50
|
|
||||||
*/
|
|
||||||
//% blockId=behaviorsDriveForward block="drive %motors|forward at %speed=motorSpeedPicker|%"
|
|
||||||
export function driveForward(motors: motors.MotorBase, speed: number): behaviors.Behavior {
|
|
||||||
return new DriveForwardBehavior(motors, speed);
|
|
||||||
}
|
|
||||||
}
|
|
@ -44,7 +44,7 @@
|
|||||||
"webfonts-generator": "^0.4.0"
|
"webfonts-generator": "^0.4.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pxt-common-packages": "0.15.6",
|
"pxt-common-packages": "0.15.7",
|
||||||
"pxt-core": "3.0.11"
|
"pxt-core": "3.0.11"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
"libs/storage",
|
"libs/storage",
|
||||||
"libs/datalog",
|
"libs/datalog",
|
||||||
"libs/tests",
|
"libs/tests",
|
||||||
"libs/behaviors"
|
"libs/automation"
|
||||||
],
|
],
|
||||||
"simulator": {
|
"simulator": {
|
||||||
"autoRun": true,
|
"autoRun": true,
|
||||||
|
Loading…
Reference in New Issue
Block a user