Skip to content

Instantly share code, notes, and snippets.

@worace
Created April 20, 2012 20:05
Show Gist options
  • Select an option

  • Save worace/2431446 to your computer and use it in GitHub Desktop.

Select an option

Save worace/2431446 to your computer and use it in GitHub Desktop.
lego nxt sample script
$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
@j3j3
Copy link
Copy Markdown

j3j3 commented May 16, 2012

I'm inside you.

@j3j3
Copy link
Copy Markdown

j3j3 commented May 16, 2012

What an amazing gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment