def main(): #This is how you should connect to your spark. This code must execute #before the raspberry pi can talk to the spark hat. addr = "tcp://raspberrypi.local:4567" comm = NET_ZMQ_Comm() try: comm.open(addr) except: print "Error connecting to Spark" sys.exit() spark = Spark_Drive(comm) drive_loop(spark) #call the never ending "drive_loop" function
def main(): addr = raw_input( "Address of target (tcp://its.ip.add.ress:port) or hit enter for local USB:" ) if addr == "-": addr = "tcp://raspberrypi.local:4567" if addr == "": comm = HID_Comm() try: comm.open() except IOError, ex: print "Spark not found:", ex sys.exit() else: comm = NET_ZMQ_Comm() try: comm.open(addr) except: print "Error connecting to Spark" sys.exit() spark = Spark_Drive(comm) us_loop(spark) def us_loop(spark): while (1): print(65535 - spark.get_ultrasonic(1)) print(65535 - spark.get_ultrasonic(2)) time.sleep(1)
# Distributed under terms of the MIT license. """ This is a basic script to remote control the CoroBot Spark from your computer """ import sys from Spark_Control import HID_Comm, NET_ZMQ_Comm, Spark_Drive from readchar import readkey def main(): address = raw_input("Address of Spark or press 'return' if using board") if address == "-": address == "tcp://CoroBotSpark.local:4567" elif address == "": comm = HID_Comm() try: comm.open() except IOError, ex: print("Spark not found:", ex) sys.exit() else: comm = NET_ZMQ_Comm() try: comm.open(address) except: print("Error connecting to Spark") sys.exit() spark = Spark_Drive(comm) drive_spark(spark)
from Spark_Control import HID_Comm, NET_ZMQ_Comm, Spark_Drive import time def main(): addr = raw_input("Address of target (tcp://its.ip.add.ress:port) or hit enter for local USB:") if addr == "-": addr = "tcp://raspberrypi.local:4567" if addr == "": comm = HID_Comm() try: comm.open() except IOError, ex: print "Spark not found:",ex sys.exit() else: comm = NET_ZMQ_Comm() try: comm.open(addr) except: print "Error connecting to Spark" sys.exit() spark = Spark_Drive(comm) drive_loop(spark) def drive_loop(spark): while(1): print("Driving forward") spark.set_motor_speed(6, 12500) spark.set_motor_speed(5, 12500) #repeat command to try and get more consistent sets on motor speed.
if((weighted_sum_deriv * time_since_last_pkt)>tune_val): return controller else: return None if __name__ == '__main__': addr = "" try: if not sys.argv[1] == "-q": addr = raw_input("Address of target (its.ip.add.ress:port) or hit enter for local USB:") except: addr = raw_input("Address of target (its.ip.add.ress:port) or hit enter for local USB:") if addr == "": comm = HID_Comm() try: comm.open() except IOError, ex: print "Spark not found:",ex sys.exit() else: comm = NET_ZMQ_Comm() try: comm.open("tcp://"+addr) except: print "Error connecting to Spark" sys.exit() sparkout = Spark_Drive(comm) gamepad = Spark_Gamepad(sparkout) js = gamepad.create_joystick() gamepad.control_loop(js)