Shop OBEX P1 Docs P2 Docs Learn Events
Stingray Sample / Demo Code? — Parallax Forums

Stingray Sample / Demo Code?

MasterCMasterC Posts: 39
edited 2010-09-14 07:37 in Robotics
Hi,

I am kind of shocked, but I have not been able to find any basic demo or sample code for getting started with the Stingray robot. It seems like a basic resource for the out-of-the-box Stingray kit would be useful. At least something simple...go forward, spin in circles, gradual turn, reverse...that kind of thing. ANYTHING, really. I was also surprised to find that searching the OBEX for "Stringray" turns up nothing at all.

Anyway, does anybody have some basic code that would make the Stingray do something? No sensors, just the kit, freshly assembled from the box. It's a long story, but I basically had 4 hours of time given to me at work to assemble the kit and make it do something interesting. However, since it took me 3 hours to assemble, there's no way I can make it do something useful in an hour starting from scratch. I had sort of thought that it would come pre-loaded with a cool demo like the Prop. Demo Board, but no luck.

Thanks!

Comments

  • SRLMSRLM Posts: 5,045
    edited 2009-12-15 04:45
    Below is some code that makes control of the motors easy at the expense of flexibility. Basically, it is a function that takes a "heading" (how hard you want to turn) and a speed (what the minimum speed is that you want). With it you should be able to write a simple program that just spins the motors however you want. The block commented code is just an example of how to use it (based on sensor input in this case, but you won't need that for a demonstration).


    CON
    
      _xinfreq = 5_000_000
      _clkmode = xtal1 + pll16x
    
      lmforward = 25 
      lmbackward = 24
      rmforward = 26
      rmbackward = 27
    
      period = 5000 'for PWM object
    
      basespeed = 22
    
    OBJ
      pwm  :  "PWM_32_v2"
    
    
    PUB Main 
      pwm.start
    
    'your code
    
     {if(binout == 1) 'turn slightly right
          calculatemotor(20,20)
        elseif(binout == 1) ' turn slightly left
          calculatemotor(-20,20)
        elseif(binout[noparse][[/noparse]0] == 1) 'Turn harder right
          calculatemotor(35, 0)
        elseif(binout == 1)
          calculatemotor(-35,0) 'turn harder left
        else 'if(binout == 1 or binout == 1) 'go straight
          calculatemotor(0,20)
        }
    
    PUB calculatemotor(turnrate, speed)
      
    
    {
    A turn rate of 0 is straight, -100 is full left, 100 is full right
    
    speed is how fast to "turn" minimum, used for going straight, + is forward, - is backwards
    -Units same as above
    
    }
      speed := -100 #> speed <# 100
      turnrate := -100 #> turnrate <# 100
      if turnrate == 0
        if(speed => 0) 'Go straight forward
          pwm.duty(rmbackward, 0,0)
          pwm.duty(lmbackward, 0,0)
          pwm.duty(lmforward, speed, period)
          pwm.duty(rmforward, speed, period)
        else 'Go straight backwards
          ||speed
          pwm.duty(rmforward, 0,0)
          pwm.duty(lmforward, 0,0)
          pwm.duty(lmbackward, ||speed, period)
          pwm.duty(rmbackward, ||speed, period)
    
      elseif(turnrate > 0) 'turn right
        if(speed => 0) 'Go on a curve forward right
          pwm.duty(rmbackward, 0,0)
          pwm.duty(lmbackward, 0,0)
          pwm.duty(lmforward, (speed+turnrate)<#100, period)
          pwm.duty(rmforward, speed, period)
        else 'Go on a curve backwards right
          pwm.duty(rmforward, 0,0)
          pwm.duty(lmforward, 0,0)
          pwm.duty(lmbackward, (||speed+turnrate)<#100, period)
          pwm.duty(rmbackward, ||speed, period)
    
      
      elseif(turnrate < 0) 'turn left
        ||turnrate
        if(speed => 0) 'Go on a curve forward left
          pwm.duty(rmbackward, 0,0)
          pwm.duty(lmbackward, 0,0)
          pwm.duty(rmforward, (speed+turnrate)<#100, period)
          pwm.duty(lmforward, speed, period)
        else 'Go on a curve backwards left
          pwm.duty(rmforward, 0,0)
          pwm.duty(lmforward, 0,0)
          pwm.duty(rmbackward, (||speed+turnrate)<#100, period)
          pwm.duty(lmbackward, ||speed, period)
       
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Powered by enthusiasm
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-12-15 15:37
    Hello,

    The Stingray was designed to be an advanced robotics platform which could be adapted to a variety of purposes. This is one reason the control board was set up the way it was. I totally understand your frustration at not seeing code specifically labeled as being for the Stingray.

    The PWM code that SRLM refers to was written with the Stingray in mind. It was not labeled for the Stingray because it is useful in many applications, however if a custom object had been written that was specific to the Stingray, the name would have carried over. Page 24 of the documentation mentions using the PWM_32 object for a drive system, however existing code had not been created pending determination of initial sensors configurations. That is, I had hoped to see what types of sensors customers would be connecting to the Stingray in order to develop some useful code for driving the wheels using PWM_32 which would work well with the common sensor configuration.

    In all fairness to Parallax this is an error on my part. Demand was there to release the Stingray before we had any accessories for it and I have been somewhat content to watch and see what others have come up with given the basic hardware and software. Currently I am working on an encoder object and accessory for the wheels. This (in my opinion) is the first step toward driving (pun intended) this robot forward in a straight line.

    When Parallax opens back up after the New Year I intend to have a working example of using the wheel encoders with some other sensors to roam the Stingray autonomously. This will be a first step toward line following, GPS navigation, and object tracking that I will be working on during the first few months of the coming year. Parallax values our customer input, so during that time I will also be revisiting the comments, suggestions and feedback provided by you, the customer, to see what items we can address to make the Stingray a more complete and well-rounded package. Thanks again for your input and stay tuned! There’s more to come!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    Check out the new Savage Circuits TV!
    ·
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2009-12-15 16:42
    I can't wait until I can get the "encoder object and accessory" to put on my Stingray! [noparse]:)[/noparse]
    I've already got the Pings for Stingray kit installed, and I also have a H55B Compass Module, Memsic Dual-Axis Accelerometer, and PIR Sensor that I intend to use with the Stingray.
    I would like to eventually get my Stingray roaming around my house (perhaps keeping some sort of mapping of the area) autonomously! Mostly just to chase my 2 cats around (or be chased by them once they get used to it). [noparse]:)[/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out the Propeller Wiki·and contribute if you can.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-12-15 17:08
    Roy,

    The encoder object will be package with a demo object that uses the PING))) sensors as well. Autonomous roaming is nice and the early plans. But I know the customers want more and Parallax plans to provide it. Once the encoders are done every other accessory will be the better for it. It really needs to be done before we can move on. But, just picture GPS navigation and other things you could do where the robot is not just wandering around avoiding things. That is the real end goal. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    Check out the new Savage Circuits TV!
    ·
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2009-12-15 17:32
    That is exactly the kind of thing I am picturing long term, and I agree the encoders need to go before other stuff. It's essential for helping to go in straight lines, and to have some semi reliable turning and measuring.
    In the meantime, I am attempting to get the compass and accelerometer wired up on the breadboard and write some code to use them as best I can with what I've got.

    I have used the demo code from the site for the PING))) sensors on the Stringray and that works reasonably well on the hard floors, but in my carpeted areas it mostly just slows and stops. I think the carpet is messing with the sound bounce back or something.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out the Propeller Wiki·and contribute if you can.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-12-15 17:37
    Roy,

    On plush carpets the PING))) sensors randomly get echoes back, especially if they're mounted on the lower holes of the sensor mounting plates. Since the code is designed to move the robot at a speed proportional to its distance from an object, this inherently makes the robot crawl along. We'll get the bugs worked out. There is a lot of potential here waiting to be unlocked and tapped. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Parallax Engineering
    Check out the new Savage Circuits TV!
    ·
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2009-12-15 18:22
    I figured it was something like that, and I have some ideas about adjusting the mounting to reduce it some. Either by inserting some washers in the lower mount point to give them a sligh tilt up in their aim or by moving the PING)))'s up higher with those new metal brackets.
    I am confident you guys will figure stuff out (or the community here will help), and I agree about the potential that needs to be tapped and unlocked, I hope to help do some of that.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out the Propeller Wiki·and contribute if you can.
  • MasterCMasterC Posts: 39
    edited 2009-12-15 19:37
    SRLM said...
    Below is some code that makes control of the motors easy at the expense of flexibility. Basically, it is a function that takes a "heading" (how hard you want to turn) and a speed (what the minimum speed is that you want). With it you should be able to write a simple program that just spins the motors however you want.
    Cool, thanks!· I appreciate the help.· I was able to use your code to slap together a quick demo.· It doesn't do anything terribly useful, but it does something.· Here's my demo code, if anyone is interested:

    CON
      _xinfreq = 5_000_000
      _clkmode = xtal1 + pll16x
     
      lmforward = 25 
      lmbackward = 24
      rmforward = 26
      rmbackward = 27
     
      period = 5000 'for PWM object
     
      basespeed = 22
     
      'Robot Rate Constants
      STOP          = 0
      SUPERSLOW     = 2
      SLOW          = 15
      MEDIUM        = 35
      FAST          = 60
      SUPERFAST     = 85
      MAXSPEED      = 100
     
      'Pause Duration Constants
      DELAY_S       = 2
      LONG_DELAY_S  = 5
      DELAY_MS      = 25
      LONG_DELAY_MS = 50   
     
     
    OBJ
      pwm  :  "PWM_32_v2"
      utils:  "Utilities_Library"      
     
     
    PUB Main | i  
    
      pwm.start
     
     
      ''MARCH!
     
      calculatemotor(0,MEDIUM)                              'go forward slowly...  
      utils.pauses(DELAY_S)                                 '...for this long
     
      calculatemotor(0,-MEDIUM)                             'go backward slowly...  
      utils.pauses(DELAY_S)                                 '...for this long    
                                                             
      calculatemotor(MEDIUM,0)                              'spin right slowly...  
      utils.pauses(DELAY_S)                                 '...for this long    
                                                             
      calculatemotor(-MEDIUM,0)                             'spin left slowly...  
      utils.pauses(DELAY_S)                                 '...for this long    
                                                             
                                                             
      calculatemotor(SLOW,MEDIUM)                           'forward and right turn  
      utils.pauses(DELAY_S)                                 '...for this long   
                                    
      calculatemotor(SLOW,-MEDIUM)                          'backward and right turn  
      utils.pauses(DELAY_S)                                 '...for this long   
     
     
     
      ''HALT!  
    
     
      calculatemotor(STOP,STOP)                             'stop... 
      utils.pauses(LONG_DELAY_S)                            '...for this long   
     
     
     
      ''SPIN CYCLE!
    
     
      repeat i from SUPERSLOW to SUPERFAST                  'Spin right with increasing speed
        calculatemotor(i,0)
        utils.pausems(DELAY_ms)             
     
      repeat i from SUPERFAST to SUPERSLOW                  'Spin right with decreasing speed  
        calculatemotor(i,0)
        utils.pausems(DELAY_ms)    
     
      repeat i from SUPERSLOW to MAXSPEED                  'Spin left with increasing speed  
        calculatemotor(-i,0)          
        utils.pausems(DELAY_ms)
     
      repeat i from MAXSPEED to SUPERSLOW                   'Spin left with decreasing speed  
        calculatemotor(-i,0)  
        utils.pausems(DELAY_ms)
     
     
     
      ''HALT!  
    
     
      calculatemotor(STOP,STOP)                             'stop... 
      utils.pauses(LONG_DELAY_S)                            '...for this long   
      
     
     
      ''TIGHT SPIN CYCLE!!!
    
     
      repeat i from SUPERSLOW to SUPERFAST                  'Tight spin right with increasing speed
        spinner(i)
        utils.pausems(LONG_DELAY_MS)        
     
      repeat i from SUPERFAST to SUPERSLOW                  'Tight spin right with decreasing speed
        spinner(i) 
        utils.pausems(LONG_DELAY_MS)
     
      repeat i from SUPERSLOW to SUPERFAST                  'Tight spin left with increasing speed
        spinner(-i)                   
        utils.pausems(LONG_DELAY_MS)
     
      repeat i from SUPERFAST to SUPERSLOW                  'Tight spin left with decreasing speed
        spinner(-i)           
        utils.pausems(LONG_DELAY_MS)
     
     
     
      ''ALL DONE!   
    
     
      spinner(0)                                            'stop 
     
     
     
    PUB calculatemotor(turnrate, speed)
     
    {
    A turn rate of 0 is straight, -100 is full left, 100 is full right
    speed is how fast to "turn" minimum, used for going straight, + is forward, - is backwards
    -Units same as above
     
    }
      speed := -100 #> speed <# 100
      turnrate := -100 #> turnrate <# 100
      if turnrate == 0
        if(speed => 0) 'Go straight forward
          pwm.duty(rmbackward, 0,0)
          pwm.duty(lmbackward, 0,0)
          pwm.duty(lmforward, speed, period)
          pwm.duty(rmforward, speed, period)
        else 'Go straight backwards
          ||speed
          pwm.duty(rmforward, 0,0)
          pwm.duty(lmforward, 0,0)
          pwm.duty(lmbackward, ||speed, period)
          pwm.duty(rmbackward, ||speed, period)
      elseif(turnrate > 0) 'turn right
        if(speed => 0) 'Go on a curve forward right
          pwm.duty(rmbackward, 0,0)
          pwm.duty(lmbackward, 0,0)
          pwm.duty(lmforward, (speed+turnrate)<#100, period)
          pwm.duty(rmforward, speed, period)
        else 'Go on a curve backwards right
          pwm.duty(rmforward, 0,0)
          pwm.duty(lmforward, 0,0)
          pwm.duty(lmbackward, (||speed+turnrate)<#100, period)
          pwm.duty(rmbackward, ||speed, period)
      
      elseif(turnrate < 0) 'turn left
        ||turnrate
        if(speed => 0) 'Go on a curve forward left
          pwm.duty(rmbackward, 0,0)
          pwm.duty(lmbackward, 0,0)
          pwm.duty(rmforward, (speed+turnrate)<#100, period)
          pwm.duty(lmforward, speed, period)
        else 'Go on a curve backwards left
          pwm.duty(rmforward, 0,0)
          pwm.duty(lmforward, 0,0)
          pwm.duty(rmbackward, (||speed+turnrate)<#100, period)
          pwm.duty(lmbackward, ||speed, period)
     
     
    
    PUB spinner(rate)
     
    { Rotates both wheels in opposite directions to spin the robot.
     
      A rate of 0 is stopped, -100 is full left spin, 100 is full right spin
    }
     
      rate := -100 #> rate <# 100   'bounds check                         
     
      if rate == 0  'Stop                                    
          pwm.duty(rmbackward, 0,0)
          pwm.duty(lmbackward, 0,0)      
          pwm.duty(rmforward, 0,0)
          pwm.duty(lmforward, 0,0)
     
      elseif rate > 0 'Spin right
          pwm.duty(rmbackward, 0,0)
          pwm.duty(lmbackward, rate, period)
          pwm.duty(lmforward, 0,0)
          pwm.duty(rmforward, rate, period)
     
      elseif rate < 0 'Spin left
          pwm.duty(rmbackward, ||rate, period)
          pwm.duty(lmbackward, 0,0)
          pwm.duty(lmforward, ||rate, period)
          pwm.duty(rmforward, 0,0)
       
    

    Oh, and the couple "pause" routines I used from my utils library are very simple:

    PUB pauses(time) | clocks              '' Pause for number of seconds
      if time > 0
        clocks := (clkfreq * time)
        waitcnt(clocks + cnt)
     
    PUB pausems(time)                        '' Pause for number of milliseconds
      pause(time)
      
    PUB pause(time) | clocks                 '' Pause for number of milliseconds
      if time > 0
        clocks := ((clkfreq / 1000) * time)
        waitcnt(clocks + cnt)
    
  • essence25essence25 Posts: 1
    edited 2009-12-16 07:24
    I was just about to buy one of these kits.. But now I'm little worried since I dont know any programming and rely on demo codes.. What do you think I should do ? Will there be a lot of code comming soon for this robot? Sensors and all ?

    Thanks
    As always Parallax is my favorite...
    ·
  • dandreaedandreae Posts: 1,375
    edited 2009-12-16 15:13
    Parallax is currently working on sample codes for the Stingray using different sensors.· You can also download the "Propeller Education Kit Labs:· Fundamentals" text for the basics using the Spin language.· Here is a link for the download:

    http://www.parallax.com/Store/Books/Propeller/tabid/171/CategoryID/45/List/0/Level/a/ProductID/541/Default.aspx?SortField=ProductName%2cProductName

    Dave



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Dave Andreae

    Parallax Tech Support·
  • SRLMSRLM Posts: 5,045
    edited 2009-12-16 16:43
    Surprisingly, I found the Stingray to be very easy to program. I just downloaded the one sample program that they have right now (stingray with pings), looked to figure out how to control the motors, and made a version that didn't require any sensors. After about an hour of programming and messing around with the kit, I had a program going that would use a single ping mounted on the right hand side to follow a wall. It was very straight forward.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Powered by enthusiasm
  • MasterCMasterC Posts: 39
    edited 2009-12-16 18:51
    essence25 said...
    I was just about to buy one of these kits.. But now I'm little worried since I dont know any programming and rely on demo codes.. What do you think I should do ? Will there be a lot of code comming soon for this robot? Sensors and all ?

    Well, now at least you have my silly little demo code (thanks to SRLM). tongue.gif
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2009-12-16 19:13
    I'm working on code over the next few weeks that will use the 3 PING))) kit, the Memsic 2125 Dual-Axis Accelerometer, and the H55B compass module on my Stingray. I'll be sharing it here once I have stuff working. After that, I'll probably get some more sensors from Parallax and put them on there also. Between the Parallax folks, SRLM, myself, and whoever else, there will be plenty of code examples using the sensors with the Stingray. So don't worry essence25.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out the Propeller Wiki·and contribute if you can.
  • BotdocterBotdocter Posts: 271
    edited 2010-02-27 04:29
    And? Have you got any luck with the memsic accelerometer? I want my bot, based on the MSR1 to balance on 2 wheels. I had a look at the dancebot code but i'm too much of a newbie to wrestle that little piggy!
  • HemPeterHemPeter Posts: 28
    edited 2010-05-08 02:22
    Here is the code I slaved on the last few weeks trying to get it together for a senior design project I was helping with.

    The StingRay had GPS, HM55B compass, and originally 5 Pings, 3 on the front and 2 facing down on aluminium plates on the bottom of the bot for edge detection, but we scrapped the downward pings because they weren't in front of the bot far enough so they weren't useful. Also we were getting false positives when on tarmac with lots of bumps in.

    Hope the community can make some use of it. I have ideas on how to improve it but since I don't get to play with the thing anymore...

    Floating Point Maths takes a while doesn't it [noparse];)[/noparse]

    turn.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm either going mad or both...
  • WhitWhit Posts: 4,191
    edited 2010-05-08 13:08
    Thanks HemPeter - I'll have a look.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Whit+


    "We keep moving forward, opening new doors, and doing new things, because we're curious and curiosity keeps leading us down new paths." - Walt Disney
  • HemPeterHemPeter Posts: 28
    edited 2010-06-04 01:11
    I would love to hear some feedback from people who've downloaded the above project.
    Something I forgot to mention, but I'm not sure if here it will ever get noticed.. the first compass object that I used was incompatible with the GPS module. For some reason the Red LED would begin blinking again a few seconds after starting the compass cog, and only by using another object was it solved.
    Also, the Ping module, "required" the 'FullDuplexSerial' object, because I would get some very odd behaviour when it wasn't included. I don't know if anyone would be able/bothered to rig it up the same way I had it, but I am curious to know =)

    Pete

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I'm either going mad or both...
  • Headache07Headache07 Posts: 3
    edited 2010-06-09 09:48
    Hi, erm can some1 hlp me with the Stingray codes.. i just need a simple code for it to move(Forward,Reverse,turn left,turn right) to how far or how i want it to move.. because the demo don't really help mi much.. plz reply ASAP i will appreciate ur hlp =)
  • daveedavee Posts: 35
    edited 2010-09-14 07:37
    As of this morning, you can use 12Blocks to program your Stingray. I have the mods (straight from the author, Hanno Sanders). The mods create a hardware profile that uses the H-Bridges built into the Stingray board. Still in alpha but should be ready to go by this weekend. Set Speed still needs work but everything else works greate.
Sign In or Register to comment.