View main.py
#!/usr/bin/env pybricks-micropython | |
from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor, | |
InfraredSensor, UltrasonicSensor, GyroSensor) | |
from pybricks.parameters import (Port, Stop, Direction, Button, Color, | |
SoundFile, ImageFile, Align) | |
from pybricks.tools import print, wait, StopWatch | |
import struct |
View connection.py
# This code was originally written by Pybricks | |
# Paste all of it into a file named 'connection.py' and place it next to your 'main.py' file | |
# Nothing below is written by Anton's Mindstorms | |
# I found it here. https://github.com/pybricks/pybricks-projects | |
from uctypes import addressof, sizeof, struct | |
from usocket import socket, SOCK_STREAM | |
from _thread import start_new_thread |
View main-car.py
#!/usr/bin/env pybricks-micropython | |
# car code | |
from pybricks.hubs import EV3Brick | |
from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor, | |
InfraredSensor, UltrasonicSensor, GyroSensor) | |
from pybricks.parameters import Port, Stop, Direction, Button, Color | |
from pybricks.tools import wait, StopWatch |
View coordinates.py
__author__ = 'anton' | |
from math import sin, cos, pi | |
from PIL import Image, ImageDraw | |
NUM_POINTS = 150 | |
PREVIEW_SIZE = 500 | |
CIRCLE = 1 | |
SQUARE = 2 |
View get_voltage.py
import smbus | |
def get_voltage(): | |
""" | |
Reads the digital output code of the MCP3021 chip on the BrickPi+ over i2c. | |
Some bit operation magic to get a voltage floating number. | |
If this doesnt work try this on the command line: i2cdetect -y 1 | |
The 1 in there is the bus number, same as in bus = smbus.SMBus(1) | |
Google the resulting error. |
View gist:8458472
#!python | |
from jaraco.nxt import * | |
from jaraco.nxt.messages import * | |
import time | |
import sdl2 | |
import math | |
sdl2.SDL_Init(sdl2.SDL_INIT_JOYSTICK) |
View gist:8458252
from jaraco.nxt import * | |
from jaraco.nxt.messages import * | |
conn = Connection('/dev/tty.NXT-DevB') | |
cmd = SetOutputState( | |
i, | |
motor_on=True, | |
set_power=motorpower, | |
run_state=RunState.running, |
View gist:8455505
import sdl2 | |
sdl2.SDL_Init(sdl2.SDL_INIT_JOYSTICK) | |
joystick = sdl2.SDL_JoystickOpen(0) | |
while True: | |
sdl2.SDL_PumpEvents() | |
#depending on the gamepad this gives you a value between -32768 and +32768 | |
#or between 0 and 32768 | |
joy_x = sdl2.SDL_JoystickGetAxis(joystick, 0) |
View gist:7439560
sudo easy_install pip | |
pip install numpy | |
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)" | |
brew tap homebrew/science | |
brew install opencv | |
pip install jaraco.nxt | |
hg clone https://bitbucket.org/antonvh/robot-sumo robot-sumo | |
cd robot-sumo/blob_recog | |
python blob_recognition.py |