Permalink
Browse files

Initial import.

git-svn-id: svn+ssh://rubyforge.org/var/svn/ruby-nxt/trunk@2 a85beeab-be1c-0410-a5ed-88d17ee140f9
  • Loading branch information...
1 parent bc85d1c commit 8005199e89c408f0ba65dc4babf55bb48cc0ba2e gunark committed Sep 7, 2006
Showing with 4,646 additions and 0 deletions.
  1. +17 −0 .project
  2. +16 −0 ruby/README
  3. +47 −0 ruby/brick.rb
  4. +78 −0 ruby/examples/mary.rb
  5. +68 −0 ruby/examples/nxt_comm_demo.rb
  6. +257 −0 ruby/motor.rb
  7. +127 −0 ruby/nxt.rb
  8. +289 −0 ruby/nxt_comm.rb
  9. +101 −0 ruby/test/motor_test.rb
  10. +50 −0 ruby/test/nxt_test.rb
  11. +137 −0 www/classes/Array.html
  12. +18 −0 www/classes/Array.src/M000002.html
  13. +142 −0 www/classes/Bignum.html
  14. +18 −0 www/classes/Bignum.src/M000021.html
  15. +144 −0 www/classes/Brick.html
  16. +26 −0 www/classes/Brick.src/M000001.html
  17. +471 −0 www/classes/Motor.html
  18. +26 −0 www/classes/Motor.src/M000003.html
  19. +22 −0 www/classes/Motor.src/M000004.html
  20. +20 −0 www/classes/Motor.src/M000005.html
  21. +20 −0 www/classes/Motor.src/M000006.html
  22. +24 −0 www/classes/Motor.src/M000007.html
  23. +19 −0 www/classes/Motor.src/M000008.html
  24. +55 −0 www/classes/Motor.src/M000009.html
  25. +19 −0 www/classes/Motor.src/M000010.html
  26. +20 −0 www/classes/Motor.src/M000011.html
  27. +35 −0 www/classes/Motor.src/M000012.html
  28. +278 −0 www/classes/NXT.html
  29. +23 −0 www/classes/NXT.src/M000024.html
  30. +25 −0 www/classes/NXT.src/M000025.html
  31. +24 −0 www/classes/NXT.src/M000026.html
  32. +26 −0 www/classes/NXT.src/M000027.html
  33. +19 −0 www/classes/NXT.src/M000028.html
  34. +543 −0 www/classes/NXTComm.html
  35. +25 −0 www/classes/NXTComm.src/M000013.html
  36. +35 −0 www/classes/NXTComm.src/M000014.html
  37. +20 −0 www/classes/NXTComm.src/M000015.html
  38. +22 −0 www/classes/NXTComm.src/M000016.html
  39. +40 −0 www/classes/NXTComm.src/M000017.html
  40. +26 −0 www/classes/NXTComm.src/M000018.html
  41. +35 −0 www/classes/NXTComm.src/M000019.html
  42. +19 −0 www/classes/NXTComm.src/M000020.html
  43. +152 −0 www/classes/String.html
  44. +20 −0 www/classes/String.src/M000022.html
  45. +21 −0 www/classes/String.src/M000023.html
  46. +1 −0 www/created.rid
  47. +130 −0 www/files/README.html
  48. +132 −0 www/files/brick_rb.html
  49. +148 −0 www/files/motor_rb.html
  50. +133 −0 www/files/nxt_comm_rb.html
  51. +133 −0 www/files/nxt_rb.html
  52. +33 −0 www/fr_class_index.html
  53. +31 −0 www/fr_file_index.html
  54. +54 −0 www/fr_method_index.html
  55. +24 −0 www/index.html
  56. +208 −0 www/rdoc-style.css
View
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>ruby-nxt</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.rubypeople.rdt.core.rubybuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.rubypeople.rdt.core.rubynature</nature>
+ </natures>
+</projectDescription>
View
@@ -0,0 +1,16 @@
+= ruby-nxt
+
+==== The ruby-nxt library lets you control the LEGO Mindstorms NXT robotics kit via Bluetooth using the Ruby language.
+
+<em>This library is currently in the early stages of development and is far from complete.</em>
+
+There are two interfaces:
+
+- The NXT class provides a high-level, multi-threaded, object-oriented interface.
+ Currently only motor functionality is implemented (sensors aren't).
+
+- The NXTComm class provides low-level direct access to the NXT Bluetooth
+ protocol.
+
+ruby-nxt requires ruby-serialport which you must download and install from:
+http://raa.ruby-lang.org/project/ruby-serialport
View
@@ -0,0 +1,47 @@
+# ruby-nxt Control Mindstorms NXT via Bluetooth Serial Port Connection
+# Copyright (C) 2006 Matt Zukowski <matt@roughest.net>
+#
+# This program 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
+#
+# This program 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
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require 'nxt_comm'
+
+# Abstract parent class of motor and sensor bricks.
+# Currently provides only very basic common functionality but may
+# be expanded in the future.
+class Brick
+
+ def initialize(port, dev = $DEV)
+ logfile = File.expand_path(File.dirname(__FILE__))+"/#{self.class}_#{port}.log"
+ @log = Logger.new logfile
+ @log.level = Logger::DEBUG
+ #puts "Logging to #{logfile}"
+
+ debug("#{self.class}::#{dev}(#{port})", :initialize)
+
+ @nxt = NXTComm.connect(dev)
+ @nxt.start
+ end
+
+ private
+ def debug(msg, method = false)
+ @log.info(method) do
+ if msg.kind_of? String
+ msg
+ else
+ msg.to_yaml
+ end
+ end
+ end
+
+end
View
@@ -0,0 +1,78 @@
+#!/usr/local/bin/ruby
+
+# Plays "Mary Had A Little Lamb"
+# Author: Christopher Continanza <christopher.continanza@villanova.edu>
+
+require 'nxt_comm'
+
+$DEBUG = true
+
+def sleeper
+ sleep(0.5)
+end
+
+NXTComm.exec("/dev/tty.NXT-DevB-1") do |cmd|
+
+ #E D C D E E E
+ cmd.PlayTone(659,500)
+ sleeper
+ cmd.PlayTone(587,500)
+ sleeper
+ cmd.PlayTone(523,500)
+ sleeper
+ cmd.PlayTone(587,500)
+ sleeper
+ cmd.PlayTone(659,500)
+ sleeper
+ cmd.PlayTone(659,500)
+ sleeper
+ cmd.PlayTone(659,500)
+ sleeper
+ sleeper
+ #D D D E G G
+ cmd.PlayTone(587,500)
+ sleeper
+ cmd.PlayTone(587,500)
+ sleeper
+ cmd.PlayTone(587,500)
+ sleeper
+ sleeper
+ cmd.PlayTone(659,500)
+ sleeper
+ cmd.PlayTone(784,500)
+ sleeper
+ cmd.PlayTone(784,500)
+ sleeper
+ sleeper
+ #E D C D E E E
+ cmd.PlayTone(659,500)
+ sleeper
+ cmd.PlayTone(587,500)
+ sleeper
+ cmd.PlayTone(523,500)
+ sleeper
+ cmd.PlayTone(587,500)
+ sleeper
+ cmd.PlayTone(659,500)
+ sleeper
+ cmd.PlayTone(659,500)
+ sleeper
+ cmd.PlayTone(659,500)
+ sleeper
+ #E D D E D C
+ cmd.PlayTone(659,500)
+ sleeper
+ cmd.PlayTone(587,500)
+ sleeper
+ cmd.PlayTone(587,500)
+ sleeper
+ cmd.PlayTone(659,500)
+ sleeper
+ cmd.PlayTone(587,500)
+ sleeper
+ cmd.PlayTone(523,750)
+ sleeper
+ sleeper
+ sleeper
+
+end
@@ -0,0 +1,68 @@
+#!/usr/local/bin/ruby
+
+require 'nxt_comm'
+
+$DEBUG = false
+
+NXTComm.exec("/dev/tty.NXT-DevB-1") do |cmd|
+
+ # StartProgram(filename)
+ # cmd.StartProgram("Try-Touch.rtm")
+
+ # StopProgram - stops any currently running programs
+ # cmd.StopProgram
+
+ # PlaySoundFile(loop?,filename)
+ # cmd.PlaySoundFile(false,"Good Job.rso")
+
+ # PlayTone(frequency,duration)
+ cmd.PlayTone(50,500)
+
+ # SetOutputState(port,power,mode,regulation,turn ratio,run state,tacho limit)
+# cmd.SetOutputState(
+# NXTComm::MOTOR_B,
+# 100,
+# NXTComm::MOTORON | NXTComm::BRAKE | NXTComm::REGULATED,
+# NXTComm::REGULATION_MODE_MOTOR_SPEED,
+# 100,
+# NXTComm::MOTOR_RUN_STATE_RUNNING,
+# 0
+# )
+# sleep(5)
+# cmd.SetOutputState(
+# NXTComm::MOTOR_B,
+# 100,
+# NXTComm::MOTORON | NXTComm::BRAKE | NXTComm::REGULATED,
+# NXTComm::REGULATION_MODE_MOTOR_SPEED,
+# 0,
+# NXTComm::MOTOR_RUN_STATE_RAMPDOWN,
+# 0
+# )
+
+ # SetInputMode(port,type,mode)
+ # cmd.SetInputMode(NXTComm::SENSOR_1,NXTComm::SWITCH,NXTComm::RAWMODE)
+
+ #GetOutputState(motor_port)
+ puts "GetOutputState: #{cmd.GetOutputState(NXTComm::MOTOR_B)}"
+
+ # GetInputValues(sensor_port)
+ # cmd.GetInputValues(NXTComm::SENSOR_1)
+
+ # ResetInputScaledValue(sensor_port)
+ # cmd.ResetInputScaledValue(NXTComm::SENSOR_1)
+
+ # MessageWrite(mailbox,message)
+ # cmd.MessageWrite(1,"Chunky Robotic Bacon!")
+
+ # ResetMotorPosition(motor_port,relative?)
+ # cmd.ResetMotorPosition(NXTComm::MOTOR_B,false)
+
+ # GetBatteryLevel
+ puts "Battery Level: #{cmd.GetBatteryLevel[0]/1000.0} V"
+
+ # StopSoundPlayback - stops any currently playing sounds
+ #cmd.PlaySoundFile(true,"Woops.rso")
+ #sleep(3)
+ #cmd.StopSoundPlayback
+
+end
Oops, something went wrong.

0 comments on commit 8005199

Please sign in to comment.