Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
ed653e8a37 | |||
31f91d4e24 | |||
8536126e23 |
@ -19,6 +19,5 @@ motors.stopAll()
|
||||
```cards
|
||||
motors.largeA.speed()
|
||||
motors.largeA.angle()
|
||||
motors.largeA.tacho()
|
||||
motors.largeA.clearCounts()
|
||||
```
|
@ -17,11 +17,11 @@ let tachoCount = 0;
|
||||
motors.largeA.reset()
|
||||
motors.largeA.run(50)
|
||||
pause(10000)
|
||||
tachoCount = motors.largeA.tacho()
|
||||
tachoCount = motors.largeA.angle()
|
||||
motors.largeA.clearCounts()
|
||||
motors.largeA.run(50)
|
||||
pause(10000)
|
||||
if (tachoCount == motors.largeA.tacho()) {
|
||||
if (tachoCount == motors.largeA.angle()) {
|
||||
brick.showString("Motor turns equal.", 1)
|
||||
} else {
|
||||
brick.showString("Motor turns NOT equal.", 1)
|
||||
|
@ -1,48 +0,0 @@
|
||||
# tacho
|
||||
|
||||
Get the current number of degress of rotation.
|
||||
|
||||
```sig
|
||||
motors.largeA.tacho()
|
||||
```
|
||||
|
||||
The motors that come with your @boardname@ have a way to detect their own turning motion. They count the amount of motor rotation in degrees. The motor will count each degree of angle rotation up to 360 degrees for a full rotation. As the motor continues to turn, the _tacho_ count keeps adding up the degrees even past one full rotation. So, if the motor makes 3 complete rotations, the count will be 1080.
|
||||
|
||||
The name _tacho_ comes from the first part of the word [tachometer](https://en.wikipedia.org/wiki/Tachometer) which is a device to measure how fast something is turning. The motor controller in the brick uses the tacho count to regulate the motor's speed.
|
||||
|
||||
## ~hint
|
||||
|
||||
**Measure RPM**
|
||||
|
||||
A standard way to know how fast a motor is turning is by measuring its _revolutions per minute_ (rpm). One revolution is the same thing as a rotation, or one turn. How do you measure rpm? Well, here's a simple way:
|
||||
|
||||
1. Record the current tacho count
|
||||
2. Run the motor for 60 seconds
|
||||
3. Get the tacho count again
|
||||
4. Subtract the first tacho count from the second one
|
||||
5. Divide that number by `360`
|
||||
|
||||
## ~
|
||||
|
||||
## Returns
|
||||
|
||||
* a [number](/types/number) which is the total count of degrees of rotation that the motor has turned since it was first started or reset.
|
||||
|
||||
## Example
|
||||
|
||||
Run the motor connected to port **A** at half speed for 5 seconds. Display the number of full rotations on the screen.
|
||||
|
||||
```blocks
|
||||
motors.largeA.run(50)
|
||||
pause(5000)
|
||||
motors.largeA.stop()
|
||||
brick.showString("Motor rotations:", 1)
|
||||
brick.showNumber(motors.largeA.tacho() / 360, 3)
|
||||
motors.largeA.run(50)
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[angle](/reference/motors/motor/tacho), [speed](/reference/motors/motor/speed),
|
||||
[set regulated](/reference/motors/motor/set-regulated),
|
||||
[reset](/reference/motors/motor/reset), [clear counts](/reference/motors/motor/clear-counts)
|
@ -16,6 +16,7 @@
|
||||
"ns.ts",
|
||||
"control.cpp",
|
||||
"control.ts",
|
||||
"eventcontext.ts",
|
||||
"serial.cpp",
|
||||
"serial.ts",
|
||||
"fieldeditors.ts"
|
||||
|
10
libs/base/shims.d.ts
vendored
10
libs/base/shims.d.ts
vendored
@ -102,14 +102,10 @@ declare namespace control {
|
||||
function millis(): int32;
|
||||
|
||||
/**
|
||||
* Run code when a registered event happens.
|
||||
* @param id the event compoent id
|
||||
* @param value the event value to match
|
||||
* Used internally
|
||||
*/
|
||||
//% weight=20 blockGap=8 blockId="control_on_event" block="on event|from %src|with value %value"
|
||||
//% blockExternalInputs=1
|
||||
//% help="control/on-event" flags.defl=16 shim=control::onEvent
|
||||
function onEvent(src: int32, value: int32, handler: () => void, flags?: int32): void;
|
||||
//% flags.defl=16 shim=control::internalOnEvent
|
||||
function internalOnEvent(src: int32, value: int32, handler: () => void, flags?: int32): void;
|
||||
|
||||
/**
|
||||
* Reset the device.
|
||||
|
@ -378,21 +378,6 @@ namespace motors {
|
||||
return getMotorData(this._port).count;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets motor tachometer count.
|
||||
* @param motor the port which connects to the motor
|
||||
*/
|
||||
//% blockId=motorTachoCount block="%motor|tacho"
|
||||
//% weight=69
|
||||
//% blockGap=8
|
||||
//% group="Counters"
|
||||
//% help=motors/motor/tacho
|
||||
tacho(): number {
|
||||
this.init();
|
||||
return getMotorData(this._port).tachoCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the motor count
|
||||
*/
|
||||
|
8
libs/screen/shims.d.ts
vendored
8
libs/screen/shims.d.ts
vendored
@ -23,14 +23,14 @@ declare interface Image {
|
||||
/**
|
||||
* Set pixel color
|
||||
*/
|
||||
//% shim=ImageMethods::set
|
||||
set(x: int32, y: int32, c: int32): void;
|
||||
//% shim=ImageMethods::setPixel
|
||||
setPixel(x: int32, y: int32, c: int32): void;
|
||||
|
||||
/**
|
||||
* Get a pixel color
|
||||
*/
|
||||
//% shim=ImageMethods::get
|
||||
get(x: int32, y: int32): int32;
|
||||
//% shim=ImageMethods::getPixel
|
||||
getPixel(x: int32, y: int32): int32;
|
||||
|
||||
/**
|
||||
* Fill entire image with a given color
|
||||
|
@ -5,7 +5,7 @@
|
||||
//% groups=["0.,","1#*"]
|
||||
function img(lits: any, ...args: any[]): Image { return null }
|
||||
|
||||
let screen = image.create(DAL.LCD_WIDTH, DAL.LCD_HEIGHT)
|
||||
const screen = image.create(DAL.LCD_WIDTH, DAL.LCD_HEIGHT)
|
||||
|
||||
namespace _screen_internal {
|
||||
//% shim=pxt::updateScreen
|
||||
@ -13,10 +13,9 @@ namespace _screen_internal {
|
||||
//% shim=pxt::updateStats
|
||||
function updateStats(msg: string): void { }
|
||||
|
||||
control.setupScreenRefresh(() => updateScreen(screen))
|
||||
|
||||
export function _stats(msg: string) {
|
||||
updateStats(msg)
|
||||
control.__screen.setupUpdate(() => updateScreen(screen))
|
||||
control.EventContext.onStats = function(msg: string) {
|
||||
updateStats(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-ev3",
|
||||
"version": "0.1.6",
|
||||
"version": "0.1.7",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "pxt-ev3",
|
||||
"version": "0.1.6",
|
||||
"version": "0.1.7",
|
||||
"description": "LEGO Mindstorms EV3 for Microsoft MakeCode",
|
||||
"private": true,
|
||||
"keywords": [
|
||||
@ -45,7 +45,7 @@
|
||||
"webfonts-generator": "^0.4.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-common-packages": "0.20.14",
|
||||
"pxt-common-packages": "0.20.28",
|
||||
"pxt-core": "3.5.11"
|
||||
},
|
||||
"scripts": {
|
||||
|
Reference in New Issue
Block a user