Created
April 20, 2012 20:05
-
-
Save worace/2431446 to your computer and use it in GitHub Desktop.
lego nxt sample script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$LOAD_PATH.unshift('./lib').uniq! | |
require 'lego_nxt/usb_connection' | |
require 'lego_nxt/constants' | |
@subject = LegoNXT::UsbConnection.new | |
ops = [LegoNXT::DirectOps::NO_RESPONSE, | |
LegoNXT::DirectOps::PLAYTONE, | |
500, | |
500].pack('CCvv') | |
@subject.transmit(ops) | |
@subject.close | |
@subject = LegoNXT::UsbConnection.new | |
motor_activate = [LegoNXT::DirectOps::NO_RESPONSE, | |
LegoNXT::DirectOps::SETOUTPUTSTATE, | |
0xFF, # output port | |
100, # power set point | |
0x01, # mode; 0x01 => Motor On | |
0x00, # Regulation Mode | |
0, # Turn Ratio (-100 - 100) | |
0x20, # Run State? - Idle/Ramp-up/Running/Ramp-down | |
1000].pack('C*') # TachoLimit (run time?) | |
puts motor_activate.inspect | |
@subject.transmit(motor_activate) | |
@subject.close | |
sleep 0.5 | |
@subject = LegoNXT::UsbConnection.new | |
motor_activate = [LegoNXT::DirectOps::NO_RESPONSE, | |
LegoNXT::DirectOps::SETOUTPUTSTATE, | |
0xFF, # output port | |
-100, # power set point | |
0x01, # mode; 0x01 => Motor On | |
0x00, # Regulation Mode | |
0x00, # Turn Ratio (-100 - 100) | |
0x20, # Run State? - Idle/Ramp-up/Running/Ramp-down | |
1000].pack('C*') # TachoLimit (run time?) | |
puts motor_activate.inspect | |
@subject.transmit(motor_activate) | |
@subject.close | |
sleep 0.5 |
I'm inside you.
What an amazing gist.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
{comment}