Norbert is my latest project: a robot that I plan on building up and programming.
I've got the motor hooked up and running, "mocking out" the control logic to a pair of switches. The plan is to get my laptop on board and control the motors through the serial port. Apparently the circuitry for such a task involves using a UART chip to convert the serial signals into something usable, which is going to be a bit of a challenge for me; I haven't worked with ICs before.
Currently Norbert is capable of backward and forward motion as well as turning, though the limitation of using switches on the chassis makes control somewhat impractical.
The plan is all laid out in terms of what revisions will include what features:
I drummed up a bit of code for the controller before I had really decided on parallel vs serial. (I had an old laptop I was considering using that had an easier-to-interface-with parallel port, but it was lacking a battery.) Hopefully it shouldn't be too difficult to modify it to use the ruby-serialport library.
class Robot COMMAND_BITS = [: right_motor_forward, : right_motor_backward, : left_motor_forward, : left_motor_backward] def go_forward write_byte aggregate_commands(: right_motor_forward, : left_motor_forward) end # [go_backward and other commands...] def aggregate_commands(*commands) commands.inject(0) do |aggregate, command| aggregate | bit_place(COMMAND_BITS.index (command)) end end def bit_place(place) (2 ** place) end def write_byte(byte) # http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/24605 p = open('/dev/port', 'w') # open /dev/port in write mode p.sync = true # turn buffering off, write to the # port as soon as it is requested p.seek(0x378, IO: : SEEK_SET) # move writing cursor to the parallel # port address p.putc(byte) # write byte to it and activate # whatever on your I/O board is # attached to the D0 pin end end
๛