Generic Step Motor WebInterface - control a step motor using a Pololu A4983 driver from a webinterface (EXPERIMENTAL PROTOTYPE - just to be used as a proof-of-concept for a IoT talk, will not be updating this code so often)
Dependencies: EthernetNetIf RPCInterface mbed HTTPServer
index.html.cpp@0:8b3857d4ce02, 2012-04-16 (annotated)
- Committer:
- botdream
- Date:
- Mon Apr 16 09:41:53 2012 +0000
- Revision:
- 0:8b3857d4ce02
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
botdream | 0:8b3857d4ce02 | 1 | /* |
botdream | 0:8b3857d4ce02 | 2 | <html> |
botdream | 0:8b3857d4ce02 | 3 | <head> |
botdream | 0:8b3857d4ce02 | 4 | <script type="text/javascript"> |
botdream | 0:8b3857d4ce02 | 5 | function sendrequest(request_uri) |
botdream | 0:8b3857d4ce02 | 6 | { |
botdream | 0:8b3857d4ce02 | 7 | var xmlhttp; |
botdream | 0:8b3857d4ce02 | 8 | if(window.XMLHttpRequest) |
botdream | 0:8b3857d4ce02 | 9 | {// code for IE7+, Firefox, Chrome, Opera, Safari |
botdream | 0:8b3857d4ce02 | 10 | xmlhttp=new XMLHttpRequest(); |
botdream | 0:8b3857d4ce02 | 11 | } |
botdream | 0:8b3857d4ce02 | 12 | else |
botdream | 0:8b3857d4ce02 | 13 | {// code for IE6, IE5 |
botdream | 0:8b3857d4ce02 | 14 | xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); |
botdream | 0:8b3857d4ce02 | 15 | } |
botdream | 0:8b3857d4ce02 | 16 | xmlhttp.onreadystatechange=function() |
botdream | 0:8b3857d4ce02 | 17 | { |
botdream | 0:8b3857d4ce02 | 18 | if (xmlhttp.readyState==4 && xmlhttp.status==200) |
botdream | 0:8b3857d4ce02 | 19 | { |
botdream | 0:8b3857d4ce02 | 20 | <!-- document.getElementById("myDiv").innerHTML=xmlhttp.responseText; --> |
botdream | 0:8b3857d4ce02 | 21 | } |
botdream | 0:8b3857d4ce02 | 22 | } |
botdream | 0:8b3857d4ce02 | 23 | console.log(request_uri); |
botdream | 0:8b3857d4ce02 | 24 | xmlhttp.open("GET",request_uri,true); |
botdream | 0:8b3857d4ce02 | 25 | xmlhttp.send(); |
botdream | 0:8b3857d4ce02 | 26 | } |
botdream | 0:8b3857d4ce02 | 27 | |
botdream | 0:8b3857d4ce02 | 28 | function adjustvalues1(){ |
botdream | 0:8b3857d4ce02 | 29 | var dataval = document.getElementById("timevalue1").value; |
botdream | 0:8b3857d4ce02 | 30 | |
botdream | 0:8b3857d4ce02 | 31 | document.getElementById("timevalue2").value = dataval*1000; |
botdream | 0:8b3857d4ce02 | 32 | |
botdream | 0:8b3857d4ce02 | 33 | document.getElementById("timevalue3").value = dataval*1000*1000; |
botdream | 0:8b3857d4ce02 | 34 | } |
botdream | 0:8b3857d4ce02 | 35 | |
botdream | 0:8b3857d4ce02 | 36 | function adjustvalues2(){ |
botdream | 0:8b3857d4ce02 | 37 | var dataval = document.getElementById("timevalue2").value; |
botdream | 0:8b3857d4ce02 | 38 | |
botdream | 0:8b3857d4ce02 | 39 | document.getElementById("timevalue1").value = dataval/1000; |
botdream | 0:8b3857d4ce02 | 40 | |
botdream | 0:8b3857d4ce02 | 41 | document.getElementById("timevalue3").value = dataval*1000; |
botdream | 0:8b3857d4ce02 | 42 | } |
botdream | 0:8b3857d4ce02 | 43 | |
botdream | 0:8b3857d4ce02 | 44 | function adjustvalues3(){ |
botdream | 0:8b3857d4ce02 | 45 | var dataval = document.getElementById("timevalue3").value; |
botdream | 0:8b3857d4ce02 | 46 | |
botdream | 0:8b3857d4ce02 | 47 | document.getElementById("timevalue1").value = dataval/1000/1000; |
botdream | 0:8b3857d4ce02 | 48 | |
botdream | 0:8b3857d4ce02 | 49 | document.getElementById("timevalue2").value = dataval/1000; |
botdream | 0:8b3857d4ce02 | 50 | } |
botdream | 0:8b3857d4ce02 | 51 | |
botdream | 0:8b3857d4ce02 | 52 | function demo(){ |
botdream | 0:8b3857d4ce02 | 53 | // set timer to 100ms |
botdream | 0:8b3857d4ce02 | 54 | sendrequest('./rpc/delay/write%20'+(100/1000000)); |
botdream | 0:8b3857d4ce02 | 55 | |
botdream | 0:8b3857d4ce02 | 56 | // set direction 0 |
botdream | 0:8b3857d4ce02 | 57 | sendrequest('./rpc/direction/write%200'); |
botdream | 0:8b3857d4ce02 | 58 | |
botdream | 0:8b3857d4ce02 | 59 | // 360 º |
botdream | 0:8b3857d4ce02 | 60 | sendrequest('./rpc/nsteps/run%20'+(1*64*50)); |
botdream | 0:8b3857d4ce02 | 61 | |
botdream | 0:8b3857d4ce02 | 62 | // set direction 1 |
botdream | 0:8b3857d4ce02 | 63 | sendrequest('./rpc/direction/write%201'); |
botdream | 0:8b3857d4ce02 | 64 | |
botdream | 0:8b3857d4ce02 | 65 | // set timer to 200ms |
botdream | 0:8b3857d4ce02 | 66 | sendrequest('./rpc/delay/write%20'+(200/1000000)); |
botdream | 0:8b3857d4ce02 | 67 | |
botdream | 0:8b3857d4ce02 | 68 | // 360 º |
botdream | 0:8b3857d4ce02 | 69 | sendrequest('./rpc/nsteps/run%20'+(1*64*50)); |
botdream | 0:8b3857d4ce02 | 70 | } |
botdream | 0:8b3857d4ce02 | 71 | </script> |
botdream | 0:8b3857d4ce02 | 72 | </head> |
botdream | 0:8b3857d4ce02 | 73 | <body> |
botdream | 0:8b3857d4ce02 | 74 | |
botdream | 0:8b3857d4ce02 | 75 | <div id="myDiv"><h2>Step Motor HTTP REST (RPC) interface.</h2></div> |
botdream | 0:8b3857d4ce02 | 76 | <button type="button" onclick="sendrequest('./rpc/enable/write%201')">Start Autorun</button> |
botdream | 0:8b3857d4ce02 | 77 | <button type="button" onclick="sendrequest('./rpc/enable/write%200')">Stop Autorun</button> |
botdream | 0:8b3857d4ce02 | 78 | <!--<button type="button" onclick="sendrequest('./rpc/releasecmd')">Release Motor CMD</button>--> |
botdream | 0:8b3857d4ce02 | 79 | <br> |
botdream | 0:8b3857d4ce02 | 80 | <button type="button" onclick="sendrequest('./rpc/sleepmode/run%2001')">Sleep</button> |
botdream | 0:8b3857d4ce02 | 81 | <button type="button" onclick="sendrequest('./rpc/sleepmode/run%2000')">Wake up</button> |
botdream | 0:8b3857d4ce02 | 82 | <br> |
botdream | 0:8b3857d4ce02 | 83 | <button type="button" onclick="sendrequest('./rpc/stepmode/run%201')">MicroStep Mode</button> |
botdream | 0:8b3857d4ce02 | 84 | <button type="button" onclick="sendrequest('./rpc/stepmode/run%200')">FullStep Mode</button> |
botdream | 0:8b3857d4ce02 | 85 | <br> |
botdream | 0:8b3857d4ce02 | 86 | <button type="button" onclick="sendrequest('./rpc/direction/write%200')">Normal Direction</button> |
botdream | 0:8b3857d4ce02 | 87 | <button type="button" onclick="sendrequest('./rpc/direction/write%201')">Inverse Direction</button> |
botdream | 0:8b3857d4ce02 | 88 | <br> |
botdream | 0:8b3857d4ce02 | 89 | <input type="text" id="timevalue1" name="timevalue1" onKeyUp="adjustvalues1();" maxlength="10" size="10" value="0.001" /> |
botdream | 0:8b3857d4ce02 | 90 | <button type="button" onclick="sendrequest('./rpc/delay/write%20'+timevalue.value)">Time value (Seconds)</button> |
botdream | 0:8b3857d4ce02 | 91 | <br> |
botdream | 0:8b3857d4ce02 | 92 | <input type="text" id="timevalue2" name="timevalue2" onKeyUp="adjustvalues2()" maxlength="10" size="10" value="1" /> |
botdream | 0:8b3857d4ce02 | 93 | <button type="button" onclick="sendrequest('./rpc/delay/write%20'+(timevalue2.value/1000))">Time value (mili-Seconds)</button> |
botdream | 0:8b3857d4ce02 | 94 | <br> |
botdream | 0:8b3857d4ce02 | 95 | <input type="text" id="timevalue3" name="timevalue3" onKeyUp="adjustvalues3()" maxlength="10" size="10" value="1000" /> |
botdream | 0:8b3857d4ce02 | 96 | <button type="button" onclick="sendrequest('./rpc/delay/write%20'+(timevalue3.value/1000000))">Time value (micro-Seconds)</button> |
botdream | 0:8b3857d4ce02 | 97 | <br> |
botdream | 0:8b3857d4ce02 | 98 | <br> |
botdream | 0:8b3857d4ce02 | 99 | <input type="text" id="nmicrosteps" name="nmicrosteps" maxlength="10" size="10" value="1" /> |
botdream | 0:8b3857d4ce02 | 100 | <button type="button" onclick="sendrequest('./rpc/nsteps/run%20'+nmicrosteps.value)">Manual MicroSteps</button> |
botdream | 0:8b3857d4ce02 | 101 | <br> |
botdream | 0:8b3857d4ce02 | 102 | <input type="text" id="nsteps" name="nsteps" maxlength="10" size="10" value="1" /> |
botdream | 0:8b3857d4ce02 | 103 | <button type="button" onclick="sendrequest('./rpc/nsteps/run%20'+(nsteps.value*16))">Manual Steps</button> |
botdream | 0:8b3857d4ce02 | 104 | <br> |
botdream | 0:8b3857d4ce02 | 105 | <input type="text" id="nsteps360" name="nsteps360" maxlength="10" size="10" value="1" /> |
botdream | 0:8b3857d4ce02 | 106 | <button type="button" onclick="sendrequest('./rpc/nsteps/run%20'+(nsteps360.value*16*200))">Manual Step 360º</button> |
botdream | 0:8b3857d4ce02 | 107 | <br> |
botdream | 0:8b3857d4ce02 | 108 | <br> |
botdream | 0:8b3857d4ce02 | 109 | <!-- <button type="button" onclick="demo()">Demo</button> --> |
botdream | 0:8b3857d4ce02 | 110 | </body> |
botdream | 0:8b3857d4ce02 | 111 | </html> |
botdream | 0:8b3857d4ce02 | 112 | */ |