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

1939 lines
84 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>EV3Motor - 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">EV3Motor</h1>
<section>
<header>
<h2>
EV3Motor
</h2>
<div class="class-description"><p>Manage power, direction, and timers for one EV3 motor.</p></div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="EV3Motor"><span class="type-signature"></span>new EV3Motor<span class="signature">(parent, index, type)</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Construct a EV3 Motor instance, which could be of type 'largeMotor' or
'mediumMotor'.</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="EV3.html">EV3</a></span>
</td>
<td class="description last"><p>the EV3 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>
<tr>
<td class="name"><code>type</code></td>
<td class="type">
<span class="param-type">string</span>
</td>
<td class="description last"><p>the type of motor (i.e. 'largeMotor' or 'mediumMotor').</p></td>
</tr>
</tbody>
</table>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id="_coastDelay"><span class="type-signature">(private) </span>_coastDelay<span class="type-signature"> :number</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>A delay, in milliseconds, to add to coasting, to make sure that a brake
first takes effect if one was sent.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">number</span>
</li>
</ul>
<h4 class="name" id="_commandID"><span class="type-signature">(private) </span>_commandID<span class="type-signature"> :number</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>An ID for the current coast command, to help override multiple coast
commands sent in succession.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">number</span>
</li>
</ul>
<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;clockwise&quot; or -1 for &quot;counterclockwise&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="EV3.html">EV3</a></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>The EV3 peripheral which owns this motor.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type"><a href="EV3.html">EV3</a></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 position, in the range [0,360].</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="_type"><span class="type-signature">(private) </span>_type<span class="type-signature"> :string</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>The type of EV3 motor this could be: 'largeMotor' or 'mediumMotor'.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">string</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="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="type"><span class="type-signature"></span>type<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h4 class="name" id="type"><span class="type-signature"></span>type<span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="_portMask"><span class="type-signature"></span>_portMask<span class="signature">(port)</span><span class="type-signature"> &rarr; {number}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Return a port value for the EV3 that is in the format for 'output bit field'
as 1/2/4/8, generally needed for motor ports, instead of the typical 0/1/2/3.
The documentation in the 'EV3 Firmware Developer Kit' for motor port arguments
is sometimes mistaken, but we believe motor ports are mostly addressed this way.</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>port</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last"><p>the port number to convert to an 'output bit field'.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>the converted port number.</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">number</span>
</dd>
</dl>
<h4 class="name" id="_runValues"><span class="type-signature"></span>_runValues<span class="signature">(run)</span><span class="type-signature"> &rarr; {array}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Generate motor run values for a given input.</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>run</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last"><p>run input.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>run values as a byte array.</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">array</span>
</dd>
</dl>
<h4 class="name" id="coast"><span class="type-signature"></span>coast<span class="signature">()</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Set the motor to coast.</p>
</div>
<h4 class="name" id="coastAfter"><span class="type-signature"></span>coastAfter<span class="signature">(time)</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Set the motor to coast after a specified amount of time.</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>time</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last"><p>the time in milliseconds.</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.
Found in the 'EV3 Firmware Developer Kit', page 56, at
https://education.lego.com/en-us/support/mindstorms-ev3/developer-kits.</p>
<p>Opcode arguments:
(Data8) LAYER Specify chain layer number [0 - 3]
(Data8) NOS Output bit field [0x00 0x0F]
(Data8) SPEED Power level, [-100 100]
(Data32) STEP1 Time in milliseconds for ramp up
(Data32) STEP2 Time in milliseconds for continues run
(Data32) STEP3 Time in milliseconds for ramp down
(Data8) BRAKE - Specify break level [0: Float, 1: Break]</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>
</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>