To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.nxtOpen lugnet.robotics.nxt in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / NXT / 881
880  |  882
Subject: 
pbLua Beta 13c Sumo program
Newsgroups: 
lugnet.robotics.nxt
Date: 
Sun, 19 Aug 2007 16:54:46 GMT
Viewed: 
21695 times
  
I posted earlier about my first impressions of pbLua Beta 13c and some
things I couldn't figure out, mainly having to do with numbers.  Ralph
Hempel promptly replied and some of the concepts are a bit over my head so I
decided I should just plow ahead with a simple application.  I have written
a simple sumo program.

For this program, simple does not equal consise.  There are over two hundred
lines of code, mostly dealing with calibration and instructions for the
competitor and handling the fact that some arenas are black with a white
ring and some are white with a black ring.  Screen shots and the entire
program are available at
http://firstcoolbreeze.home.comcast.net/SumoSimple/SumoSimple.htm

The simple part of the program is the strategy:  go forward until the robot
senses the edge, reverse, spin in place, repeat forever.

Comments and suggestions for improvement are welcome.  I would appreciate
some help with the Tacho features of pbLua.  I experimented quite a bit and
am still baffled.  I want the robot to back up 270 degrees of a wheel
rotation and similarly spin in place for some number of degrees of wheel
rotation.

Since I couldn't figure out the Tacho commands, I have the robot reverse for
half a second and spin in place for half a second.  With low battery voltage
the spin in place results in a 90 degree spin.  On full battery voltage the
spin results in a 180 degree spin.  Here's the code.  The variable
"PowerLevel" is set by the competitor during the calibration routines.  The
variable "boundary" is also calculated during calibration.

    nxt.OutputSetRegulation( 2, 1, 1) -- motor B, regulated state, brake
mode
    nxt.OutputSetRegulation( 3, 1, 1) -- motor C, regulated state, brake
mode
    while true do
        nxt.OutputSetSpeed( 2, 32, PowerLevel )  -- motor B, runstate = 32 =
run motor
        nxt.OutputSetSpeed( 3, 32, PowerLevel )  -- motor C, runstate = 32 =
run motor
        rawAD, state0, state1 = nxt.InputGetState( LightSensorPort ) -- read
light sensor into rawAD
        while rawAD > boundary do
                rawAD, state0, state1 = nxt.InputGetState( LightSensorPort )
        end
        -- At the boundary.  Stop motor using "0."  Without this, robot
overshoots quite a bit.
        nxt.OutputSetSpeed( 2, 32, 0 )  -- motor B
        nxt.OutputSetSpeed( 3, 32, 0 )  -- motor C
        -- Go backwards half a second.
        nxt.OutputSetSpeed( 2, 32, -PowerLevel )  -- motor B, run motor,
backwards
        nxt.OutputSetSpeed( 3, 32, -PowerLevel )  -- motor C, run motor,
backwards
        nowTime =  nxt.TimerRead()
        while nxt.TimerRead() < nowTime + 500 do end
        -- spin in place by setting one motor to forward
        nxt.OutputSetSpeed( 2, 32, PowerLevel )  -- motor B
        -- spin in place for half a second
        nowTime =  nxt.TimerRead()
        while nxt.TimerRead() < nowTime + 500 do end
    end


Walt White



Message has 1 Reply:
  Re: pbLua Beta 13c Sumo program
 
(...) That's a great idea. My kids worked on an RCX based sumo bot last year in school, and just last week they were asking about using the NXT and the new motors. Maybe it's time to build a robot instead of write software all the time :-) (...) 1. (...) (17 years ago, 19-Aug-07, to lugnet.robotics.nxt)

2 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    
Active threads in NXT programmable brick

 
Verified and Trusted Team of Hackers
15 hours ago
Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR