Shop OBEX P1 Docs P2 Docs Learn Events
BoeBot Shield for Arduino Question — Parallax Forums

BoeBot Shield for Arduino Question

Syn7Syn7 Posts: 6
edited 2012-12-31 17:52 in Robotics
I am learning as I go with the tutorials and I am at Chapter 4, Activity 4. Ramping. So I thought I understood. I used the samples to do the ramping for forward start, 3 seconds or whatever it was, then stop. No problem. So at the end of the tutorial it asks me to:
  • Open the sketch ForwardLeftRightBackward and save it as ForwardLeftRightBackwardRamping.
  • Modify the new sketch so your BOE Shield-Bot will ramp into and out of each maneuver. Hint: you might use the code snippets above, and similar snippets from StartAndStopWithRamping.
I thought I understood, So I made my sketch and it worked great till the very end. It ramps well for every maneuver and ramps up in the last part going backwards, but doesn't ramp down or stop. What did I do wrong here? I'm thinking it's something dumb and easy, but I'm not seeing it. After much messing around, I figured I would just ask. So here is my sketch....

Sorry about the notes, I cut and paste most of it then just adjusted what I needed to. I will fix the notes once I get it right.

// Robotics with the BOE Shield - ForwardLeftRightBackwardRamping// Move forward, left, right, then backward for testing and tuning.


#include <Servo.h>                           // Include servo library


Servo servoLeft;                             // Declare left and right servos
Servo servoRight;
 
void setup()                                 // Built-in initialization block
{ 
  tone(4, 3000, 1000);                       // Play tone for 1 second
  delay(1000);                               // Delay to finish tone


  servoLeft.attach(13);                      // Attach left signal to P13 
  servoRight.attach(12);                     // Attach right signal to P12


  // Full speed forward
  for(int speed = 0; speed <= 100; speed += 2) // Ramp up to full speed.
  {
    servoLeft.writeMicroseconds(1500+speed);   // us = 1500,1502,...1598,1600
    servoRight.writeMicroseconds(1500-speed);  // us = 1500,1498,...1402,1400
    delay(20);                                 // 20 ms at each speed
  }
   
  delay(1500);                                 // Full speed for 1.5 seconds


  for(int speed = 100; speed >= 0; speed -= 2) // Ramp from full speed to stop
  {
    servoLeft.writeMicroseconds(1500+speed);   // us = 1600,1598,...1502,1500
    servoRight.writeMicroseconds(1500-speed);  // us = 1400,1402,...1498,1500
    delay(20);                                 // 20 ms at each speed
  }                            // ...for 2 seconds


  // Turn left in place
    for(int speed = 0; speed <= 100; speed += 2) // Ramp stop to right turn
  {
    servoLeft.writeMicroseconds(1500-speed);   // us = 1500,1502, 1508...1600
    servoRight.writeMicroseconds(1500-speed);  // us = 1500,1502, 1508...1600
    delay(20);                                 // 20 ms at each speed
  }


  for(int speed = 100; speed >= 0; speed -= 2)// right turn to stop
  {
    servoLeft.writeMicroseconds(1500-speed);   // us = 1600,1598, 1597...1500
    servoRight.writeMicroseconds(1500-speed);  // us = 1600,1598, 1597...1500
    delay(20);                                 // 20 ms at each speed
  }                           // ...for 0.6 seconds


  // Turn right in place
  for(int speed = 0; speed <= 100; speed += 2) // Ramp stop to right turn
  {
    servoLeft.writeMicroseconds(1500+speed);   // us = 1500,1502, 1508...1600
    servoRight.writeMicroseconds(1500+speed);  // us = 1500,1502, 1508...1600
    delay(20);                                 // 20 ms at each speed
  }


  for(int speed = 100; speed >= 0; speed -= 2)// right turn to stop
  {
    servoLeft.writeMicroseconds(1500+speed);   // us = 1600,1598, 1597...1500
    servoRight.writeMicroseconds(1500+speed);  // us = 1600,1598, 1597...1500
    delay(20);                                 // 20 ms at each speed
  }                             // ...for 0.6 seconds


  // Full speed backward
    for(int speed = 0; speed <= 100; speed -= 2) // Ramp up to full speed.
  {
    servoLeft.writeMicroseconds(1500+speed);   // us = 1500,1502,...1598,1600
    servoRight.writeMicroseconds(1500-speed);  // us = 1500,1498,...1402,1400
    delay(20);                                 // 20 ms at each speed
  }
   
  delay(1500);                                 // Full speed for 1.5 seconds


  for(int speed = -100; speed >= 0; speed += 2) // Ramp from full speed to stop
  {
    servoLeft.writeMicroseconds(1500+speed);   // us = 1600,1598,...1502,1500
    servoRight.writeMicroseconds(1500-speed);  // us = 1400,1402,...1498,1500
    delay(20);                                 // 20 ms at each speed
  }                             // ...for 2 seconds
  
  
  
  servoLeft.detach();                        // Stop sending servo signals
  servoRight.detach(); 
}  


void loop()                                  // Main loop auto-repeats
{                                            // Empty, nothing needs repeating
} 




any help would be much appreciated. Thanx.

Comments

  • Martin_HMartin_H Posts: 4,051
    edited 2012-12-31 03:49
    Hi and welcome to the forum. I scanned your code and I think this line is the problem.

    for(int speed = -100; speed >= 0; speed += 2) // Ramp from full speed to stop

    You are starting with a negative number so speed will fail the test. I think the loop will terminate right away. Try this instead :

    for(int speed = -100; speed <= 0; speed += 2) // Ramp from full speed to stop
  • Syn7Syn7 Posts: 6
    edited 2012-12-31 17:52
    That didn't work. But switching the +/- before the speed made a difference. I just used the forward code and reversed those two parts. Seems to have worked well, but it wasn't the fix I was looking for. My real goal is to learn the 'int for speed' part. Was what I did the best way to go about it?

    I do realize why my first try failed tho.
    [COLOR=#3E3E3E][FONT=Parallax]for(int speed = -100; speed >= 0; speed += 2) // Ramp from full speed to stop[/FONT][/COLOR]
    
    This can't work.

    Here's what did work:

    .
    // ForwardLeftRightBackwardRamping// Move forward, left, right, then backward for testing and tuning w/ ramping.
    
    
    
    #include <Servo.h>                           // Include servo library
    
    
    
    
    Servo servoLeft;                             // Declare left and right servos
    Servo servoRight;
     
    void setup()                                 // Built-in initialization block
    { 
      tone(4, 3000, 1000);                       // Play tone for 1 second
      delay(1000);                               // Delay to finish tone
    
    
    
    
      servoLeft.attach(13);                      // Attach left signal to P13 
      servoRight.attach(12);                     // Attach right signal to P12
    
    
    
    
      // Full speed forward
      for(int speed = 0; speed <= 100; speed += 2) 
      {
        servoLeft.writeMicroseconds(1500+speed);   
        servoRight.writeMicroseconds(1500-speed);  
        delay(20);                                 
      }
       
      delay(1500);                                 
    
    
    
    
      for(int speed = 100; speed >= 0; speed -= 2) 
      {
        servoLeft.writeMicroseconds(1500+speed);   
        servoRight.writeMicroseconds(1500-speed);  
        delay(20);                                 
      }                            
    
    
    
    
      // Turn left in place
        for(int speed = 0; speed <= 100; speed += 2) 
      {
        servoLeft.writeMicroseconds(1500-speed);   
        servoRight.writeMicroseconds(1500-speed);  
        delay(20);                                 
      }
    
    
    
    
      for(int speed = 100; speed >= 0; speed -= 2)
      {
        servoLeft.writeMicroseconds(1500-speed);   
        servoRight.writeMicroseconds(1500-speed);  
        delay(20);                                 
      }                           
    
    
    
    
      // Turn right in place
      for(int speed = 0; speed <= 100; speed += 2) 
      {
        servoLeft.writeMicroseconds(1500+speed);   
        servoRight.writeMicroseconds(1500+speed);  
        delay(20);                                 
      }
    
    
    
    
      for(int speed = 100; speed >= 0; speed -= 2)
      {
        servoLeft.writeMicroseconds(1500+speed);   
        servoRight.writeMicroseconds(1500+speed);  
        delay(20);                                 
      }                             
    
    
    
    
      // Full speed backward
       for(int speed = 0; speed <= 100; speed += 2) 
      {
        servoLeft.writeMicroseconds(1500-speed);   
        servoRight.writeMicroseconds(1500+speed);  
        delay(20);                                 
      }
       
      delay(1500);                                 
    
    
    
    
      for(int speed = 100; speed >= 0; speed -= 2) 
      {
        servoLeft.writeMicroseconds(1500-speed);   
        servoRight.writeMicroseconds(1500+speed);  
        delay(20);                                 
      }                            
    
    
      
      servoLeft.detach();                       
      servoRight.detach(); 
    }  
    
    
    
    
    void loop()                                  
    {                                            
    }
    
Sign In or Register to comment.