コード例 #1
0
# Open a csv files that has rows of Speeds in
# This uses the first row in the CSV for the column names (see the speeds.csv)
input_file = csv.DictReader(
    open("Cycling Data for Cannybots.xlsx - Cyclists.csv"))

for row in input_file:

    # Read the speed from column which has the title of 'Speed' in the current row
    inputDataRider1Speed = float(row["Rider One Speed (km/Hr)"])
    inputDataRider2Speed = float(row["Rider Two Speed (km/Hr)"])

    # scale the input speed to between 0 (stop) and 255 (full speed)
    # these values were chosen by hand after inspecting the input data
    rider1Speed = 255 - (50 + inputDataRider1Speed * 8)
    rider2Speed = 255 - (50 + inputDataRider2Speed * 8)

    print "Input Data speed: {}  => Rider 1 speed: {}".format(
        inputDataRider1Speed, rider1Speed)
    print "Input Data speed: {}  => Rider 2 speed: {}".format(
        inputDataRider2Speed, rider2Speed)

    # send the forward speed
    rider1.update(0, rider1Speed, 0, 0)
    rider2.update(0, rider2Speed, 0, 0)

    # hold the speed for a number of seconds
    sleep(SPEED_DURATION)

rider1.stop()  # Stop the Cannybot
rider2.stop()
コード例 #2
0
# Open a csv files that has rows of Speeds in
# This uses the first row in the CSV for the column names (see the speeds.csv)
input_file = csv.DictReader(open("Cycling Data for Cannybots.xlsx - Cyclists.csv"))


for row in input_file:

    # Read the speed from column which has the title of 'Speed' in the current row
    inputDataRider1Speed = float(row["Rider One Speed (km/Hr)"])
    inputDataRider2Speed = float(row["Rider Two Speed (km/Hr)"])

    # scale the input speed to between 0 (stop) and 255 (full speed)
    # these values were chosen by hand after inspecting the input data
    rider1Speed = 255 - (50 + inputDataRider1Speed * 8)
    rider2Speed = 255 - (50 + inputDataRider2Speed * 8)

    print "Input Data speed: {}  => Rider 1 speed: {}".format(inputDataRider1Speed, rider1Speed)
    print "Input Data speed: {}  => Rider 2 speed: {}".format(inputDataRider2Speed, rider2Speed)

    # send the forward speed
    rider1.update(0, rider1Speed, 0, 0)
    rider2.update(0, rider2Speed, 0, 0)

    # hold the speed for a number of seconds
    sleep(SPEED_DURATION)


rider1.stop()       # Stop the Cannybot
rider2.stop()

コード例 #3
0
ファイル: sendSpeeds.py プロジェクト: puvadeee/bluebrain
cannybot = CannybotClient()             # Connects to the default Cannybot configured in NodeRED (using a local WebSocket API)
joypad   = JoypadClient(cannybot)       # Creates a Joystick helper that can create and send joystick messages


# Open a csv files that has rows of Speeds in
# This uses the first row in the CSV for the column names (see the speeds.csv)
input_file = csv.DictReader(open("speeds.csv"))


for row in input_file:

    # Read the speed from column which has the title of 'Speed' in the current row
    inputDataSpeed = float(row["Speed"])

    # scale the input speed to between 0 (stop) and 255 (full speed)
    # these values were chosen by hand after inspecting the input data
    cannybotSpeed = 50 + inputDataSpeed * 10

    print "Input Data speed: {}  => Cannybot speed: {}".format(inputDataSpeed, cannybotSpeed)

    # send the forward speed
    joypad.update(0, cannybotSpeed, 0, 0)

    # hold the speed for a number of seconds
    sleep(SPEED_DURATION)


joypad.stop()       # Stop the Cannybot


コード例 #4
0
ファイル: joypad_test.py プロジェクト: puvadeee/bluebrain
from cannybots.clients.wsclient import CannybotClient
from cannybots.clients.joypad import JoypadClient


def dataReceived(message):
    print "Received: " + message

cannybot = CannybotClient()             #  Connects to the first available Cannybot
joypad   = JoypadClient(cannybot)
cannybot.registerReceiveCallback(dataReceived)

sleep(2)  # wait a bit for connection setup

joypad.requestStatus()

#for speed in range(-255 , 255):
#    print "Speed: " + str(speed)
#    joypad.update(speed, speed, 0, 0)
#    sleep(0.25)

for speed in range(1,5):
    motorASpeed = speed*50
    motorBSpeed = speed*50
    joypad.update(motorASpeed, motorBSpeed, 0, 0)
    sleep(1)


joypad.stop()