Shop OBEX P1 Docs P2 Docs Learn Events
HELP — Parallax Forums

HELP

Igna7iousIgna7ious Posts: 4
edited 2015-11-23 18:32 in Propeller 1
I am working on a project for Engineering where we use the activity bot to navigate a track in 90 seconds using qtis. This is my first time programming so I don't know understand much. So far I can navigate however the robot can't make the time. I created a program to make it move faster on the straights then slow down before the junctions. For reasons that I don't understand it only works halfway. The counters work and increment around the entire track however at halfway the program stops before entering the for loops at work_around5. The thing that puzzles me is that work_around1-4 work as intended after that it just stops. I have already replaced the batteries with a fresh set. Anything you can give me will help.

Comments

  • I'd love to help, but I have no idea what your program does when there are 19 different functions named "work_around*". To me, "work around" is synonymous with duct tape - as in, a temporary fix. Given that your file is named "work around.c" I wonder if that's not necessary the case though. What are those functions supposed to do?
  • Hi Igna7ious,

    One problem seems to be with initializing variable values. I see a lot of c == value in places where it looks like you intend to assign values instead of compare them. c = value assigns a value to c. In contrast, c == value returns 1 if they are equal, or 0 if they are not. So, make sure your statements that are evaluating conditions, like if, while, else if, and case use the variable == value to make a comparison. Example, if(squareSides == 4) {...} All intended assignments need a single equals. Example, triangleSides = 3;

    Down at the bottom-center of the SimpleIDE window, you'll see a hammer with a green + circle. Click that to open the Build Status pane and start double-clicking the warnings about commands that have no effect. Each one will take you to what might be a == that should really be an =. You can click that Show Build Status hammer a second time to collapse the Build Status pane.

    If that doesn't fix it, the next step would be to search for the point of failure in the program. Make guesses of where the program gets stuck, and then add combinations of high/low for the P26, P27 lights. You'll have four combinations to work with. Here's an example (just an example, there are lots of variations you can try, and places you can put the various high/low combinations).
    void work_around5()
    {
       b++;
      high(26);
      high(27);
      pause(50);
      low(26);
      low(27);
      for(c=0;c<1000;c++){
          
        int qtis = getQTIs(7, 4);  
          
        if(qtis == 0b0110)drive_speed(100,100);
        //Left  
        if(qtis == 0b1000) drive_speed(70, 100);    // Far left, rotate left
        if(qtis == 0b1100) drive_speed(90, 100);    // Left, pivot left
        if(qtis == 0b0100) drive_speed(95, 100);    // A little left, curve left
      
        //Right
        if(qtis == 0b0010) drive_speed(100, 95);    // A little right, curve right
        if(qtis == 0b0011) drive_speed(100, 90);    // Right, pivot right
        if(qtis == 0b0001) drive_speed(100, 70);
        
            //  printf("%c,a=%d,b=%d,c=%d\n",CLS,a,b,c); 
        if(c > 250)
        {
          high(26);
          low(27);
        }
        else if(c > 500)
        {
          high(27);
          low(26);
        }
        else if(c > 750)
        {
          high(27);
          low(27);
        }
        else
        {
          low(27);
          low(27);
        }
      }
    } 
    

    Additional Notes

    Save code space, replace printf with print. It mainly matters when you have floating point, but it'll still save a little here.

    If you still need more speed on the straightaways, you can temporarily disable feedback with drive_feedback(0), and give it speeds of up to whatever your batteries will support. Brand new alkaline batteries could probably support drive_speed(150, 150) with feedback off. I can't remember if you'll need drive_setMaxSpeed(150) too. Make sure to call drive_feedback(1) and drive_setMaxSpeed(128) before returning to maneuvers that require the encoders.

    Andy
  • P.S. Next time, please put Work Around.side and Work Around.c in a folder, zip it, and then upload the zip. Example attached.
  • DavidZemon,

    Thank you for the reply. The functions increment a variable b then goes into a for loop that allows it to switch to a higher or lower speed while still following the qtis for a set time period. They are named work around because I was trying to achieve the same effect a different way that kept having the same problem. I found what the problem was but not how to fix it so I made this program to work around what was giving me the previous issue. As to why there are so many, the track has many turns that require different times and speeds so they all do roughly the same thing for different sections of the track.
  • Andy Lindsay (Parallax),

    Thank you as well for your reply. The solution you gave me solved current problem and has brought up another. As soon as the program gets to where a would equal 9 it will not turn right. I altered the program to make it stop as soon as it hits that corner and it continues forward anyway. I also added a line to stop it for half a second after the previous for loop has finished to confirm that it ends before the turn. I took a few hours to look at it seems that when I tell it to follow the path without the accelerations it follows it fine. All the qtis seem to be functioning fine and I changed the batteries again just to be safe and nothing. If you have the time do you mind looking over this to see if I have missed something? I have attached the revised code. Thank you so much for your time.
  • Here is an image of the track if it will help.
    848 x 837 - 680K
Sign In or Register to comment.