Compare commits

...

7 Commits

Author SHA1 Message Date
1d83d6c40e 0.0.97 2018-02-09 10:26:28 -08:00
53bff7b133 updated package lock 2018-02-09 10:26:20 -08:00
2f6ad3110a motor blocks with optional args (#290)
* motor blocks with optional args

* updated signatures

* added toggle mode

* adding annotations
2018-02-09 10:25:39 -08:00
22ce840181 Widget fixes (#316)
* Use bBox in motor slider

* Use setRate instead of setAngle in gyro widget
2018-02-08 16:55:23 -08:00
d8589ea98c Discussion note for gyro precsion (#317)
* Discussion note for gyro precsion

* Wrong sig
2018-02-08 15:06:08 -08:00
adb577547d 0.0.96 2018-02-08 12:53:17 -08:00
ab6290c76d Add blocky grid (#313) 2018-02-08 11:49:26 -08:00
8 changed files with 1113 additions and 1118 deletions

View File

@ -6,11 +6,11 @@ Get the current angle of the motor's rotation in degrees.
motors.largeA.angle()
```
When a motor is started for the first time, or after a reset, it's angle of rotation starts at `0` degrees. A complete rotation (a turn in a full circle) is `360` degrees. At `360` degrees, the motor angle gets set back to `0`. So, one and a half turns adds up to `540` degrees of total rotation but the motor only cares about the current angle from `0` degrees which is `180` degrees.
When a motor is started for the first time, or after a reset, it's angle of rotation starts at `0` degrees. A complete rotation (a turn in a full circle) is `360` degrees. At `360` degrees, the motor angle doesn't go back to `0` but keeps counting in degrees. So, one and a half turns adds up to `540` degrees of total rotation.
## Returns
* a [number](/types/number) which is the current angle of rotation for the motor. The value returned is the number of degrees from `0` to `359`.
* a [number](/types/number) which is the current angle of rotation for the motor.
## Example

View File

@ -223,9 +223,10 @@ namespace motors {
* @param value (optional) measured distance or rotation
* @param unit (optional) unit of the value
*/
//% blockId=motorSetSpeed block="set %motor|speed to %speed=motorSpeedPicker|%"
//% blockId=motorSetSpeed block="set %motor speed to %speed=motorSpeedPicker|\\%||for %value %unit"
//% weight=100 blockGap=8
//% group="Move"
//% expandableArgumentMode=toggle
//% help=motors/motor/set-speed
setSpeed(speed: number, value: number = 0, unit: MoveUnit = MoveUnit.MilliSeconds) {
this.init();
@ -495,10 +496,11 @@ namespace motors {
* @param value (optional) move duration or rotation
* @param unit (optional) unit of the value
*/
//% blockId=motorPairTank block="tank %motors|%speedLeft=motorSpeedPicker|%|%speedRight=motorSpeedPicker|%"
//% blockId=motorPairTank block="tank %motors %speedLeft=motorSpeedPicker|\\% %speedRight=motorSpeedPicker|\\%||for %value %unit"
//% weight=96 blockGap=8
//% inlineInputMode=inline
//% group="Move"
//% expandableArgumentMode=toggle
//% help=motors/synced/tank
tank(speedLeft: number, speedRight: number, value: number = 0, unit: MoveUnit = MoveUnit.MilliSeconds) {
this.init();
@ -521,11 +523,12 @@ namespace motors {
* @param value (optional) move duration or rotation
* @param unit (optional) unit of the value
*/
//% blockId=motorPairSteer block="steer %chassis|turn ratio %turnRatio=motorTurnRatioPicker|speed %speed=motorSpeedPicker|%"
//% blockId=motorPairSteer block="steer %chassis turn ratio %turnRatio=motorTurnRatioPicker speed %speed=motorSpeedPicker|\\%||for %value %unit"
//% weight=95
//% turnRatio.min=-200 turnRatio=200
//% inlineInputMode=inline
//% group="Move"
//% expandableArgumentMode=toggle
//% help=motors/synced/steer
steer(turnRatio: number, speed: number, value: number = 0, unit: MoveUnit = MoveUnit.MilliSeconds) {
this.init();

View File

@ -3,11 +3,35 @@
Get the current rotation angle of the gyro.
```sig
sensors.gyro2.rate()
sensors.gyro2.angle()
```
When the brick changes its position, it's moved in the direction of one of the axes used to measure three-dimensional space. Depending on where the gyro sensor is attached, it can measure the difference in angle from where it was before it moved. This angle is measured in degrees. The angle is the number of degrees rotated from where the gyro was last [reset](/reference/sensors/gyro/reset).
## ~hint
## Accuracy and calibration
Gyro sensors aren't perfectly accurate. Sometimes, because of temperature and changes in the way elecricity behaves in the sensor, the gyro returns a small error in it's measurement. This causes the gyro sensor to return an incorrect value for the amount of angle it detected. This might make your robot drive off course and not go to where you want it to.
### Drift
If you want to turn the tank or robot you built to the left by 45 degrees, you might run the motor on the right side until the gyro reported that you turned by 45 degrees. What if the gyro was getting an error of 4 degrees every time it measured an angle? You may have actually turned 49 degrees when you expected to turn 45 degrees. Well, that might not be too bad if you use the gyro's angle value only once. It's fine if you just wanted to turn and stop or drive a short distance in only that direction.
The problem is that when you need to read the angle measurement frequently, the amount of error in the angle measurement may continue to increase. If the sensor thought it moved by 45 degrees the first time instead of really 49 degrees, your second turn will put you at 98 degrees when the sensor said 90 degrees. If you want a robot to turn right 90 degrees and drive for 5 meters, it might actually turn 98 degrees and drive 0.7 meters off course before it stops. This error in the sensor's measurement is called _drift_.
### Time to reset
If errors in the angle values returned by the gyro sensor are making your project not work right, then it's time to **[reset](/reference/sensors/gyro/reset)**. A reset will return the gyro sensor's current angle value back to `0` and _calibrate_ for drift. Calibration is the process of finding out how much error there is in a sensor's measurement and then removing the error from the value returned to your program.
Are you using a gyro sensor in your project and need accuracy for your angle values? You should reset the gyro sensor at a regular intervals to improve precision in the values reported to your program.
### Handling imprecision
Unfortunately, the angle values returned from the [gyro sensor](https://education.lego.com/en-us/products/ev3-gyro-sensor-/45505) are going to have some inaccuracy even when calibrated. The error could be as muchs as 3 degrees in either direction of rotation (`3` or `-3` degrees). So, you need to decide how precise your angle measurments need to be and have your code handle the possiblity that angle values aren't always exact.
## ~
## Returns
* a [number](/types/number) that is the current angle of rotation in degrees.

2173
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "pxt-ev3",
"version": "0.0.95",
"version": "0.0.97",
"description": "LEGO Mindstorms EV3 for Microsoft MakeCode",
"private": true,
"keywords": [
@ -44,8 +44,8 @@
"webfonts-generator": "^0.4.0"
},
"dependencies": {
"pxt-common-packages": "0.18.1",
"pxt-core": "3.3.1"
"pxt-common-packages": "0.19.1",
"pxt-core": "3.4.1"
},
"scripts": {
"test": "node node_modules/pxt-core/built/pxt.js travis"

View File

@ -133,6 +133,11 @@
"extendEditor": true,
"disableBlockIcons": true,
"blocklyOptions": {
"grid": {
"spacing": 40,
"length": 2,
"colour": "#ddd"
}
},
"blockColors": {
"loops": "#58AB41",

View File

@ -86,9 +86,11 @@ namespace pxsim.visuals {
private prevVal: number;
private updateSliderValue(pt: SVGPoint, parent: SVGSVGElement, ev: MouseEvent) {
let cur = svg.cursorPoint(pt, parent, ev);
let bBox = this.content.getBoundingClientRect();
const coords = {
x: cur.x / this.scaleFactor - this.left / this.scaleFactor,
y: cur.y / this.scaleFactor - this.top / this.scaleFactor
x: cur.x / this.scaleFactor - bBox.left / this.scaleFactor,
y: cur.y / this.scaleFactor - bBox.top / this.scaleFactor
};
const radius = MotorSliderControl.SLIDER_RADIUS / 2;
const dx = coords.x - radius;

View File

@ -76,7 +76,7 @@ namespace pxsim.visuals {
let t = Math.max(0, Math.min(1, (width + bBox.left / this.scaleFactor - cur.x / this.scaleFactor) / width))
const state = this.state;
state.setAngle((1 - t) * (100));
state.setRate((1 - t) * (100));
}
}