easy-scratch/doc/scratch-vm/BoostMotor.html

2641 lines
88 KiB
HTML
Raw Normal View History

2025-02-12 12:27:32 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>BoostMotor - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
<script src="scripts/nav.js" defer></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav >
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="-_StackFrame.html">_StackFrame</a><ul class='methods'><li data-type='method'><a href="-_StackFrame.html#.create">create</a></li><li data-type='method'><a href="-_StackFrame.html#.release">release</a></li><li data-type='method'><a href="-_StackFrame.html#reset">reset</a></li><li data-type='method'><a href="-_StackFrame.html#reuse">reuse</a></li></ul></li><li><a href="BLE.html">BLE</a><ul class='methods'><li data-type='method'><a href="BLE.html#connectPeripheral">connectPeripheral</a></li><li data-type='method'><a href="BLE.html#didReceiveCall">didReceiveCall</a></li><li data-type='method'><a href="BLE.html#disconnect">disconnect</a></li><li data-type='method'><a href="BLE.html#handleDisconnectError">handleDisconnectError</a></li><li data-type='method'><a href="BLE.html#isConnected">isConnected</a></li><li data-type='method'><a href="BLE.html#read">read</a></li><li data-type='method'><a href="BLE.html#requestPeripheral">requestPeripheral</a></li><li data-type='method'><a href="BLE.html#startNotifications">startNotifications</a></li><li data-type='method'><a href="BLE.html#write">write</a></li></ul></li><li><a href="BlockCached.html">BlockCached</a></li><li><a href="Blocks.html">Blocks</a><ul class='methods'><li data-type='method'><a href="Blocks.html#_addScript">_addScript</a></li><li data-type='method'><a href="Blocks.html#_deleteScript">_deleteScript</a></li><li data-type='method'><a href="Blocks.html#_getBackdropField">_getBackdropField</a></li><li data-type='method'><a href="Blocks.html#_getBlockParams">_getBlockParams</a></li><li data-type='method'><a href="Blocks.html#_getCostumeField">_getCostumeField</a></li><li data-type='method'><a href="Blocks.html#_getCustomBlockInternal">_getCustomBlockInternal</a></li><li data-type='method'><a href="Blocks.html#_getSoundField">_getSoundField</a></li><li data-type='method'><a href="Blocks.html#_getSpriteField">_getSpriteField</a></li><li data-type='method'><a href="Blocks.html#blocklyListen">blocklyListen</a></li><li data-type='method'><a href="Blocks.html#blockToXML">blockToXML</a></li><li data-type='method'><a href="Blocks.html#changeBlock">changeBlock</a></li><li data-type='method'><a href="Blocks.html#createBlock">createBlock</a></li><li data-type='method'><a href="Blocks.html#deleteBlock">deleteBlock</a></li><li data-type='method'><a href="Blocks.html#emitProjectChanged">emitProjectChanged</a></li><li data-type='method'><a href="Blocks.html#getAllVariableAndListReferences">getAllVariableAndListReferences</a></li><li data-type='method'><a href="Blocks.html#getBlock">getBlock</a></li><li data-type='method'><a href="Blocks.html#getBranch">getBranch</a></li><li data-type='method'><a href="Blocks.html#getFields">getFields</a></li><li data-type='method'><a href="Blocks.html#getInputs">getInputs</a></li><li data-type='method'><a href="Blocks.html#getMutation">getMutation</a></li><li data-type='method'><a href="Blocks.html#getNextBlock">getNextBlock</a></li><li data-type='method'><a href="Blocks.html#getOpcode">getOpcode</a></li><li data-type='method'><a href="Blocks.html#getProcedureDefinition">getProcedureDefinition</a></li><li data-type='method'><a href="Blocks.html#getProcedureParamNamesAndIds">getProcedureParamNamesAndIds</a></li><li data-type='method'><a href="Blocks.html#getProcedureParamNamesIdsAndDefaults">getProcedureParamNamesIdsAndDefaults</a></li><li data-type='method'><a href="Blocks.html#getScripts">getScripts</a></li><li data-type='method'><a href="Blocks.html#getTopLevelScript">getTopLevelScript</a></li><li data-type='method'><a href="Blocks.html#moveBlock">moveBlock</a></li><li data-type='method'><a href="Blocks.html#mutationToXML">mutationToXML</a></li><li data-type='method'><a href="Blocks.html#resetCache">resetCache</a></li><li data-type='method'><a href="Blocks.html#runAllMonitored">runAllMonitored</a></li><li data-type='method'><a href="Blocks.html#toXML">toXML</a></li><li data-type='method'><a href="Blocks.html#updateAssetName">updateAssetName</a></li><li data-type='method'><a href
</nav>
<div id="main">
<h1 class="page-title">BoostMotor</h1>
<section>
<header>
<h2>
BoostMotor
</h2>
<div class="class-description"><p>Manage power, direction, position, and timers for one Boost motor.</p></div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="BoostMotor"><span class="type-signature"></span>new BoostMotor<span class="signature">(parent, index)</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Construct a Boost Motor instance.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>parent</code></td>
<td class="type">
<span class="param-type"><a href="Boost.html">Boost</a></span>
</td>
<td class="description last"><p>the Boost peripheral which owns this motor.</p></td>
</tr>
<tr>
<td class="name"><code>index</code></td>
<td class="type">
<span class="param-type">int</span>
</td>
<td class="description last"><p>the zero-based index of this motor on its parent peripheral.</p></td>
</tr>
</tbody>
</table>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id="_direction"><span class="type-signature">(private) </span>_direction<span class="type-signature"> :number</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>This motor's current direction: 1 for &quot;this way&quot; or -1 for &quot;that way&quot;</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">number</span>
</li>
</ul>
<h4 class="name" id="_index"><span class="type-signature">(private) </span>_index<span class="type-signature"> :int</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>The zero-based index of this motor on its parent peripheral.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">int</span>
</li>
</ul>
<h4 class="name" id="_parent"><span class="type-signature">(private) </span>_parent<span class="type-signature"> :<a href="Boost.html">Boost</a></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>The Boost peripheral which owns this motor.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type"><a href="Boost.html">Boost</a></span>
</li>
</ul>
<h4 class="name" id="_pendingDurationTimeoutDelay"><span class="type-signature">(private) </span>_pendingDurationTimeoutDelay<span class="type-signature"> :number</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>The delay/duration of the pending duration timeout.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">number</span>
</li>
</ul>
<h4 class="name" id="_pendingDurationTimeoutId"><span class="type-signature">(private) </span>_pendingDurationTimeoutId<span class="type-signature"> :Object</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>If the motor has been turned on or is actively braking for a specific duration, this is the timeout ID for
the end-of-action handler. Cancel this when changing plans.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Object</span>
</li>
</ul>
<h4 class="name" id="_pendingDurationTimeoutStartTime"><span class="type-signature">(private) </span>_pendingDurationTimeoutStartTime<span class="type-signature"> :number</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>The starting time for the pending duration timeout.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">number</span>
</li>
</ul>
<h4 class="name" id="_pendingRotationDestination"><span class="type-signature">(private) </span>_pendingRotationDestination<span class="type-signature"> :number</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>The target position of a turn-based command.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">number</span>
</li>
</ul>
<h4 class="name" id="_pendingRotationPromise"><span class="type-signature">(private) </span>_pendingRotationPromise<span class="type-signature"> :Object</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>If the motor has been turned on run for a specific rotation, this is the function
that will be called once Scratch VM gets a notification from the Move Hub.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Object</span>
</li>
</ul>
<h4 class="name" id="_position"><span class="type-signature">(private) </span>_position<span class="type-signature"> :number</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>This motor's current relative position</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">number</span>
</li>
</ul>
<h4 class="name" id="_power"><span class="type-signature">(private) </span>_power<span class="type-signature"> :number</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>This motor's current power level, in the range [0,100].</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">number</span>
</li>
</ul>
<h4 class="name" id="_status"><span class="type-signature">(private) </span>_status<span class="type-signature"> :boolean</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Is this motor currently moving?</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">boolean</span>
</li>
</ul>
<h4 class="name" id="direction"><span class="type-signature"></span>direction<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id="direction"><span class="type-signature"></span>direction<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id="pendingDurationTimeoutDelay"><span class="type-signature"></span>pendingDurationTimeoutDelay<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id="pendingDurationTimeoutStartTime"><span class="type-signature"></span>pendingDurationTimeoutStartTime<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id="pendingRotationDestination"><span class="type-signature"></span>pendingRotationDestination<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id="pendingRotationPromise"><span class="type-signature"></span>pendingRotationPromise<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id="pendingRotationPromise"><span class="type-signature"></span>pendingRotationPromise<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id="position"><span class="type-signature"></span>position<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id="position"><span class="type-signature"></span>position<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id="power"><span class="type-signature"></span>power<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id="power"><span class="type-signature"></span>power<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id="status"><span class="type-signature"></span>status<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id="status"><span class="type-signature"></span>status<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="_clearDurationTimeout"><span class="type-signature">(private) </span>_clearDurationTimeout<span class="signature">()</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Clear the motor action timeout, if any. Safe to call even when there is no pending timeout.</p>
</div>
<h4 class="name" id="_clearRotationState"><span class="type-signature">(private) </span>_clearRotationState<span class="signature">()</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Clear the motor states related to rotation-based commands, if any.
Safe to call even when there is no pending promise function.</p>
</div>
<h4 class="name" id="_setNewDurationTimeout"><span class="type-signature">(private) </span>_setNewDurationTimeout<span class="signature">(callback, delay)</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Set a new motor action timeout, after clearing an existing one if necessary.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>callback</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="description last"><p>to be called at the end of the timeout.</p></td>
</tr>
<tr>
<td class="name"><code>delay</code></td>
<td class="type">
<span class="param-type">int</span>
</td>
<td class="description last"><p>wait this many milliseconds before calling the callback.</p></td>
</tr>
</tbody>
</table>
<h4 class="name" id="_turnOn"><span class="type-signature">(private) </span>_turnOn<span class="signature">()</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Turn this motor on indefinitely</p>
</div>
<h4 class="name" id="turnOff"><span class="type-signature"></span>turnOff<span class="signature">(useLimiter<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Turn this motor off.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>useLimiter</code></td>
<td class="type">
<span class="param-type">boolean</span>
</td>
<td class="attributes">
&lt;optional><br>
</td>
<td class="default">
<code>true</code>
</td>
<td class="description last"><p>if true, use the rate limiter</p></td>
</tr>
</tbody>
</table>
<h4 class="name" id="turnOnFor"><span class="type-signature"></span>turnOnFor<span class="signature">(milliseconds)</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Turn this motor on for a specific duration.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>milliseconds</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last"><p>run the motor for this long.</p></td>
</tr>
</tbody>
</table>
<h4 class="name" id="turnOnForDegrees"><span class="type-signature"></span>turnOnForDegrees<span class="signature">(degrees, direction)</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Turn this motor on for a specific rotation in degrees.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>degrees</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last"><p>run the motor for this amount of degrees.</p></td>
</tr>
<tr>
<td class="name"><code>direction</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last"><p>rotate in this direction</p></td>
</tr>
</tbody>
</table>
<h4 class="name" id="turnOnForever"><span class="type-signature"></span>turnOnForever<span class="signature">()</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Turn this motor on indefinitely</p>
</div>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>
</body>
</html>