コード例 #1
0
ファイル: server.py プロジェクト: MikeSquall/pi_robot
async def handle_command(websocket, path):
    while True:
        message = await websocket.recv()

        message = literal_eval(message)
        print(message)

        if message['command'] == 'moveForward':
            robot.forward()
            answer = {'action': 'moveForward'}
        elif message['command'] == 'moveBackward':
            robot.backward()
            answer = {'action': 'moveBackward'}
        elif message['command'] == 'turnRight':
            robot.right()
            answer = {'action': 'turnRight'}
        elif message['command'] == 'turnLeft':
            robot.left()
            answer = {'action': 'turnLeft'}
        elif message['command'] == 'stop':
            robot.stop()
            answer = {'action': 'stop'}
        elif message['command'] == 'grabberGrab':
            # grabber action grab
            answer = {'action': 'grabberGrab', 'value': message['value']}
        elif message['command'] == 'grabberTilt':
            # grabber action tilt
            answer = {'action': 'grabberTilt', 'value': message['value']}
        elif message['command'] == 'grabberHeight':
            # grabber action height
            answer = {'action': 'grabberHeight', 'value': message['value']}
        await websocket.send(json.dumps(answer))
コード例 #2
0
ファイル: server.py プロジェクト: cooly9502/Robot-Server
    def do_POST(self):

        global f
        global b
        global r
        global l
        global robot

        self._set_headers()
        form = cgi.FieldStorage(fp=self.rfile,
                                headers=self.headers,
                                environ={'REQUEST_METHOD': 'POST'})

        print form.getvalue("forward")
        print form.getvalue("backward")
        print form.getvalue("left")
        print form.getvalue("right")

        if form.getvalue("forward") == "Forward":
            if f == 0:
                robot.stop()
                robot.forward()
                f = 1
            else:
                robot.stop()
                f = 0
        if form.getvalue("backward") == "Backward":
            if b == 0:
                robot.stop()
                robot.backward()
                b = 1
            else:
                robot.stop()
                b = 0
        if form.getvalue("left") == "Left":
            if l == 0:
                robot.stop()
                robot.left()
                l = 1
            else:
                robot.stop()
                l = 0
        if form.getvalue("right") == "Right":
            if r == 0:
                robot.stop()
                robot.right()
                r = 1
            else:
                robot.stop()
                r = 0

        file = open("index.html", "r")
        page = file.read()
        file.close()

        self.wfile.write(page)
コード例 #3
0
def move(direction):
    if direction == 'forward':
       robot.forward(0.5)
    if direction == 'backward':
       robot.backward(0.5)
    if direction == 'left':
       robot.left(0.5)
    if direction == 'right':
       robot.right(0.5)
    return '{}'
コード例 #4
0
def action(client, userdata, message):
    data = message.payload.decode()
    data = json.loads(data)
    data = data['action']
    print(data)
    if data == 'forward':
        print('forward')
        robot.forward()
    elif data == 'stop':
        print('stop')
        robot.stop()
    elif data == 'left':
        print('left')
        robot.left()
    elif data == 'right':
        print('right')
        robot.right()
    elif data == 'backward':
        print('backward')
        robot.backward()
    elif data == 'servo left':
        print('servo left')
        robot.servo_left()
    elif data == 'servo center':
        print('servo center')
        robot.servo_center()
    elif data == 'servo right':
        print('servo right')
        robot.servo_right()
    elif data == 'lights':
        print('lights')
        robot.lights()
    elif data == 'blinkers':
        print('blinkers')
        robot.blinkers()
    elif data == 'voltage':
        print('voltage')
        voltage = robot.voltage()
        voltage = send_json(voltage)
        myMQTT.publish('from_robot', voltage, 0)
    elif data == 'distance':
        print('distance')
        distance = robot.distance()
        distance = send_json(distance)
        myMQTT.publish('from_robot', distance, 0)
    else:
        pass
コード例 #5
0
ファイル: app.py プロジェクト: mkyle1121/gopigo
def move_div():
    #if flask.request.method == 'POST':
    if flask.request.form['button'] == 'forward':
        print('forward!')
        robot.forward()
    elif flask.request.form['button'] == 'stop':
        print('stop!')
        robot.stop()
    elif flask.request.form['button'] == 'left':
        print('left')
        robot.left()
    elif flask.request.form['button'] == 'right':
        print('right')
        robot.right()
    elif flask.request.form['button'] == 'backward':
        print('backward')
        robot.backward()
    else:
        pass
    return flask.render_template('index.html')
コード例 #6
0
# robot.robot_speed = 125
# robot.forward(3)
# robot.right_rot(.7)
# robot.forward(2.5)
# robot.left_rot(.7)
# robot.forward(5)
# robot.forward(4)
# robot.left_rot(.7)
# robot.forward(3)
#
# robot.forward(3)
# robot.right_rot(.7)
# robot.forward(3)
# robot.stop()

'''

These are all the functions you can call in robot.

robot.backward(1.0)
robot.forward(1.0)
robot.left(1.0)
robot.right(1.0)
robot.left_rot(1.0)
robot.right_rot(1.0)
robot.stop(1.0)
robot.blink()
d = robot.distance()
v = robot.volt()

'''
コード例 #7
0
ファイル: main.py プロジェクト: halstar/MySmartTankRobot
def console_thread(robot, left_motor, right_motor, imu_device, front_pan_tilt, front_lidar, back_pan_tilt, back_lidar, speed_pid_controller):

    print_help()

    is_console_on = True
    selected_pid  = 1

    while is_console_on == True:

        print('> ', end = '')

        user_input = input()

        if len(user_input) == 1:

            command = user_input[0]

            if command == '1':
                print('')
                print('Speed PID selected')
                print('')
                selected_pid = 1
            elif command == 'm':
                print('')
                left_motor.print_info ('LEFT  DC MOTOR')
                right_motor.print_info('RIGHT DC MOTOR')
                print('')
            elif command == 'v':
                print('')
                front_pan_tilt.print_info('FRONT')
                print('')
                back_pan_tilt.print_info ('BACK' )
                print('')
            elif command == 'c':
                print('')
                print('SPEED PID:')
                speed_pid_controller.print_info()
                print('')
            elif command == 'u':
                print('')
                imu_device.print_info()
                print('')
            elif command == 'r':
                print('')
                robot.print_info()
                print('')
                front_lidar.print_info('FRONT LIDAR')
                back_lidar.print_info ('BACK  LIDAR')
                print('')
                print('Line following threshold: {}'.format(control.line_threshold))
                print('')
            elif command == 'q':
                print('')
                print('***** GOING TO OPERATIONAL MODE *****')
                is_console_on = False
            elif command == 'x':
                print('***** EXITING GRACEFULLY *****')
                robot.stop()
                front_pan_tilt.stop()
                back_pan_tilt.stop ()
                if status.is_rpi_gpio_used:
                    RPi.GPIO.cleanup()
                os._exit(0)
            elif command == 'h':
                print_help()

        elif len(user_input) == 2:

            command = user_input[0:2]

            if command == 'sf':
                robot.forward_step()
            elif command == 'sb':
                robot.backward_step()
            elif command == 'sl':
                robot.left_step()
            elif command == 'sr':
                robot.right_step()

        elif len(user_input) > 2 and user_input[1] == '=':

            command = user_input[0]
            value   = float(user_input[2:])

            if command == 'l':
                if value == 0:
                    log_set_level(NO_LOG )
                elif value == 1:
                    log_set_level(ERROR  )
                elif value == 2:
                    log_set_level(WARNING)
                elif value == 3:
                    log_set_level(INFO   )
                elif value == 4:
                    log_set_level(DEBUG  )
                else:
                    print('Invalid log level')
            elif command == 'p':
                if selected_pid == 1:
                    speed_pid_controller.set_kp(value)
            elif command == 'i':
                if selected_pid == 1:
                    speed_pid_controller.set_ki(value)
            elif command == 'd':
                if selected_pid == 1:
                    speed_pid_controller.set_kd(value)
            elif command == 'w':
                if selected_pid == 1:
                    speed_pid_controller.set_anti_wind_up(value)
            elif command == 's':
                if value > 0:
                    robot.forward(value)
                elif value < 0:
                    robot.backward(-value)
                else:
                    robot.stop()
            elif command == 'a':
                if value < 0:
                    robot.right_with_angle(-value, True)
                else:
                    robot.left_with_angle(value, True)
            elif command == 'g':
                if value < 0:
                    robot.right_with_strength(-value)
                else:
                    robot.left_with_strength(value)
            elif command == 't':
                control.line_threshold = value

        elif len(user_input) > 2 and user_input[2] == '=':

            command = user_input[0:2]
            value   = float(user_input[3:])

            if command == 'fp':
                front_pan_tilt.set_pan(value)
            elif command == 'ft':
                front_pan_tilt.set_tilt(value)
            elif command == 'bp':
                back_pan_tilt.set_pan(value)
            elif command == 'bt':
                back_pan_tilt.set_tilt(value)
コード例 #8
0
ファイル: solution.py プロジェクト: sumsted/mempy_20160321
# robot.robot_speed = 125
# robot.forward(3)
# robot.right_rot(.7)
# robot.forward(2.5)
# robot.left_rot(.7)
# robot.forward(5)
# robot.forward(4)
# robot.left_rot(.7)
# robot.forward(3)
#
# robot.forward(3)
# robot.right_rot(.7)
# robot.forward(3)
# robot.stop()

'''

These are all the functions you can call in robot.

robot.backward(1.0)
robot.forward(1.0)
robot.left(1.0)
robot.right(1.0)
robot.left_rot(1.0)
robot.right_rot(1.0)
robot.stop(1.0)
robot.blink()
d = robot.distance()
v = robot.volt()

'''
コード例 #9
0
ファイル: robot_sock_client.py プロジェクト: mkyle1121/gopigo
 print(data.decode())
 if data == 'forward':
     print('forward!')
     robot.forward()
 elif data == 'stop':
     print('stop!')
     robot.stop()
 elif data == 'left':
     print('left')
     robot.left()
 elif data == 'right':
     print('right')
     robot.right()
 elif data == 'backward':
     print('backward')
     robot.backward()
 elif data == 'servo left':
     print('servo left')
     robot.servo_left()
 elif data == 'servo center':
     print('servo center')
     robot.servo_center()
 elif data == 'servo right':
     print('servo right')
     robot.servo_right()
 elif data == 'lights':
     print('lights')
     robot.lights()
 elif data == 'blinkers':
     print('blinkers')
     robot.blinkers()