-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
2,229 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,73 @@ | ||
# ev3dev-lang-python-demo | ||
# ev3dev demo programs | ||
|
||
This folder contains several demo programs that you can use to help you in | ||
developing your own code. Brief descriptions of each demo are provided below; | ||
you can access the full source code and some more detailed information on each | ||
by opening the respective folders above. | ||
|
||
To install these on your EV3, use git to clone the ev3dev-lang-python repository | ||
from github. Your EV3 will need Internet connectivty in order to clone the | ||
repository from github. | ||
``` | ||
$ sudo apt-get install git | ||
$ git clone https://github.com/rhempel/ev3dev-lang-python.git | ||
``` | ||
|
||
## Running A Program | ||
There are two ways to run a program. You can run a program from the command line | ||
or from the brickman interface. | ||
|
||
Note that for both running from the command line and running from Brickman the | ||
program **must be marked as an executable** and the **first line of the program | ||
must be** `#!/usr/bin/env python3`. To mark a program as executable run | ||
`chmod +x PROGRAM_NAME.py`. All of the demo programs are already marked as | ||
executable and already have `#!/usr/bin/env python3` so you should be fine, we | ||
only mention it so you know to do these things when writing your own programs. | ||
|
||
## Command Line | ||
To run one of the demo programs from the command line, cd to the directory and | ||
run the program via `./PROGRAM_NAME.py`. Example: | ||
``` | ||
$ cd ev3dev-lang-python/demo/R3PTAR/ | ||
$ ./r3ptar.py | ||
``` | ||
## Brickman | ||
To run one of the demo programs from Brickman, select the program in the | ||
File Browser. | ||
|
||
## Demo Programs | ||
### BALANC3R | ||
|
||
Laurens Valk's BALANC3R - This robot uses the gyro sensor to balance on two | ||
wheels. Use the IR remote to control BALANC3R | ||
|
||
* http://robotsquare.com/2014/07/01/tutorial-ev3-self-balancing-robot/ | ||
|
||
### EV3D4 | ||
|
||
* http://www.lego.com/en-us/mindstorms/build-a-robot/ev3d4 | ||
* EV3D4RemoteControl - Use the IR remote to control EV3D4 | ||
* EV3D4WebControl - Use a web interface to control EV3D4. There is a desktop version and a mobile version, both support touchscreen so you can drive via your smartphone. The web server will listen on port 8000 so go to http://x.x.x.x:8000/ | ||
|
||
### EXPLOR3R | ||
|
||
Lauren Valk's EXPLOR3R | ||
|
||
* http://robotsquare.com/2015/10/06/explor3r-building-instructions/ | ||
|
||
### MINDCUB3R | ||
|
||
David Gilday's MINDCUB3R | ||
|
||
* http://mindcuber.com/ | ||
|
||
### TRACK3R | ||
|
||
A basic example of Object Oriented programming where there is a base TRACK3R | ||
class with child classes for the various permutations of TRACK3R | ||
|
||
* http://www.lego.com/en-us/mindstorms/build-a-robot/track3r | ||
* TRACK3R.py | ||
* TRACK3RWithBallShooter | ||
* TRACK3RWithClaw | ||
* TRACK3RWithSpinner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import logging | ||
from ev3dev.GyroBalancer import GyroBalancer | ||
|
||
|
||
class BALANC3R(GyroBalancer): | ||
""" | ||
Laurens Valk's BALANC3R | ||
http://robotsquare.com/2014/06/23/tutorial-building-balanc3r/ | ||
""" | ||
def __init__(self): | ||
GyroBalancer.__init__(self, | ||
gainGyroAngle=1156, | ||
gainGyroRate=146, | ||
gainMotorAngle=7, | ||
gainMotorAngularSpeed=9, | ||
gainMotorAngleErrorAccumulated=3) | ||
|
||
|
||
if __name__ == '__main__': | ||
logging.basicConfig(level=logging.DEBUG, | ||
format='%(asctime)s %(levelname)5s: %(message)s') | ||
log = logging.getLogger(__name__) | ||
|
||
log.info("Starting BALANC3R") | ||
robot = BALANC3R() | ||
robot.main() | ||
log.info("Exiting BALANC3R") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import logging | ||
import sys | ||
from ev3dev.auto import OUTPUT_A, OUTPUT_B, OUTPUT_C | ||
from ev3dev.helper import RemoteControlledTank, MediumMotor | ||
|
||
class EV3D4RemoteControlled(RemoteControlledTank): | ||
|
||
def __init__(self, medium_motor=OUTPUT_A, left_motor=OUTPUT_C, right_motor=OUTPUT_B): | ||
RemoteControlledTank.__init__(self, left_motor, right_motor) | ||
self.medium_motor = MediumMotor(medium_motor) | ||
|
||
if not self.medium_motor.connected: | ||
log.error("%s is not connected" % self.medium_motor) | ||
sys.exit(1) | ||
|
||
self.medium_motor.reset() | ||
|
||
|
||
logging.basicConfig(level=logging.INFO, | ||
format='%(asctime)s %(levelname)5s: %(message)s') | ||
log = logging.getLogger(__name__) | ||
|
||
log.info("Starting EV3D4") | ||
ev3d4 = EV3D4RemoteControlled() | ||
ev3d4.main() | ||
log.info("Exiting EV3D4") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import logging | ||
import sys | ||
from ev3dev.auto import OUTPUT_A, OUTPUT_B, OUTPUT_C | ||
from ev3dev.helper import MediumMotor | ||
from ev3dev.webserver import WebControlledTank | ||
|
||
class EV3D4WebControlled(WebControlledTank): | ||
|
||
def __init__(self, medium_motor=OUTPUT_A, left_motor=OUTPUT_C, right_motor=OUTPUT_B): | ||
WebControlledTank.__init__(self, left_motor, right_motor) | ||
self.medium_motor = MediumMotor(medium_motor) | ||
|
||
if not self.medium_motor.connected: | ||
log.error("%s is not connected" % self.medium_motor) | ||
sys.exit(1) | ||
|
||
self.medium_motor.reset() | ||
|
||
|
||
logging.basicConfig(level=logging.INFO, | ||
format='%(asctime)s %(levelname)5s: %(message)s') | ||
log = logging.getLogger(__name__) | ||
|
||
log.info("Starting EV3D4") | ||
ev3d4 = EV3D4WebControlled() | ||
ev3d4.main() # start the web server | ||
log.info("Exiting EV3D4") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# EV3D4 | ||
EV3D4 is designed to look like R2-D2 from Star Wars. There are two options for | ||
controlling EV3D4. The first is to use the IR remote to send commands to the IR | ||
sensor, run EV3D4RemoteControl.py to use this method. The second means of | ||
controlling EV3D4 is via a web browser, run EV3D4WebControl.py to use this method. | ||
You can run both of these from the Brickman interface or if logged in via ssh | ||
you can run them via ./EV3D4RemoteControl.py or ./EV3D4WebControl.py. | ||
|
||
**Building instructions**: https://www.lego.com/en-us/mindstorms/build-a-robot/ev3d4 | ||
|
||
### EV3D4RemoteControl | ||
EV3D4RemoteControl.py creates a child class of ev3dev/helper.py's | ||
RemoteControlledTank. | ||
|
||
|
||
### EV3D4WebControl | ||
EV3D4WebControl creates a child class of ev3dev/webserver.py's WebControlledTank. | ||
The WebControlledTank class runs a web server that serves the web pages, | ||
images, etc but it also services the AJAX calls made via the client. The user | ||
loads the initial web page at which point they choose the "Desktop interface" | ||
or the "Mobile Interface". | ||
|
||
Desktop Interface - The user is presented with four arrows for moving forwards, | ||
backwards, spinning clockwise or spinning counter-clockwise. Two additional | ||
buttons are provided for controlling the medium motor. There are two sliders, | ||
one to control the speed of the tank and the other to control the speed of the | ||
medium motor. | ||
|
||
Mobile Interface - The user is presented with a virtual joystick that is used | ||
to control the movements of the robot. Slide your thumb forward and the robot | ||
moves forward, slide it to the right and the robot spins clockwise, etc. The | ||
further you move the joystick towards the edge of the circle the faster the | ||
robot moves. Buttons and a speed slider for the medium motor are also provided. | ||
|
||
Both interfaces have touch support so you can use either Desktop or Mobile from | ||
your smartphone. When the user clicks/touches a button some jQuery code will | ||
fire off an AJAX call to let the EV3D4 web server know what the user clicked or | ||
where the joystick is if using the Mobile Interface. The web server in | ||
WebControlledTank services this AJAX call and adjust motor speed/power | ||
accordingly. | ||
|
||
You can see a demo of the web interface below. Note that the demo is on a | ||
simple Tank robot, not EV3D4, but that doesn't really matter as EV3D4 is also | ||
just a Tank robot. | ||
|
||
**Demo Video**: https://www.youtube.com/watch?v=x5VauXr7W4A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<!DOCTYPE> | ||
<html xmlns="http://www.w3.org/1999/xhtml"> | ||
<head> | ||
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> | ||
<link rel="shortcut icon" href="favicon.ico"> | ||
<link rel="stylesheet" type="text/css" href="/include/tank.css" media="screen" /> | ||
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.0/themes/smoothness/jquery-ui.css"> | ||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> | ||
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.0/jquery-ui.min.js"></script> | ||
<script src="/include/jquery.ui.touch-punch.min.js"></script> | ||
<script src="/include/tank-desktop.js"></script> | ||
<title>Lego Tank</title> | ||
</head> | ||
<body> | ||
<div class='alignCenter'> | ||
<div id='header'> | ||
</div> | ||
|
||
<div id='controls'> | ||
<img class='button nav' id='ArrowUp' src='/include/ArrowUp.png' /> | ||
<div class='clear'></div> | ||
|
||
<img class='button nav' id='ArrowLeft' src='/include/ArrowLeft.png' /> | ||
<img id='body' src='/include/tank.png' /> | ||
<img class='button nav' id='ArrowRight' src='/include/ArrowRight.png' /> | ||
<div class='clear'></div> | ||
|
||
<img class='button nav' id='ArrowDown' src='/include/ArrowDown.png' /> | ||
<div class='clear'></div> | ||
</div> | ||
|
||
<div id='desktop-medium-motor-spin'> | ||
<img class='button medium CounterClockwise' src='/include/ArrowClockwise.png' /> | ||
<img class='button medium Clockwise' src='/include/ArrowClockwise.png' /> | ||
<br> | ||
<div id="medium-motor-speed"></div> | ||
<label for="medium-motor-speed">Medium Motor Speed</label> | ||
<br> | ||
<div id="tank-speed"></div> | ||
<label for="tank-speed">Tank Speed</label> | ||
</div> | ||
|
||
<div class='clear'></div> | ||
|
||
</div> <!-- alignCenter --> | ||
</body> | ||
</html> |
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/*! | ||
* jQuery UI Touch Punch 0.2.3 | ||
* | ||
* Copyright 2011-2014, Dave Furfero | ||
* Dual licensed under the MIT or GPL Version 2 licenses. | ||
* | ||
* Depends: | ||
* jquery.ui.widget.js | ||
* jquery.ui.mouse.js | ||
*/ | ||
!function(a){function f(a,b){if(!(a.originalEvent.touches.length>1)){a.preventDefault();var c=a.originalEvent.changedTouches[0],d=document.createEvent("MouseEvents");d.initMouseEvent(b,!0,!0,window,1,c.screenX,c.screenY,c.clientX,c.clientY,!1,!1,!1,!1,0,null),a.target.dispatchEvent(d)}}if(a.support.touch="ontouchend"in document,a.support.touch){var e,b=a.ui.mouse.prototype,c=b._mouseInit,d=b._mouseDestroy;b._touchStart=function(a){var b=this;!e&&b._mouseCapture(a.originalEvent.changedTouches[0])&&(e=!0,b._touchMoved=!1,f(a,"mouseover"),f(a,"mousemove"),f(a,"mousedown"))},b._touchMove=function(a){e&&(this._touchMoved=!0,f(a,"mousemove"))},b._touchEnd=function(a){e&&(f(a,"mouseup"),f(a,"mouseout"),this._touchMoved||f(a,"click"),e=!1)},b._mouseInit=function(){var b=this;b.element.bind({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),c.call(b)},b._mouseDestroy=function(){var b=this;b.element.unbind({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),d.call(b)}}}(jQuery); |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.