Shop OBEX P1 Docs P2 Docs Learn Events
BUG! Robot drive speed and Robot drive distance don't mix! — Parallax Forums

BUG! Robot drive speed and Robot drive distance don't mix!

Peavey5150Peavey5150 Posts: 20
edited 2018-01-03 21:29 in General Discussion
Robot drive speed and Robot drive distance don't mix!

I Used a Robot drive stop block in between them to switch from using one type of navigation to the other.

This DOES NOT WORK! Robot drives backwards

Please explain how to use Robot drive speed and Robot drive distance in the same program


using C lang

Propeller WX
activity bot 360


example below


//
Libraries and Definitions
#include "simpletools.h"
#include "servo360.h"
#include "abdrive360.h"



//
Main Program
int main()
{
ee_getInt(32768); // NOTE: This is a temporary patch to make the AB360 robot library compile correctly.
drive_speed(64, 64); // goes forward
pause(2000); // wait
drive_speed(0, 0); // drive stop
pause(2000); // wait
drive_goto(30, 30); // should drive forward but robot goes backwards bug here!
drive_speed(0, 0);

}

Comments

  • Robot drive speed and Robot drive distance don't mix!

    I Used a Robot drive stop block in between them to switch from using one type of navigation to the other.

    This DOES NOT WORK! Robot drive backwards

    Please explain how to use Robot drive speed and Robot drive distance in the same program
  • VonSzarvasVonSzarvas Posts: 3,272
    edited 2018-01-03 21:27
    Hi Peavey5150,

    Multiple posting is not permitted here. I've merged your messages together for you.

    If you have an urgent question regarding a Parallax product, you could try emailing support@parallax.com

    This forum is mainly for user-to-user help. If you try to explain your issue and question more clearly, then you might get some help here
    I'm not sure anyone could understand your predicament so far.

    Consider adding these details...

    What hardware are you using?
    Which language?
    Try attaching your code too.

    All the best.
  • code example
  • I've tried a few things. The code below "works", but I think that there is something tricky (bug?)
    #include "simpletools.h"
    #include "abdrive360.h"
    
    int main()                    
    {
      print("\n speed 64 \n");  
      drive_speed(64, 64);            // rotate at 64 t/s for 2 sec
      pause(2000);
      print("\n speed 100 \n");
      drive_speed(100, 100);           // rotate at 100 t/s for 2 sec
      pause(2000);  
      print("\n speed 0 \n");   
      drive_speed(0, 0);              // allow switch to drive_goto
     
      
      print("\n goto -200 \n");      //  goto position -200 absolute
      drive_goto(-200, -200);
    
      print("\n goto 0 \n");           // goto position 0 additional (if not first goto)
      drive_goto(0, 0);
    
      print("\n goto -100 \n");
      drive_goto(-100, -100);     // goto position -100 additional (if not first goto)
      pause(1000); 
      print("\n goto 100 \n");   
      drive_goto(100, 100);   // goto position +100 additional (if not first goto)
      pause(1000);    
    drive_speed(0, 0);
    }
    

    I could be wrong, but I think that the first drive_goto statement goes to a position that treats zero as the position the servo was in when power was first applied. If there was a previous drive_speed command, the first drive_goto will re-position the servo to zero +/- the drive_goto value (including the number of 360degree rotations). Subsequent drive_goto commands are then relative to the previous position.

    If you run the code above as written you will see that after the switch, the drive_goto(-200,-200) unwinds a lot (change the pause value for the drive_speed commands to see how that changes the amount that the drive_goto(-200,-200) unwinds).

    Then the drive_goto(0,0) movement is almost nothing. But if you comment out the drive_goto(-200,-200), then the drive_goto(0,0) also unwinds, but not as much as the drive_goto(-200,-200) did. I did not calibrate my servos, so I can't say if drive_goto(-200,-200) will return to the starting point before the drive_speed(100,100); pause(2000); commands.

    I'm not sure if the behavior of the first drive_goto was intentional or just a bug, and if intentional how to make use of that to do what you want (move a certain distance relative to current position from the drive_speed commands,) possibly it needs to use one of the drive_getTicks commands.

    Hopefully Parallax will provide documentation for the 360 libraries soon.

    Hope this helps
    Tom M.
  • twm47099twm47099 Posts: 867
    edited 2018-01-04 23:25
    A few more tests.

    Using drive_getTicks works to allow the robot to move using the drive_goto command a certain distance relative to the current position that resulted from prior drive_speed commands.

    Here's code that works:
    #include "simpletools.h"
    #include "abdrive360.h"
    
    int main()                    
    {
      int Lticks = 0;                  //  *** add this
      int Rticks = 0;                  //  *** add this
      print("\n speed 64 \n");         // start  at speed 64 for 2 sec
      drive_speed(64, 64);
      pause(2000);
      print("\n speed 100 \n");       // speed up to 100 for 2 sec
      drive_speed(100, 100);
      pause(2000);  
    
      print("\n speed 0 \n");    
      drive_speed(0, 0);                 // stop to allow switch to drive_goto
      
    //  ===== Transition from drive_speed to drive_goto
    //  This section gets current position in ticks,
    //  Then goes to that position (absolute position based on original servo "0")
    //    There should be [u]almost[/u] no motion
    //  Subsequent drive_goto commands will be relative to current position.
    
      drive_getTicks(&Lticks, &Rticks);    //  *** add this
      print("Lticks = %d  ", Lticks);      //  *** for debugging
      Rticks = Rticks * -1;            //  *** add this -- Rticks was opposite rotation
      print("Rticks = %d", Rticks);        //  *** for debugging
      drive_goto(Lticks, Rticks);          //  *** add this -- all subsequent should be relative
    
    // ===== End transition from drive_speed to drive_goto
    
      print("\n goto +200 \n");        // continue in same direction +200 relative
      drive_goto(200, 200);       
      print("\n goto 0 \n");         // go backwards 0 relative
      drive_goto(0, 0);              // should be almost no motion
      pause(1000);       
      print("\n goto -100 \n");    // keep going backwards -100 relative
      drive_goto(-100, -100); 
      pause(1000); 
      print("\n goto 100 \n");        // go forwards 100 relative
      drive_goto(100, 100);  
      pause(1000);    
     drive_speed(0, 0);               // stop
    

    There is a small hiccup when executing "drive_goto(Lticks, Rticks);" That could be due to me not having calibrated my servos, or possibly round off errors?

    By the way, using BlocklyProp allowed me to figure out the syntax and use of the "drive_getTicks(&Lticks, &Rticks); " function and that I needed to multiply Rticks by -1 due to the rotation direction difference Left & Right servos. Programming in Blockly and then reviewing the Code generated made its use very clear.

    Tom M.
  • Thanks for the bug reports. I was able to duplicate the symptoms and will post a library update, hopefully later today.
  • Peavey5150Peavey5150 Posts: 20
    edited 2018-01-05 02:09
    @AndyLindsay (Parallax), That would be awesome.

    Thanks for your help!
  • Peavey5150Peavey5150 Posts: 20
    edited 2018-01-05 02:09
    @twm47099

    I appreciate your help. I ran your code saw the hiccup you mentioned. Bot still backs up. I think your on to something.


    Thanks,
    Peavey
  • Peavey5150Peavey5150 Posts: 20
    edited 2018-01-05 02:55
    @twm47099

    This is your code with my example combined


    This seem to help and I added a pause statement after drive_speed(0,0).
    Still has issues with programs with condition statements .

    Will wait for word back from Parallax.

    Thanks for your help

    #include "simpletools.h"
    #include "abdrive360.h"

    int main()
    {
    int Lticks = 0; // *** add this
    int Rticks = 0; // *** add this


    print("\n speed 100 \n"); // speed up to 100 for 2 sec
    drive_speed(100, 100);
    pause(2000);

    print("\n speed 0 \n");
    drive_speed(0, 0); // stop to allow switch to drive_goto
    pause(2000);

    // ===== Transition from drive_speed to drive_goto
    // This section gets current position in ticks,
    // Then goes to that position (absolute position based on original servo "0")
    // There should be almost no motion
    // Subsequent drive_goto commands will be relative to current position.

    drive_getTicks(&Lticks, &Rticks); // *** add this
    print("Lticks = %d ", Lticks); // *** for debugging
    Rticks = Rticks * -1; // *** add this -- Rticks was opposite rotation

    print("Rticks = %d", Rticks); // *** for debugging
    drive_goto(Lticks, Rticks); // *** add this -- all subsequent should be relative

    // ===== End transition from drive_speed to drive_goto

    print("\n goto +30 \n"); // continue in same direction +200 relative
    drive_goto(30,30);
    print("\n goto 0 \n"); // go backwards 0 relative

    drive_speed(0, 0); // stop
  • edited 2018-01-05 18:54
    Okay, I'm pretty sure I found and fixed the bug, but it's going to need community testing before we can add it to the Update Your Learn Folder page and the BlocklyProp site.

    Instructions on updating your C libraries for testing the correction are in the abdrive360, servo360 - Instructions for setup and testing page. Make sure to test without Tom's code that remedies the bug by reminding the library what its position is. If you run across any other bugs that look like they might be in the Simple Libraries, please check the Simple Libraries Issues list, and start a new issue if one that pertains to the topic isn't already there.

    For some ideas of things to try, go to Propeller C Programming with the ActivityBot.

    The updated library that'll eventually make it to BlocklyProp can be tested at the BlocklyDemo site. IMPORTANT: If you have never used this site before, your normal BlocklyProp username and password won't work; you'll have to set up a separate account. Also, don't assume that your work will be saved forever on BlocklyDemo. The next paragraph explains how to copy large programs from one site to the other. From BlocklyProp to BlocklyDemo for testing, and from BlocklyDemo to BlocklyProp if you want to make sure you can refer back to code you wrote in BlocklyDemo at some point in the future.

    If you want to copy an existing program from BlocklyProp to BlocklyDemo to see if the library correction fixes the problem, you can re-enter it, but there is also a shortcut for larger programs. Start by opening your code at the BlocklyProp site. When you are viewing the blocks, click the menu in the upper right corner next to the Save button, and select Download Blocks file. Then, go to the BlocklyDemo site and start a new project. When you reach the point where you would normally start placing blocks, click the upper-right menu button again, and use Upload Blocks File to upload the file you downloaded from BlocklyProp.

    Again, for some ideas of things to try, go to BlocklyProp Robotics with the ActivityBot.
  • @twm47099, Tom, that was a clever work-around!
    twm47099 wrote: »
    ...Hopefully Parallax will provide documentation for the 360 libraries soon...

    When you download the latest community branch of Simple Libraries (link to instructions in post above this one), you'll be able to use Help -> Simple Library Reference in SimpleIDE to navigate to drafts of the Doxygen generated HTML docs. I still have to enter Editor feedback and re-Doxygen them.
    twm47099 wrote: »
    ...By the way, using BlocklyProp allowed me to figure out the syntax and use of the...function and that I needed... Programming in Blockly and then reviewing the Code generated made its use very clear...

    Yeah, the BlocklyProp system seems to be one pleasant surprise after another! Seems like every time I use it, I end up pausing at some point and thinking to myself, "Dang! This is amazing!!!" I really think the developers who worked on this project did a beyond-fantastic job.

    Oh, and another nice source of documentation - you can right click any block and select Help. It'll take you to separate help pages that are much more user-friendly than the C language docs. Sometimes the block right-click menu gets hidden behind the OS right-click menu. If that happens, the Help menu item won't be visible, so try CTRL + scroll wheel to zoom in or out a little, then try right-clicking the block again. If you find anything else that the BlocklyProp developers need to hear about, the best place to report it is on the BlocklyProp issues page.
  • Peavey5150Peavey5150 Posts: 20
    edited 2018-01-05 16:44
    @AndyLindsay (Parallax)

    I just tried the updated library you posted. Everything is working great!
    Even works super fast with condition statements! I will continue to program and test.

    Thanks for the quick reply and fix!

    Thanks for your help!
    Nick B.
    Okay, I'm pretty sure I found and fixed the bug, but it's going to need community testing before we can add it to the Update Your Learn Folder page and the BlocklyProp site.

    Instructions on updating your C libraries for testing the correction are in the abdrive360, servo360 - Instructions for setup and testing page. Make sure to test without the code that remedies the bug by reminding the library what its position is. If you run across any other bugs that look like they might be in the Simple Libraries, please check the Simple Libraries Issues list, and start a new issue if one that pertains to the topic isn't already there.

  • Excellent, and thanks for the update!
Sign In or Register to comment.