예제 #1
0
    def startWebSocketClient(self):
        self.cannybot = CannybotClient()  #  Connects to the default Cannybot
        self.cannybot.registerReceiveCallback(self.processCannybotEvent)

        # If there's any trouble just exit, the service daemon will restart us
        self.cannybot.registerErrorCallback(self.stop)
        self.cannybot.registerClosedCallback(self.stop)

        self.joypad = JoypadClient(self.cannybot)
예제 #2
0
import csv
from time import sleep

from cannybots.clients.wsclient import CannybotClient
from cannybots.clients.joypad import JoypadClient

SPEED_DURATION = 2                      # Number of seconds to hold a speed for

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)
예제 #3
0
from time import sleep

from cannybots.clients.wsclient import CannybotClient
from cannybots.clients.joypad import JoypadClient

SPEED_DURATION = 2  # Number of seconds to hold a speed for

cannybot1 = CannybotClient(
    botId='2'
)  # Connects to the default Cannybot configured in NodeRED (using a local WebSocket API)
cannybot2 = CannybotClient(botId='3')

sleep(2)

rider1 = JoypadClient(
    cannybot1
)  # Creates a Joystick helper that can create and send joystick messages
rider2 = JoypadClient(cannybot2)

# 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)
예제 #4
0
import sys
import os
import csv
from time import sleep

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)