| Message: 18286 |
 |
BY: Emmanuel Pirsch (epirsch) DATE: 2007-02-21 00:04 SUBJECT: RE: Commands::Move and :turn_ratio I tried it with the latest source code from subversion and the it behaves the same. At first it turns in the right direction, but the next move command turn in the other direction before going straight (by what it looks like to be the same amount it turned)...
Here is a sample of my program that reproduce the problem:
------------------
require 'rubygems'
require 'nxt_comm'
require 'getoptlong'
def parse_options
opts= GetoptLong.new(
['--port', '-P', GetoptLong::REQUIRED_ARGUMENT]
)
# Initialize options with default values
options= {
:port => "/dev/rfcomm0"
}
begin
opts.each do |opt, arg|
case opt
when '--port'
options[:port]= arg
end
end
rescue
"ARG!"
end
options
end
def move(args = {})
defaults= {
:ports => [:b, :c],
:direction => :forward,
:duration => {:rotations => 2.7},
:next_action => :break,
:power => 75,
:turn_ratio => :straight
}
block= Commands::Move.new(@nxt)
block.ports= args[:ports] || defaults[:ports]
block.direction= args[:direction] || defaults[:direction]
block.duration= args[:duration] || defaults[:duration]
block.next_action= args[:next_action] || defaults[:next_action]
block.power= args[:power] || defaults[:power]
block.turn_ratio= args[:turn_ratio] || defaults[:turn_ratio]
block.start
end
def stop(args= {})
defaults= {:next_action => :break}
block= Commands::Move.new(@nxt)
block.next_action= args[:next_action] || defaults[:next_action]
block.stop
end
options= parse_options
puts "Starting Nxt with #{options}"
@nxt= NXTComm.new(options[:port])
puts "Connection established! Battery level = #{@nxt.get_battery_level / 1000.0}V."
move :turn_ratio => :left, :duration => {:seconds => 1}
move :duration => {:rotations => 3.5}
| |