Permalink
Browse files

OMG ROBOBRRD IS ON IRC! *squawk*

  • Loading branch information...
0 parents commit 0e0e909a8030af3bcbbc90f53798cbee74f78553 @RobotGrrl committed Oct 22, 2011
Binary file not shown.
@@ -0,0 +1,94 @@
+## Copyright (c) 2009 Benjamin Eckel
+##
+## This is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## with this; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+from ircbot import SingleServerIRCBot
+from irclib import nm_to_n, nm_to_h, irc_lower, ip_numstr_to_quad, ip_quad_to_numstr
+
+import inspect
+import Commands
+from Arduinos import Arduino
+
+class ArduinoBot(SingleServerIRCBot):
+
+ def __init__(self, arduino, channel, nickname, server, port=6667):
+ SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
+ self.channel = channel
+ self.arduino = arduino
+
+ def on_nicknameinuse(self, c, e):
+ c.nick(c.get_nickname() + "_")
+
+ def on_welcome(self, c, e):
+ c.join(self.channel)
+
+ def on_privmsg(self, c, e):
+ self.do_command(e, e.arguments()[0])
+
+ def on_pubmsg(self, c, e):
+ """
+ This function is called eveytime a public message is sent to the channel
+ and ArduinoIRCBot hears it.
+ you can get the source and message with (nick, message) = split_event(e)
+ """
+ (nick, message) = split_event(e)
+ try:
+ cmd = message.split(':')
+ if cmd[0].lstrip().rstrip() == c.get_nickname():
+ if Commands.DEBUG:
+ print "%s sent me %s" % (nick, message)
+ response = self.do_command(nick, cmd[1].lstrip().rstrip()) ## make sure no spaces before or after cmd
+ if Commands.DEBUG:
+ print 'response = %s\n' % response
+ self.send_pubmsg(c, response)
+ arduino.flush()
+ arduino.flushInput()
+ arduino.flushOutput()
+ except:
+ pass #ignore, message not for ArduinoBot, could log convo here
+ return
+
+ def send_pubmsg(self, c, message):
+ """Sends a public message to the forum"""
+ c.privmsg(self.channel, message)
+
+ def do_command(self, source, cmd):
+ """
+ This is where we will handle the so-called 'commands' to the Arduino
+ """
+ #c = self.connection
+
+ try:
+ cmd = cmd.split(' ')
+ if Commands.DEBUG:
+ print "cmd: %s" % cmd
+ if len(cmd) > 1:
+ return getModuleCallables()[cmd[0]](self.arduino, cmd[1:])
+ else:
+ return getModuleCallables()[cmd[0]](self.arduino)
+ except:
+ return ""#I don't care about that function"
+
+
+
+def getModuleCallables():
+ reload(Commands)
+ if Commands.DEBUG:
+ print "Callables: %s" % dict(inspect.getmembers(Commands, callable))
+ return dict(inspect.getmembers(Commands, callable))
+
+def split_event(e):
+ """Splits an event into the source (nickname) and message"""
+ return (nm_to_n(e.source()), e.arguments()[0])
Binary file not shown.
@@ -0,0 +1,33 @@
+## Copyright (c) 2009 Benjamin Eckel
+##
+## This is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## with this; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+import serial
+
+class Arduino():
+
+ def __init__(self, path='/dev/tty.usbserial', baud=9600):
+ self.ser = serial.Serial(path, baud)
+
+ def send(self, data):
+ self.ser.write(data)
+
+ def read(self, bytes):
+ while (1):
+ if (self.ser.inWaiting() > bytes-1):
+ return self.ser.read(bytes)
+
+ def flush():
+ self.ser.flushInput()
+ self.ser.flushInput()
Binary file not shown.
@@ -0,0 +1,117 @@
+## Copyright (c) 2009 Benjamin Eckel
+##
+## This is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## with this; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# module for configuration and commands
+#
+from Arduinos import Arduino
+import time
+
+# Program Settings
+DEBUG = True
+
+# IRC Settings
+NICK = "ROBOBRRD3000"
+SERVER = "irc.freenode.net"
+CHANNEL = "#GeekStreams"
+#SERVER = "chat1.ustream.tv"
+#CHANNEL = "#robot-party"
+PORT = 6667
+
+# Arduino Settings
+#USB_PATH = '/dev/tty.FireFly-514C-SPP' # bt
+#BAUD = 115200
+#USB_PATH = '/dev/tty.usbserial-A9007M4I' # wired MANOI
+#BAUD = 9600
+
+#USB_PATH = '/dev/tty.usbserial-A6T8R6YA' # wired YODA
+#BAUD = 9600
+
+#USB_PATH = '/dev/tty.usbserial-FTE4Z66C' # xb
+#BAUD = 9600
+
+USB_PATH = '/dev/tty.usbserial-A40082TP' # adk
+BAUD = 9600
+
+# ---
+# RoboBrrd
+
+def flapwings(arduino):
+ print "Flap Wings"
+ arduino.send('*')
+ arduino.send('FW')
+ arduino.send('*')
+ return ""
+
+def dance1(arduino):
+ print "Dance 1"
+ arduino.send('*')
+ arduino.send('D1')
+ arduino.send('*')
+ return ""
+
+def dance2(arduino):
+ print "Dance 2"
+ arduino.send('*')
+ arduino.send('D2')
+ arduino.send('*')
+ return ""
+
+def blink(arduino):
+ print "Blink"
+ arduino.send('*')
+ arduino.send('BL')
+ arduino.send('*')
+ return ""
+
+def asymptote(arduino):
+ print "Word winner!"
+ arduino.send('*')
+ arduino.send('WORD')
+ arduino.send('*')
+ return ""
+
+def chirp1(arduino):
+ print "Chirp1"
+ arduino.send('*')
+ arduino.send('C1')
+ arduino.send('*')
+ return ""
+
+def ir(arduino):
+ print "IR"
+ arduino.send('*')
+ arduino.send('IR')
+ arduino.send('*')
+
+ r = arduino.read(1)
+ while(r != "&"):
+ r = arduino.read(1)
+
+ if(r == "&"):
+ return arduino.read(4)
+ else:
+ return "oops"
+
+def wave(arduino):
+ print "Wave"
+ arduino.send('*')
+ arduino.send('WAV')
+ arduino.send('*')
+ return ""
+
+def help(arduino):
+ return ""
+
Binary file not shown.
@@ -0,0 +1,31 @@
+## Copyright (c) 2009 Benjamin Eckel
+##
+## This is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## with this; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#! /usr/bin/env python
+import Commands
+
+from ArduinoBot import *
+from Arduinos import Arduino
+
+def main():
+
+ bot = ArduinoBot(Arduino(Commands.USB_PATH, Commands.BAUD), Commands.CHANNEL, Commands.NICK, Commands.SERVER, Commands.PORT)
+ bot.start()
+
+if __name__ == "__main__":
+ main()
+
+
+
Oops, something went wrong.

0 comments on commit 0e0e909

Please sign in to comment.