Esempio n. 1
0
    def send_data_new(self, action):
        # Trying out method of updating robot pos in background
        # Here 1st action would be sent to arduino and temp_pos&next_pos = robot_pos + action
        # Next iteration if robot_pos != next_pos: temp_pos = temp_pos + action
        # Once robot_pos == next_pos, next_pos = temp_pos and send next_pos

        # print("action is: {}".format(action))
        if 0 < action < 6:  # actions 1 - 5 = Move Up
            move = int(action * 3)
        elif 5 < action < 11:  # actions 6 - 10 = Move Down
            move = -int((action - 5) * 3)
        elif action == 11:
            sendBuff = "999"
            send(self.SER_cnxn, str(sendBuff))
        elif action == 0:  # action = Do nothing
            pass

        if 0 < action < 11:
            if self._next_robot_pos is None:
                # Error handling
                self._next_robot_pos = self._robot_pos + move
                self._temp_robot_pos = self._next_robot_pos
            elif self._next_robot_pos is not None and self._robot_pos == self._next_robot_pos:
                # sends next position for robot to move to
                self._temp_robot_pos += move
                self._next_robot_pos = self._temp_robot_pos
            elif self._next_robot_pos is not None and self._robot_pos != self._next_robot_pos:
                self._temp_robot_pos += move  # This updates robot pos in background while moving
            self.verify_robot_pos()

        # Constantly tell arduino to execute current command
        if self._puck_x < -150:
            send(self.SER_cnxn, "999")
        else:
            send(self.SER_cnxn, str(self._next_robot_pos))
Esempio n. 2
0
def export_data(request=False):
    if request is False:
        return False
    if "config" in request:
        config = request["config"]
    else:
        config = {"Default_Severity": 1, "Device_Vendor": "MISP", "Device_Product": "MISP", "Device_Version": 1,
                  'custom1':'deviceCustomDate1'}
        if request["type"] in cefmapping:
            send_data.send("{} host CEF:0|{}|{}|{}|{}|{}|{}|{}={} {}={}\n".format(
                datetime.datetime.now().strftime("%b %d %H:%M:%S"),
                config["Device_Vendor"],
                config["Device_Product"],
                config["Device_Version"],
                request["category"],
                request["category"],
                config["Default_Severity"],
                cefmapping[request["type"]],
                request["value"],
                config["custom1"],
                datetime.datetime.fromtimestamp(int(request["timestamp"])).strftime("%b %d %H:%M:%S"),
            ))
Esempio n. 3
0
    def reset(self):
        # Resets the environment on startup and at the beginning of episode
        new_state = []

        # Receive Puck data from Image Processing PI
        rc = recv_puck(self.TCP_cnxn)

        # Move physical robot to middle of playing field
        self._next_robot_pos = 150
        self._temp_robot_pos = self._next_robot_pos
        send(self.SER_cnxn, str(self._next_robot_pos))

        # Updates robot position directly from arduino keeps previous value until new value is sent

        self._robot_pos = recv_robo(self.SER_cnxn)
        if self._robot_pos == None:
            self._robot_pos = self._prev_robot_pos

        # Update puck variables
        self._puck_x = rc[0]
        self._puck_y = rc[1]
        self._speed_x = 0  #self.get_speed('x') start at 0 for first state
        self._speed_y = 0  #self.get_speed('y')

        # Resetting flags used for informing robot
        # These flags should change to True only once per episode
        self._goal_scored = False
        # self._intercepted = False
        # self._hit = False

        new_state.append(self._robot_pos)
        new_state.append(rc[0])
        new_state.append(rc[1])
        new_state.append(self._speed_x)
        new_state.append(self._speed_y)

        return np.array(new_state)
Esempio n. 4
0
        # Print a counter
        print(i)

	# Detect motion via PIR Sensor
        detect = GPIO.input(4)

        # When PIR sensor detect motion
        if(detect):
            print("Motion Detected")

            print("LED ON")
            GPIO.output(10,GPIO.HIGH)

            # Send data to server
            send_data.send("PutYourNameHere")

            # Wait a moment
            time.sleep(10)

            print("LED OFF")
            GPIO.output(10,GPIO.LOW)

            i = 0

        # Wait a little before detecting further motion
        time.sleep(1)
        # Increase a counter
        i += 1

except Exception:
Esempio n. 5
0
def move_up(intensity):
    # move robot left based on intensity
    send("u{}".format(intensity))
Esempio n. 6
0
def hit_puck(direction):
    # spin hockey stick in direction specified
    direction = direction.split('')[0]
    send("h{}".format(direction))
Esempio n. 7
0
def move_down(intensity):
    # move robot right based on intensity
    send("d{}".format(intensity))
Esempio n. 8
0
import send_data

send_data.send("BOON")