updated chassis (#250)
This commit is contained in:
parent
02b0716043
commit
8aa47f3d1e
@ -1,11 +1,10 @@
|
|||||||
{
|
{
|
||||||
|
"chassis": "A differential drive robot",
|
||||||
"chassis.Chassis": "A differential drive robot",
|
"chassis.Chassis": "A differential drive robot",
|
||||||
"chassis.Chassis.drive": "Makes a differential drive robot move with a given speed (cm/s) and rotation rate (deg/s)\nusing a unicycle model.",
|
"chassis.Chassis.drive": "Makes a differential drive robot move with a given speed (cm/s) and rotation rate (deg/s)\nusing a unicycle model.",
|
||||||
"chassis.Chassis.drive|param|rotationSpeed": "rotation of the robot around the center point, eg: 30",
|
"chassis.Chassis.drive|param|rotationSpeed": "rotation of the robot around the center point, eg: 30",
|
||||||
"chassis.Chassis.drive|param|speed": "speed of the center point between motors, eg: 10",
|
"chassis.Chassis.drive|param|speed": "speed of the center point between motors, eg: 10",
|
||||||
"chassis.Chassis.drive|param|value": "the amount of movement, eg: 2",
|
"chassis.Chassis.setBaseLength": "Sets the base length in centimeters",
|
||||||
"chassis.Chassis.setMotors": "Sets the motors used by the chassis, default is B+C",
|
"chassis.Chassis.setMotors": "Sets the motors used by the chassis, default is B+C",
|
||||||
"chassis.Chassis.setProperty": "Sets a property of the robot",
|
"chassis.Chassis.setWheelRadius": "Sets the wheel radius in centimeters"
|
||||||
"chassis.Chassis.setProperty|param|property": "the property to set",
|
|
||||||
"chassis.Chassis.setProperty|param|value": "the value to set"
|
|
||||||
}
|
}
|
@ -1,9 +1,8 @@
|
|||||||
{
|
{
|
||||||
"ChassisProperty.BaseLength|block": "base length (cm)",
|
|
||||||
"ChassisProperty.WheelRadius|block": "wheel radius (cm)",
|
|
||||||
"chassis.Chassis.drive|block": "drive %chassis|at %speed|cm/s|turning %rotationSpeed|deg/s",
|
"chassis.Chassis.drive|block": "drive %chassis|at %speed|cm/s|turning %rotationSpeed|deg/s",
|
||||||
|
"chassis.Chassis.setBaseLength|block": "set %chassis|base length to %cm|(cm)",
|
||||||
"chassis.Chassis.setMotors|block": "set %chassis|motors to %motors",
|
"chassis.Chassis.setMotors|block": "set %chassis|motors to %motors",
|
||||||
"chassis.Chassis.setProperty|block": "set %chassis|%property|to %value",
|
"chassis.Chassis.setWheelRadius|block": "set %chassis|wheel radius to %cm|(cm)",
|
||||||
"chassis|block": "chassis",
|
"chassis|block": "chassis",
|
||||||
"{id:category}Chassis": "Chassis"
|
"{id:category}Chassis": "Chassis"
|
||||||
}
|
}
|
@ -1,10 +1,7 @@
|
|||||||
enum ChassisProperty {
|
/**
|
||||||
//% block="wheel radius (cm)"
|
* A differential drive robot
|
||||||
WheelRadius,
|
*/
|
||||||
//% block="base length (cm)"
|
//% weight=50 color=#cf00cf
|
||||||
BaseLength
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace chassis {
|
namespace chassis {
|
||||||
/**
|
/**
|
||||||
* A differential drive robot
|
* A differential drive robot
|
||||||
@ -29,13 +26,17 @@ namespace chassis {
|
|||||||
* using a unicycle model.
|
* using a unicycle model.
|
||||||
* @param speed speed of the center point between motors, eg: 10
|
* @param speed speed of the center point between motors, eg: 10
|
||||||
* @param rotationSpeed rotation of the robot around the center point, eg: 30
|
* @param rotationSpeed rotation of the robot around the center point, eg: 30
|
||||||
* @param value the amount of movement, eg: 2
|
* @param distance
|
||||||
* @param unit
|
**/
|
||||||
*/
|
|
||||||
//% blockId=motorDrive block="drive %chassis|at %speed|cm/s|turning %rotationSpeed|deg/s"
|
//% blockId=motorDrive block="drive %chassis|at %speed|cm/s|turning %rotationSpeed|deg/s"
|
||||||
//% inlineInputMode=inline
|
//% inlineInputMode=inline
|
||||||
//% weight=95 blockGap=8
|
//% weight=95 blockGap=8
|
||||||
drive(speed: number, rotationSpeed: number, value: number = 0, unit: MoveUnit = MoveUnit.MilliSeconds) {
|
drive(speed: number, rotationSpeed: number, distance: number = 0) {
|
||||||
|
if (!speed) {
|
||||||
|
this.motors.stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// speed is expressed in %
|
// speed is expressed in %
|
||||||
const R = this.wheelRadius; // cm
|
const R = this.wheelRadius; // cm
|
||||||
const L = this.baseLength; // cm
|
const L = this.baseLength; // cm
|
||||||
@ -52,24 +53,28 @@ namespace chassis {
|
|||||||
const sr = vr / maxw * 100; // %
|
const sr = vr / maxw * 100; // %
|
||||||
const sl = vl / maxw * 100; // %
|
const sl = vl / maxw * 100; // %
|
||||||
|
|
||||||
this.motors.tank(sr, sl, value, unit)
|
// cm / (cm/s) = s
|
||||||
|
const seconds = distance / speed;
|
||||||
|
|
||||||
|
this.motors.tank(sr, sl, seconds, MoveUnit.Seconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a property of the robot
|
* Sets the wheel radius in centimeters
|
||||||
* @param property the property to set
|
* @param cm
|
||||||
* @param value the value to set
|
|
||||||
*/
|
*/
|
||||||
//% blockId=chassisSetProperty block="set %chassis|%property|to %value"
|
//% blockId=chassisSetWheelRadius block="set %chassis|wheel radius to %cm|(cm)"
|
||||||
//% blockGap=8
|
setWheelRadius(cm: number) {
|
||||||
//% weight=10
|
this.wheelRadius = cm;
|
||||||
setProperty(property: ChassisProperty, value: number) {
|
}
|
||||||
switch (property) {
|
|
||||||
case ChassisProperty.WheelRadius:
|
/**
|
||||||
this.wheelRadius = Math.max(0.1, value); break;
|
* Sets the base length in centimeters
|
||||||
case ChassisProperty.BaseLength:
|
* @param cm
|
||||||
this.baseLength = Math.max(0.1, value); break;
|
*/
|
||||||
}
|
//% blockId=chassisSetBaseLength block="set %chassis|base length to %cm|(cm)"
|
||||||
|
setBaseLength(cm: number) {
|
||||||
|
this.baseLength = cm;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -81,6 +86,10 @@ namespace chassis {
|
|||||||
setMotors(motors: motors.SynchedMotorPair) {
|
setMotors(motors: motors.SynchedMotorPair) {
|
||||||
this.motors = motors;
|
this.motors = motors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toString(): string {
|
||||||
|
return `chassis base ${this.baseLength}, wheel ${this.wheelRadius}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//% fixedInstance whenUsed
|
//% fixedInstance whenUsed
|
||||||
|
Loading…
Reference in New Issue
Block a user