コード例 #1
0
ファイル: S-CodeParse.py プロジェクト: zhangfaquan/smars
def readLine(line):

    sm = SmarsRobot()
    sm.setname("Quaddy")
    sm.type = "Quad"

    if line[0] == 's101': # Move Forward
        sm.walkforward(100)
    if line[0] == 's102': # Move Backward
        sm.walkbackward(100)
    if line[0] == 's103': # Turn left
        sm.turnleft()
    if line[0] == 's104': # Turn right
        sm.turnright()
    if line[0] == 's155': # Stand Up
        sm.stand()
    if line[0] == 's156': # Sit down
        sm.sit()
    if line[0] == 's157': # Clap
        print("line count: ", len(line))
        if len(line) <= 1:
            clap_count = 3
        else:
            clap_count = int(line[1]) # convert str to int
        sm.clap(clap_count)
    if line[0] == 's158': # Wiggle
        print("line count:", len(line))
        if len(line) <= 1:
            wiggle_count = 3
        else:
            wiggle_count = int(line[1]) # convert str to int
        sm.wiggle(wiggle_count)
コード例 #2
0
    if key == "5":
        continuous_check()
    if key == "6":
        # set legs to body position
        legs_body()
    if key == "7":
        # set legs to stretch position
        legs_stretch()
    if key == "8":
        sm.clap(4)

    if key == "w":
        # Walk!
        sm.walkforward(100)
    if key == "s":
        sm.walkbackward(100)
    if key == "a":
        sm.turnleft()
    if key == "d":
        sm.turnright()
    if key == 'r':
        sm.stand()
    if key == "f":
        sm.sit()
    if key == "q":
        print("Good bye!")
    if key == "c":
        sm.clap(4)
    if key == "x":
        sm.wiggle(4)
コード例 #3
0
ファイル: ScratchListener.py プロジェクト: zhangfaquan/smars
    a.append(chr((n >> 8) & 0xFF))
    a.append(chr(n & 0xFF))
    scratchSock.send(a.tostring() + cmd)


def recvScratchCommand():
    msg = scratchSock.recv(42001)
    print(msg, "length =", len(msg))
    a = ""
    a = msg.split('"')
    print("a 0", a[0])
    print("a 1", a[1])
    cmd = a[1]
    return cmd


while True:
    cmd = recvScratchCommand()
    if cmd == "Walkforward":
        smars.walkforward(100)
    if cmd == "Walkbackward":
        smars.walkbackward(100)
    if cmd == "Sit":
        smars.sit()
    if cmd == "Stand":
        smars.stand()
    if cmd == "TurnLeft":
        smars.turnleft()
    if cmd == "TurnRight":
        smars.turnright()