Shop OBEX P1 Docs P2 Docs Learn Events
Juke Bot quesitons — Parallax Forums

Juke Bot quesitons

p_tp_t Posts: 15
edited 2013-03-27 12:11 in Robotics
I Just purchased a new propeller BOE and decided I would try and mimic the juke box project on the learn propeller site. I am brand new to spin programming so please excuse my questions if they seem simple. I am finding spin a bit more intense than Basic Stamp and could use some help with some clarification. My current setup is the same for the project except I just want to load the program straight to the board instead of being wireless due to funds atm, and I am skipping the music play till I can figure out how to make the bot roam. I would just like to turn on the bot and let it roam around. Here is the following code I am working on, I basically deleted the previous data for the Xbee receiver and changed Pub RobotNav to Pub Go. Below this code I posted the original code I cut from.

CURRENT CODE:

OBJ


drive : "PropBOE-Bot Servo Drive" ' Propeller Boe-Bot servo control
pingdar : "Ping)))Dar" ' Control turret, measure w. Ping


CON


PING = 17, TURRET = 16 ' Ping))) & turret servo I/O labels


DAT


' Ping)))Dar object requires number of elements, followed by a list of angles
' in ascending order, a list of cm minimum distances, and a list that orders
' when the Ping))) should be pointed in each direction.
elements long 11
angles long -90, -72, -54, -36, -18, 00, 18, 36, 54, 72, 90
space long 22, 22, 27, 27, 37, 37, 37, 27, 27, 22, 22
order long 0, 10, 1, 9, 2, 8, 3, 7, 4, 6, 5

VAR


long navCog, navStack[128] 'Stack space robot navigation cog


PUB Go '' Robot navigation method


drive.Rampstep(8, 8) ' Max speed signal change per 20 ms
drive.Wheels(100, 100) ' Wheels full speed forward
pingdar.Init(PING, TURRET, @elements) ' Initialize Ping)))Dar object


' Main loop sets wheels full to speed forward, then checks distance at the next angle
' in the list with pingdar.Advance. If it's less than the maximum allowed cm space
' at that angle, then it just keeps going forward. If not, then it directs the
' Ping))) 0-degrees and then rotates the robot until it sees an opening.


repeat
drive.Wheels(100, 100)
if pingdar.Advance < (pingdar.Space(pingdar.Angle))
if pingdar.Angle =< 0
drive.Wheels(-100, 100)
repeat until pingdar.Distance(0) > pingdar.Space(0)
else
drive.Wheels(100, -100)
repeat until pingdar.Distance(0) > pingdar.Space(0)


ORIGINAL CODE:
' Propeller Boe-Bot Receiver.spin


OBJ


system : "Propeller Board of Education" ' System configuration
time : "Timing" ' Time and delay convenience methods
xb : "XBee_Object" ' XB wireless communication
wav : "jm_wav_player" ' Wav player


CON
' I/O pin names
XB_DO = 4, XB_DI = 3 ' XBee transmit and receive


A_LF = 26, A_RT = 27 ' Audio left, right


#22, SD_DO, SD_CLK, SD_DI, SD_CS ' PropBOE microSD P22...P25


DAT


' List of I/O pin connections required by wav player's start method
wavIO long A_LF, A_RT, SD_DO, SD_CLK, SD_DI, SD_CS


PUB Go | status, key ''Code starts - top object top method

system.Clock(80_000_000) ' Set system clock to 80 MHz
xb.start(XB_DO, XB_DI, 0, 9_600) ' Start XBee object
time.pause(100) ' 1/10 second delay


repeat
status := wav.Start(@wavIO) ' Start wav player
if (status == 0) ' If started
quit ' Quit the loop
else ' If not started
time.Pause(250) ' Wait 1/4 second & try again


wav.Set_Volume(80, 80) ' Set wav player volume

repeat ' Main loop
if (key := xb.RxCheck) > 0 ' If incoming character, copy to key
case key ' & evaluate on case-by-case basis
"1":
if (wav.playing == false) ' If nothing playing
wav.play(string("crazy.wav"), 1) ' play crazy.wav one time
"2":
if (wav.playing == false) ' If nothing playing,
wav.play(string("levels.wav"), 1) ' play levels.wav one time
"3":
if (wav.playing == false) ' ...etc.
wav.play(string("somebody.wav"), 1)
"4":
if (wav.playing == false)
wav.play(string("dontstop.wav"), 1)
"5":
if (wav.playing == false)
wav.play(string("feeling.wav"), 1)
"R", "r": ' Start robot navigation
ifnot navcog ' Dont start it twice
navCog := cognew(RobotNav, @navStack) + 1 ' Remember cog it started in
"S", "s":
if navcog
drive.Stop ' Use drive to stop servo signal cog
cogstop(navCog~ -1) ' Stop robot navigation cog
"X", "x": ' Stop current wave
wav.kill


OBJ


drive : "PropBOE-Bot Servo Drive" ' Propeller Boe-Bot servo control
pingdar : "Ping)))Dar" ' Control turret, measure w. Ping


CON


PING = 17, TURRET = 16 ' Ping))) & turret servo I/O labels


DAT


' Ping)))Dar object requires number of elements, followed by a list of angles
' in ascending order, a list of cm minimum distances, and a list that orders
' when the Ping))) should be pointed in each direction.
elements long 11
angles long -90, -72, -54, -36, -18, 00, 18, 36, 54, 72, 90
space long 22, 22, 27, 27, 37, 37, 37, 27, 27, 22, 22
order long 0, 10, 1, 9, 2, 8, 3, 7, 4, 6, 5

VAR


long navCog, navStack[128] 'Stack space robot navigation cog


PUB RobotNav '' Robot navigation method


drive.Rampstep(8, 8) ' Max speed signal change per 20 ms
drive.Wheels(100, 100) ' Wheels full speed forward
pingdar.Init(PING, TURRET, @elements) ' Initialize Ping)))Dar object


' Main loop sets wheels full to speed forward, then checks distance at the next angle
' in the list with pingdar.Advance. If it's less than the maximum allowed cm space
' at that angle, then it just keeps going forward. If not, then it directs the
' Ping))) 0-degrees and then rotates the robot until it sees an opening.


repeat
drive.Wheels(100, 100)
if pingdar.Advance < (pingdar.Space(pingdar.Angle))
if pingdar.Angle =< 0
drive.Wheels(-100, 100)
repeat until pingdar.Distance(0) > pingdar.Space(0)
else
drive.Wheels(100, -100)
repeat until pingdar.Distance(0) > pingdar.Space(0)

Comments

  • p_tp_t Posts: 15
    edited 2013-03-27 12:11
    Well I finally found out my problem.

    I did not have system.Clock and the obj in my new code. If anyone else wants to try and has problems here is my new code, right now im trying to play music while it is moving.

    OBJ


    system : "Propeller Board of Education" ' System configuration
    time : "Timing" ' Time and delay convenience methods
    drive : "PropBOE-Bot Servo Drive" ' Propeller Boe-Bot servo control
    pingdar : "Ping)))Dar" ' Control turret, measure w. Ping
    wav : "jm_wav_player" ' Wav player


    CON
    PING = 19, TURRET = 18 ' Ping))) & turret servo I/O labels
    A_LF = 26, A_RT = 27 ' Audio left, right


    #22, SD_DO, SD_CLK, SD_DI, SD_CS ' PropBOE microSD P22...P25


    DAT


    ' List of I/O pin connections required by wav player's start method
    wavIO long A_LF, A_RT, SD_DO, SD_CLK, SD_DI, SD_CS


    DAT


    ' Ping)))Dar object requires number of elements, followed by a list of angles
    ' in ascending order, a list of cm minimum distances, and a list that orders
    ' when the Ping))) should be pointed in each direction.
    elements long 11
    angles long -90, -72, -54, -36, -18, 00, 18, 36, 54, 72, 90
    space long 22, 22, 27, 27, 37, 37, 37, 27, 27, 22, 22
    order long 0, 10, 1, 9, 2, 8, 3, 7, 4, 6, 5


    PUB Go
    system.Clock(80_000_000)
    drive.Rampstep(8, 8) ' Max speed signal change per 20 ms
    drive.Wheels(100, 100) ' Wheels full speed forward
    pingdar.Init(PING, TURRET, @elements) ' Initialize Ping)))Dar object


    ' Main loop sets wheels full to speed forward, then checks distance at the next angle
    ' in the list with pingdar.Advance. If it's less than the maximum allowed cm space
    ' at that angle, then it just keeps going forward. If not, then it directs the
    ' Ping))) 0-degrees and then rotates the robot until it sees an opening.


    repeat
    drive.Wheels(100, 100)
    if pingdar.Advance < (pingdar.Space(pingdar.Angle))
    if pingdar.Angle =< 0
    drive.Wheels(-100, 100)
    repeat until pingdar.Distance(0) > pingdar.Space(0)
    else
    drive.Wheels(100, -100)
    repeat until pingdar.Distance(0) > pingdar.Space(0)
Sign In or Register to comment.