コード例 #1
0
def checkPleasure(arg):
    arg.AddNeuron(3)
    arg.AddNeuron(3)
    while (1):
        if GPIO.input(button1) == 0:  # if button 1 press
            print("Button 1 Was Pressed:")
            if BS1 == False:  # If the LED is off
                GPIO.output(LED1, True)  # turn on LED 1
                BS1 = True  # Set Flag to show LED1 is now On
                arg.SpikeProcessing(3, 0)
                if (not MotionController.blocked):
                    MotionController.feelPleasure(MotionController.blocked)
        else:  # If the LED is on
            GPIO.output(LED1, False)  # Turn LED 1 off
            BS1 = False  # Set Flag to show LED1 is now Off
        if GPIO.input(button2) == 0:  #Repeat for LED 2 and button 2
            print("Button 2 Was Pressed:")
            if BS2 == False:
                GPIO.output(LED2, True)
                BS2 = True
                arg.SpikeProcessing(3, 1)
                if (not MotionController.blocked):
                    MotionController.feelPain(MotionController.blocked)
        else:  # If the LED is on
            GPIO.output(LED2, False)  # Turn LED 1 off
            BS2 = False

        BS1 = False
        BS2 = False

        sleep(0.2)
コード例 #2
0
ファイル: ANet.py プロジェクト: Habbul/XCR-2-dev
 def SpikeProcessing(self, groupId, neuronId):
     spiked = []
     self.NeuronGroups[groupId].Neurons[neuronId].Spiking()
     for group in range(len(self.NeuronGroups)):
         if(group != groupId):
             for elem in range(len(self.NeuronGroups[group].Neurons)):
                 new = self.NeuronGroups[group].Neurons[elem]
                 for sin in range(len(new.sinapces)):
                     if(new.sinapces[sin].n2 is self.NeuronGroups[groupId].Neurons[neuronId]):
                         new.UpdateSinaps(self.NeuronGroups[groupId].Neurons[neuronId])
     if(len(self.NeuronGroups[groupId].Neurons[neuronId].chosen) > 0):
         locked = self.NeuronGroups[groupId].Neurons[neuronId]
         spiked = []
         spiked.append(locked)
         for elem in locked.chosen:
             spiked.append(elem.n2)
             if(len(elem.n2.chosen) > 0):
                 for ch in elem.n2.chosen:
                     if(not spiked.__contains__(ch)):
                         spiked.append(ch.n2)
         for i in range(len(locked.chosen)):
             print("Spike! " + str(locked.chosen[i].n1.Id) + " of group " + str(locked.chosen[i].n1.groupId)
               + " associated with " + str(locked.chosen[i].n2.Id) + " of group " + str(locked.chosen[i].n2.groupId))
         """methods of decidion maker"""
     MotionController.Process(groupId, neuronId, spiked, MotionController.blocked)
コード例 #3
0
    def init_processes(self):
        # queue buttons - button_handler
        self.queue_buttons_bh = multiprocessing.Queue()

        # queue button_handler - strategy_module
        self.queue_bh_sm = multiprocessing.Queue()

        # queue motion_controller - information_board
        self.queue_mc_ib = multiprocessing.Queue()

        self.button_handler = ButtonHandler.ButtonHandler(self.queue_buttons_bh, self.queue_bh_sm)
        self.motion_controller = MotionController.MotionController(self.queue_bh_sm, self.queue_mc_ib, self.weight_limit)
        self.information_table = InformationBoard.InformationBoard(self.queue_mc_ib)

        self.init_buttons()

        self.process_button_handler = multiprocessing.Process(target=self.button_handler.run)

        self.process_motion_controller = threading.Thread(target=self.motion_controller.run)

        self.process_information_table = multiprocessing.Process(target=self.information_table.run)

        # process_buttons.start()
        self.process_button_handler.start()
        self.process_motion_controller.start()
        self.process_information_table.start()
コード例 #4
0
ファイル: Tank.py プロジェクト: GreenKing/Tank_War
 def __init__(self, location, direction):
     pygame.sprite.Sprite.__init__(self)
     self.direction = direction
     self.set_image(self.direction)
     self.rect = self.image.get_rect()
     self.set_location(location)
     self.speed = 80
     self.mcontroller = MotionController(self, Vector2(StepX, StepY))
     self.att = Attribute(self)
     self.name = "TANK"
コード例 #5
0
ファイル: Bullet.py プロジェクト: GreenKing/Tank_War
 def __init__(self, tank, location, direction):    
     Bullet.__init__(self, tank)
     self.set_image(direction)
     self.rect = self.image.get_rect()
     self.set_location(location)
     #print self.rect
     self.speed = 200
     self.mcontroller = MotionController(self, Vector2(StepX,StepY))
     self.state = 0
     self.atk = 40
コード例 #6
0
ファイル: Bullet.py プロジェクト: GreenKing/Tank_War
class SBullet(Bullet):
    images = {}
    delta = [Vector2(0, 0), Vector2(-0.5, -1), Vector2(-1, -0.5), Vector2(-0.5, 0), Vector2(0, -0.5)]
    def __init__(self, tank, location, direction):    
        Bullet.__init__(self, tank)
        self.set_image(direction)
        self.rect = self.image.get_rect()
        self.set_location(location)
        #print self.rect
        self.speed = 200
        self.mcontroller = MotionController(self, Vector2(StepX,StepY))
        self.state = 0
        self.atk = 40
        
    def set_image(self, direction):
        self.direction = direction
        self.image = SBullet.images[direction]
        
    def set_location(self, location):
        x, y, w, h = self.rect
        self.location = self.rect.topleft = location + SBullet.delta[self.direction] * Vector2(w, h)        
        
    def get_rect(self):
        return self.rect
    
    def get_direction(self):
        return self.direction
    
    def shoot(self):
        self.state = 1
        
    def update(self, timepased):
        if self.state == 1:
            self.location, self.direction = self.mcontroller.update_state(timepased, self.direction)
            self.image = SBullet.images[self.direction]
            self.rect.topleft = self.location
            
        if self.collision_update():
            self.kill()
コード例 #7
0
N = 64  # Number of Elements

dx = 1. # Spacing of Capture Points in mm

Lx = 255. # Length of Scan in mm

X0 = 25. # Initial Position of Centre of Aperture (mm)

X = np.linspace(X0, X0+Lx, int(np.round(Lx/dx))) # Vector of capture positions (mm)

T = 2*1.25*np.sqrt(( X[-1] + (N-1)*p/2 - h[-1][0])**2 + h[-1][1]**2)/5.92 # Time gate (mircoseconds)

F = mp.PhasedArray(N, fsamp=25., pwidth=1/20.) # MicroPulse object for FMC acquisition

G = mc.Controller() # MotionController object for Galil axis control

xy = [] # List to store position of hole to be imaged w.r.t. to first element

for XX in X:

    th = np.array([np.arctan2(np.abs(XX - hh[0]), hh[1]) for hh in h])

    indh = np.argmin(th)

    if th < thmax:

        F.GetFMCData((0., T), 80., 200., 16)

        xy.append((h[indh][0] - (XX - (N-1)*p/2.),h[indh][1]))
コード例 #8
0
ファイル: main.py プロジェクト: zeta1999/Axis-Reloaded
def main():
    EXIT_COMMAND = "exit"
    
    vc = VisionController()
    mc =  MotionController()
    # print("Initializing Motion Controller")
    mc.run()
    # print("Initializing Motion Controller")
    # print("Press enter to run VC")
    input()
    vc.run()
    input()
    # time.sleep(20)

    # Queue for 
    inputQueue = queue.Queue()
    print("Startup complete.")
    print("Input help or h for command list")
    inputThread = threading.Thread(target=read_kbd_input, args=(inputQueue,), daemon=True)
    inputThread.start()
    camera = True
    pause = False
    while (True):
        if camera:
            correction = vc.getPosition()
            state = vc.getState()
            if state != "Centered":
                correction = np.array([correction[0], correction[1], 0])
            #print(correction)
                mc.set_correction(correction)
                if not pause:
                    mc.set_mode(2)
            else:
                if not pause:
                    mc.set_mode(1)

        if (inputQueue.qsize() > 0):
            input_str = inputQueue.get().strip().lower()
            #print("input_str = {}".format(input_str))

            if (input_str == EXIT_COMMAND):
                vc.shutDown()
                mc.set_mode(0)
                print("Press enter when plate is removed to complete shutdown.")
                while inputQueue.qsize() < 0:
                   time.sleep(.5)
                temp = inputQueue.get() 
                mc.set_mode(3)
                print("Exiting serial terminal.")
                break
            elif pause and not input_str == '0':
                print("System is paused, input 0 to resume")
            else:
                if not input_str.isalpha():
                    mc.set_mode(int(input_str))
                    if int(input_str) == 0:
                        pause = not pause
                elif input_str == 'camera':
                    camera = not camera
                    camState = "Camera turned on." if camera else "Camera turned off."
                    print(camState)
                elif input_str == 'state' or input_str == 's':
                    print(state + " at : " +str(correction[0]) +" " + str(correction[1]))
                elif input_str == 'help' or input_str == 'h':
                    print("Input Options:")
                    print("camera will toggle the camera state")
                    print("s or state returns the current position and state of the plate")
                    print("recenter or c triggers a recenter motion after spin cycle completes")
                    print("exit starts the shutdown sequence")
                    print("0 pauses motion")
                    print("1 resumes spin cycle")
                    print("2 resumes recenter motion")
                    print("3 is emergency limp (will drop plate)")
                elif input_str == 'recenter' or input_str == 'c':
                    mc.set_mode(2)
                    mcState = mc.getMCState()
                    while mcState != 2:
                        print("Waiting to start recenter " )
                        time.sleep(.5)
                        mcState = mc.getMCState()



            # Insert your code here to do whatever you want with the input_str.

        # The rest of your program goes here.

        time.sleep(0.01) 
    print("End.")
コード例 #9
0
ファイル: Tank.py プロジェクト: GreenKing/Tank_War
class Tank(pygame.sprite.Sprite):
    images = {}
    delta = [Vector2(0, 0), Vector2(0.5, 0), Vector2(0, 0.375), Vector2(0.5, 1), Vector2(1, 0.375)]

    def __init__(self, location, direction):
        pygame.sprite.Sprite.__init__(self)
        self.direction = direction
        self.set_image(self.direction)
        self.rect = self.image.get_rect()
        self.set_location(location)
        self.speed = 80
        self.mcontroller = MotionController(self, Vector2(StepX, StepY))
        self.att = Attribute(self)
        self.name = "TANK"

    def shoot(self, shoot):
        if len(self.bullets.sprites()) > 0:
            return
        if shoot == 1:
            x, y, w, h = self.rect
            # print x,y,w,h
            pos = self.location + Tank.delta[self.direction] * Vector2(w, h)
            bullet = SBullet(self, pos, self.direction)
            bullet.add(self.bullets_group)
            bullet.add(self.bullets)
            bullet.shoot()
            SoundPlayer.play_shoot_sound()

    def set_image(self, direction):
        self.image = Tank.images[direction]

    def set_direction(self, direction):
        self.direction = direction
        self.set_image(self.direction)

    def set_location(self, location):
        self.rect.topleft = self.location = location

    def set_bullets(self, bullets):
        self.bullets_group = bullets
        self.bullets = pygame.sprite.RenderUpdates()

    def step_back(self):
        self.set_location(self.mcontroller.step_back())

    def moved(self):
        dx, dy = self.location - self.mcontroller.lastlocation
        dx = abs(dx)
        dy = abs(dy)
        if (dx + dy) <= 0.00001:
            return False
        else:
            return True

    def on_attacked(self, atk):
        self.att.on_attacked(atk)

    def on_collision_with(self, mover):
        if not self.moved():
            # print "not moved, return"
            return False
        # print "direction", self.direction
        if abs(self.direction - mover.direction) == 2:
            # self.step_back()
            # print "facing each other, step back"
            return True
        rect = self.rect.copy()
        # print "self.rect before", self.rect
        rect.topleft = self.mcontroller.step_back()
        # print "self.rect", self.rect
        # print "rect", rect
        if not rect.colliderect(mover.rect):
            # self.step_back()
            # print "initiative"
            return True
        # else:
        # print "passive"
        return False

    def blocked(self, rect):
        self.set_location(self.mcontroller.backwards(rect))

    def collision_update(self):
        # collide_arr = sprite.spritecollide(self, enemy_tanks, 0)
        spritecollide = self.rect.colliderect

        for group in [enemy_tanks.sprites(), players.sprites()]:
            for s in group:
                if spritecollide(s.rect):
                    if self.on_collision_with(s):
                        self.step_back()
                        return

        for group in [stones.sprites(), rivers.sprites(), bricks.sprites()]:
            for s in group:
                if spritecollide(s.rect):
                    self.blocked(s.rect)
                    return

    def update_control(self, timepased, direction, shoot):
        location, direction = self.mcontroller.update_state(timepased, direction)
        self.set_direction(direction)
        self.set_location(location)
        self.shoot(shoot)
        self.collision_update()
        self.att.update_att()
コード例 #10
0
def curi(net):
    MotionController.curiosity(MotionController.blocked)
コード例 #11
0
import MotionController as mc
import MicroPulse as mp
import numpy as np

pth = 'E:/MicroPulseFBHBacksideScans/'

SampleName = 'D01-03-Backside'

m = mp.PhasedArray(32, pwidth=1 / 10.)
c = mc.Controller()

Npos = 80

speed = 3.

p = np.linspace(0, Npos - 1, Npos)

for pp in p:

    c.MoveAbsolute('Y', pp, speed)

    m.GetFMCData((0., 85.), dB=50., Voltage=200., Averages=8)

m.SaveScan(pth + SampleName + '1.p')

m.ClearAScans()

for pp in p[::-1]:

    c.MoveAbsolute('Y', pp, speed)
from __future__ import print_function, division

import time

import MotionController

controller = MotionController.PyMotionController()

initialized = False

# Try to initialize the motion manager
try:
    initialized = controller.initMotionManager()
except:
    print('\nException occured')

if initialized:
    print("Initialized")

    # Walking demo
    controller.initWalking()
    time.sleep(1)
    controller.walk(5, 0, 0)
    time.sleep(1)
    controller.walk(5, 10)
    time.sleep(1)
    controller.walk(5, -10)
    time.sleep(1)
    controller.walk(-1, 0, 2)

    time.sleep(5)