Belgium
Asked — Edited

Example Python Scripts Calling Ez_B.Dll

Hi,

These are intended to be for guidance only, so others can get the idea of how to convert C# or VB into Python. They are probably only useful to people who already use Python.

First step in to install IronPython from here: http://ironpython.net/download/ Ironpython is simply a version of Python with extra .NET bindings.

At the IronPython Command prompt paste in one of the scripts below.

Enjoy!

David.


face_track.py


import clr import sys clr.AddReference('System.Windows.Forms') from System.Windows.Forms import Application, Button, Form from time import * from thread import * sys.path.Add(r"C:[your path here]\EZ-SDK\DLL") clr.AddReference ("EZ_B.dll") import EZ_B import FaceDetect my_ezb = EZ_B.EZB() _camera = EZ_B.Camera(my_ezb) cameras = EZ_B.Camera.GetVideoCaptureDeviceList() videoCaptureDeviceName = cameras[-1] panel1 = Form() panel2 = Form() #these forms have only limited functionality here, e.g. trying to move the window will cause the window to freeze p1 = start_new_thread(Application.Run,(panel1,)) p2 = start_new_thread(Application.Run,(panel2,)) _camera.StartCamera(videoCaptureDeviceName, panel1, panel2, 160, 120) print "Video started:", videoCaptureDeviceName

while True: if _camera.IsActive == False: print 'Camera not active' else: f1 = _camera.CameraFaceDetection.GetFaceDetection() if f1.isFound == False: print 'No face detected' else: print f1.verticalLocation,f1.horizontalLocation sleep(0.5)


RoboSapien.py


import clr import sys from time import * sys.path.Add(r"C:[your path here]\EZ-SDK\DLL") clr.AddReference ("EZ_B.dll") import EZ_B

def wait(my_ezb,seconds): from time import sleep seconds = int(seconds) for i in xrange(seconds): for j in xrange(10): #regularly send a command to the board to keep it connected #there is probably a better way to do this my_ezb.Uart.SendSerial(my_ezb.Digital.DigitalPortEnum.D1, my_ezb.Uart.BAUD_RATE_ENUM.Baud_57600, "1") sleep(0.1) print i

def wait(my_ezb,seconds): from time import sleep seconds = int(seconds) for i in xrange(seconds): for j in xrange(10): #regularly send a command to the board to keep it connected #there is probably a better way to do this my_ezb.Uart.SendSerial(my_ezb.Digital.DigitalPortEnum.D1, my_ezb.Uart.BAUD_RATE_ENUM.Baud_57600, "1") sleep(0.1) print i

def wakeup(my_ezb,pause): my_ezb.RoboSapien.SendCommand(my_ezb.RoboSapien.RoboSapienCmdEnum.WakeUp) print 'Wake-up' wait(my_ezb,pause)

def burp(my_ezb,pause): my_ezb.RoboSapien.SendCommand(my_ezb.RoboSapien.RoboSapienCmdEnum.Burp) print 'Pardon' wait(my_ezb,pause)

def fart(my_ezb,pause): my_ezb.RoboSapien.SendCommand(my_ezb.RoboSapien.RoboSapienCmdEnum.Fart) print 'Oops' wait(my_ezb,pause)

def highfive(my_ezb,pause): my_ezb.RoboSapien.SendCommand(my_ezb.RoboSapien.RoboSapienCmdEnum.HighFive) print 'Gimme five!' wait(my_ezb,pause)

def lefthandstrike(my_ezb,pause): my_ezb.RoboSapien.SendCommand(my_ezb.RoboSapien.RoboSapienCmdEnum.LeftHandStrike) print 'Hiyah!' wait(my_ezb,pause)

def righthandstrike(my_ezb,pause): my_ezb.RoboSapien.SendCommand(my_ezb.RoboSapien.RoboSapienCmdEnum.RightHandStrike) print 'Hoyah!' wait(my_ezb,pause)

def leftarmup(my_ezb,pause): my_ezb.RoboSapien.SendCommand(my_ezb.RoboSapien.RoboSapienCmdEnum.LeftArmUp) my_ezb.RoboSapien.SendCommand(my_ezb.RoboSapien.RoboSapienCmdEnum.Stop) print 'Up' wait(my_ezb,pause)

def rightarmup(my_ezb,pause): my_ezb.RoboSapien.SendCommand(my_ezb.RoboSapien.RoboSapienCmdEnum.RightArmUp) my_ezb.RoboSapien.SendCommand(my_ezb.RoboSapien.RoboSapienCmdEnum.Stop) print 'Up' wait(my_ezb,pause)

def leftarmdown(my_ezb,pause): my_ezb.RoboSapien.SendCommand(my_ezb.RoboSapien.RoboSapienCmdEnum.LeftArmDown) my_ezb.RoboSapien.SendCommand(my_ezb.RoboSapien.RoboSapienCmdEnum.Stop) print 'Down' wait(my_ezb,pause)

def rightarmdown(my_ezb,pause): my_ezb.RoboSapien.SendCommand(my_ezb.RoboSapien.RoboSapienCmdEnum.RightArmDown) my_ezb.RoboSapien.SendCommand(my_ezb.RoboSapien.RoboSapienCmdEnum.Stop) print 'Down' wait(my_ezb,pause) def leftarmdown(my_ezb,pause): my_ezb.RoboSapien.SendCommand(my_ezb.RoboSapien.RoboSapienCmdEnum.LeftArmDown) my_ezb.RoboSapien.SendCommand(my_ezb.RoboSapien.RoboSapienCmdEnum.Stop) print 'Down' wait(my_ezb,pause)

def rightarmdown(my_ezb,pause): my_ezb.RoboSapien.SendCommand(my_ezb.RoboSapien.RoboSapienCmdEnum.RightArmDown) my_ezb.RoboSapien.SendCommand(my_ezb.RoboSapien.RoboSapienCmdEnum.Stop) print 'Down' wait(my_ezb,pause)

my_ezb = EZ_B.EZB() for i in xrange(20): if my_ezb.IsConnected != True: com_string = 'com'+str(i) print 'Trying',com_string my_ezb.Connect(com_string)

wait(my_ezb,5) wakeup(my_ezb,15) while my_ezb.IsConnected: lefthandstrike(my_ezb,5) righthandstrike(my_ezb,5) leftarmup(my_ezb,3) rightarmup(my_ezb,3) leftarmdown(my_ezb,3) rightarmdown(my_ezb,3)



ARC Pro

Upgrade to ARC Pro

Get access to the latest features and updates before they're released. You'll have everything that's needed to unleash your robot's potential!

United Kingdom
#1  

Thanks, I'll have to try some of this in EventGhost's python interface, will add so much to my home automation if I can control the EZB direct from EventGhost.

Belgium
#2  

The message board does not display the all-important tabs (either as tabs or spaces). Here are the files with the tabs in. (Edit: I uploaded them here, but they don't appear, message me if you want them).

United Kingdom
#3  

To upload make sure you zip it, click choose file n the right, select it, then hit the upload button... I see a few people miss the upload button part :).