Page 4 of 6 FirstFirst 123456 LastLast
Results 31 to 40 of 52

Thread: Biayered-X

  1. #31
    Join Date
    May 2008
    Posts
    2,228
    Images
    155
    Rep Power
    126

    Re: Biayered-X

    Looks like you're short one "}" before "if(bioloid.playing){"

    -Fergs

  2. #32
    Join Date
    Jun 2009
    Location
    Wisconsin
    Posts
    369
    Images
    192
    Rep Power
    56

    Re: Biayered-X

    It looks like you are missing some open and close curly braces '{ }' on some of the conditionals near the end.

    Also being more generous with the white space and very explicit with the syntax may help you a lot while learning.
    Code:
    #include <ax12.h>
    #include <BioloidController.h>
    #include <Commander.h>
    #include "poses.h"  // exported from PyPose
    
    BioloidController bioloid = BioloidController(1000000);
    Commander command = Commander();
    
    void setup()
    {
        // stand up slowly
        
        // recommended pause
        delay(100);
        
        bioloid.loadPose(QuadStart);
        bioloid.readPose();
        bioloid.interpolateSetup(500);
        
        while(bioloid.interpolating > 0)
        {
            bioloid.interpolateStep();
            delay(3);
        }
    }
    
    void loop()
    {
        // check for new messages
        if(command.ReadMsgs() > 0)
        {   
            // toggle LED so we know johnny5 is alive
            digitalWrite(0,HIGH-digitalRead(0));
        
            // only process if we aren't currently doing a sequence
            if(bioloid.playing == 0)
            {               
                if(command.walkV > 50)
                {
                    bioloid.playSeq(CrawlForward);
                }
                else if(command.walkV < -50)
                {
                    bioloid.playSeq(CrawlBackward);
                }
                else if(command.walkH > 50)
                {
                    bioloid.playSeq(CrawlSideLeft);    
                }
                else if(command.walkH < -50)
                {
                    bioloid.playSeq(CrawlSideRight);
                }
          
                if(command.buttons&BUT_R1)
                {
                    bioloid.playSeq(openFlower); 
                }
          
                if(command.buttons&BUT_R2)
                {
                    bioloid.playSeq(closeFlower);
                }
          
                if(command.buttons&BUT_R3)
                {
                    bioloid.playSeq(Crawl2Stand);
                }
            }
        } 
        
        if(bioloid.playing > 0)
        {
            // continue sequence
            bioloid.play();  
        }
      
    }
    Last edited by Upgrayd; 08-14-2010 at 11:04 AM.

  3. #33
    Join Date
    Dec 2007
    Location
    Whidbey Island, WA
    Posts
    1,718
    Images
    456
    Rep Power
    96

    Re: Biayered-X

    Thanks UpGrayd and Fergs.

    That seams to have worked.

    I'm still having trouble using the software commander tester. When I open Nuke and click on test drive a window comes up that does body rotation with a grid on the left side. Needless to say it looks nothing like the commander.

    Am I doing something wrong? I was thinking that I need to run Nuke first, but given the configuration of X I don't think that will really work.

    I guess it only sort of matters because I'm going to be getting an arbotix commander with next months robotics budget.

    Thanks again.

    DB

  4. #34
    Join Date
    May 2008
    Posts
    2,228
    Images
    155
    Rep Power
    126

    Re: Biayered-X

    Quote Originally Posted by darkback2 View Post
    I'm still having trouble using the software commander tester. When I open Nuke and click on test drive a window comes up that does body rotation with a grid on the left side. Needless to say it looks nothing like the commander.

    Am I doing something wrong? I was thinking that I need to run Nuke first, but given the configuration of X I don't think that will really work.
    The "software commander" just speaks the same protocol. See that big white box with a crosshairs through it? That's your joystick. Click the mouse (might have to drag a bit) in that box to set speed and/or turning direction (-100 to 100, so once your mouse is > halfway up from the cross line, it will start walking forward, about where that arrow is drawn). The "software commander" has nothing to do with NUKE really -- except that the "default" NUKE sketch people export talks "commander" protocol, and if they don't have a real commander, this is a way to test that their bot is working before going off in whatever direction of control they want. It's also a still a beta -- eventually it'll look a bit snazzier.



    -Fergs

  5. #35
    Join Date
    May 2008
    Posts
    2,228
    Images
    155
    Rep Power
    126

    Re: Biayered-X

    Quote Originally Posted by Upgrayd View Post
    It looks like you are missing some open and close curly braces '{ }' on some of the conditionals near the end.

    Code:
                if(command.buttons&BUT_R3)
                {
                    bioloid.playSeq(Crawl2Stand);
                }
    That code is a bit unnecessary -- he was missing one brace at the end (for the overall "if" loop of "if command.ReadMsgs...). The "if" statement will execute the next C/C++ "block" after it, if the "statement" inside the () is true. A single statement, such as:

    bioloid.playSeq(Crawl2Stand);

    is a block in itself, by definition. If you only have a single statement to execute, no need to wrap it in {}. If on the other hand, you need to execute more than one statement, you need to put all statements in a block, using {}. Thus:

    Code:
         if(command.buttons&BUT_R3)
            bioloid.playSeq(Crawl2Stand);
    is exactly the same as the 4-line version. But you quickly end up in "brace hell" with the other version, trying to figure out what is open/closed, when there are 30 something braces in the function.

    -Fergs

  6. #36
    Join Date
    Dec 2007
    Location
    Whidbey Island, WA
    Posts
    1,718
    Images
    456
    Rep Power
    96

    Re: Biayered-X

    First of all, I finally got the version that I copied from Fergs to compile properly. It took some trial and error adding "}" in a few different places until it compiled properly. The bad news is neither one plays sequences when I drag the mouse around the NUKE test drive widow thing. I'm not sure if its the commander code or what.

    So here is what happens.

    When I plug in the arbotix X drops down into his crawl pose. I then set the port in pypose and switch to the NUKE editor. I select testdrive.

    I click in the middle lf the X and drag the mouse up towards the top of the box.

    Nothing happens.

    I was looking at the brackets and trying to see what was bracketed out where.

    Here is what I came up with.

    Code:
    #include <ax12.h>
    #include <BioloidController.h>
    #include <Commander.h>
    #include "poses.h"  // exported from PyPose
    
    BioloidController bioloid = BioloidController(1000000);
    Commander command = Commander();
    
    void setup()
    {
        // stand up slowly
        
        // recommended pause
        delay(100);
        
        bioloid.loadPose(QuadStart);
        bioloid.readPose();
        bioloid.interpolateSetup(500);
        
        while(bioloid.interpolating > 0)
        {
            bioloid.interpolateStep();
            delay(3);
        }
    }
    
    void loop()
    {
        // check for new messages
        if(command.ReadMsgs() > 0)
        {   
            // toggle LED so we know johnny5 is alive
            digitalWrite(0,HIGH-digitalRead(0));
        
            // only process if we aren't currently doing a sequence
            if(bioloid.playing == 0)
            {               
                if(command.walkV > 50)
                {
                    bioloid.playSeq(CrawlForward);
                }
                else if(command.walkV < -50)
                {
                    bioloid.playSeq(CrawlBackward);
                }
                else if(command.walkH > 50)
                {
                    bioloid.playSeq(CrawlSideLeft);    
                }
                else if(command.walkH < -50)
                {
                    bioloid.playSeq(CrawlSideRight);
                }
          
                if(command.buttons&BUT_R1)
                {
                    bioloid.playSeq(openFlower); 
                }
          
                if(command.buttons&BUT_R2)
                {
                    bioloid.playSeq(closeFLower);
                }
          
                if(command.buttons&BUT_R3)
                {
                    bioloid.playSeq(Crawl2Stand);
                }
            } 
        
        if(bioloid.playing > 0)
        {
            // continue sequence
            bioloid.play();  
        }
      
    }
    }

  7. #37
    Join Date
    May 2008
    Posts
    2,228
    Images
    155
    Rep Power
    126

    Re: Biayered-X

    I think you've added the paranthesis in a bit of the wrong spot (see below). However, that shouldn't cause it to completely lock up -- is the LED blinking? If not, the commander isn't sending information...

    EDIT: crap, I forgot to enable the digital as an output... added that to the code. Also helps to enable the serial input -- added that too. This should work:

    Code:
    #include <ax12.h>
    #include <BioloidController.h>
    #include <Commander.h>
    #include "poses.h"  // exported from PyPose
    
    BioloidController bioloid = BioloidController(1000000);
    Commander command = Commander();
    
    void setup()
    {
         pinMode(0, OUTPUT);  // bah, need to see the LED.
    
        // setup serial
        Serial.begin(38400);
       
        // stand  up slowly
        
        // recommended pause
        delay(100);
        
        bioloid.loadPose(QuadStart);
        bioloid.readPose();
        bioloid.interpolateSetup(500);
        
        while(bioloid.interpolating > 0)
        {
            bioloid.interpolateStep();
            delay(3);
        }
    }
    
    void loop()
    {
        // check for new messages
        if(command.ReadMsgs() > 0)
        {   
            // toggle LED so we know johnny5 is alive
            digitalWrite(0,HIGH-digitalRead(0));
        
            // only process if we aren't currently doing a sequence
            if(bioloid.playing == 0)
            {               
                if(command.walkV > 50)
                {
                    bioloid.playSeq(CrawlForward);
                }
                else if(command.walkV < -50)
                {
                    bioloid.playSeq(CrawlBackward);
                }
                else if(command.walkH > 50)
                {
                    bioloid.playSeq(CrawlSideLeft);    
                }
                else if(command.walkH < -50)
                {
                    bioloid.playSeq(CrawlSideRight);
                }
          
                if(command.buttons&BUT_R1)
                {
                    bioloid.playSeq(openFlower); 
                }
          
                if(command.buttons&BUT_R2)
                {
                    bioloid.playSeq(closeFLower);
                }
          
                if(command.buttons&BUT_R3)
                {
                    bioloid.playSeq(Crawl2Stand);
                }
            }
        }  // moved this one up from below, so that the "play" happens all the time, even if the commander isn't sending at 30hz.
      
        if(bioloid.playing > 0)
        {
            // continue sequence
            bioloid.play();  
        }
    }
    -Fergs
    Last edited by lnxfergy; 08-14-2010 at 10:48 PM.

  8. #38
    Join Date
    Dec 2007
    Location
    Whidbey Island, WA
    Posts
    1,718
    Images
    456
    Rep Power
    96

    Re: Biayered-X

    Hey,

    Not sure what I'm doing wrong. We figured out the patch. Seam to have that going.

    Here is the other stuff.

    Code:
    #include <ax12.h>
    #include <BioloidController.h>
    #include <Commander.h>
    #include "poses.h"  // exported from PyPose
    
    BioloidController bioloid = BioloidController(1000000);
    Commander command = Commander();
    
    void setup()
    {
         pinMode(0, OUTPUT);  // bah, need to see the LED.
    
        // setup serial
        Serial.begin(38400);
       
        // stand  up slowly
        
        // recommended pause
        delay(100);
        
        bioloid.loadPose(QuadStart);
        bioloid.readPose();
        bioloid.interpolateSetup(500);
        
        while(bioloid.interpolating > 0)
        {
            bioloid.interpolateStep();
            delay(3);
        }
    }
    
    void loop()
    {
        // check for new messages
        if(command.ReadMsgs() > 0)
        {   
            // toggle LED so we know johnny5 is alive
            digitalWrite(0,HIGH-digitalRead(0));
        
            // only process if we aren't currently doing a sequence
            if(bioloid.playing == 0)
            {               
                if(command.walkV > 50)
                {
                    bioloid.playSeq(CrawlForward);
                }
                else if(command.walkV < 50)
                {
                    bioloid.playSeq(CrawlBackward);
                }
                else if(command.walkH > 50)
                {
                    bioloid.playSeq(CrawlSideLeft);    
                }
                else if(command.walkH < 50)
                {
                    bioloid.playSeq(CrawlSideRight);
                }
                else
                {
                    bioloid.playSeq(CrawlStop);
                }
          
                if(command.buttons&BUT_R1)
                {
                    bioloid.playSeq(openFlower); 
                }
          
                if(command.buttons&BUT_R2)
                {
                    bioloid.playSeq(closeFLower);
                }
          
                if(command.buttons&BUT_R3)
                {
                    bioloid.playSeq(Crawl2Stand);
                }
            }
        }  // moved this one up from below, so that the "play" happens all the time, even if the commander isn't sending at 30hz.
      
        if(bioloid.playing > 0)
        {
            // continue sequence
            bioloid.play();  
        }
    }

  9. #39
    Join Date
    Dec 2007
    Location
    Whidbey Island, WA
    Posts
    1,718
    Images
    456
    Rep Power
    96

    Re: Biayered-X

    Ok,

    So I'm trying to get it so that I can send serial data letters out the serial port and have the arbotix respond by playing a sequence. For example. if I send "a" out the serial port the arbotix will play a sequence.

    Here is the code I came up with, and the errors I got trying to compile it.

    Code:
    #include <ax12.h>
    #include <BioloidController.h>
    #include <Commander.h>
    #include "poses.h"  // exported from PyPose
    
    BioloidController bioloid = BioloidController(1000000);
    Commander command = Commander();
    
    void setup()
    {
        // stand up slowly
        
        // recommended pause
        delay(100);
        
        bioloid.loadPose(QuadStart);
        bioloid.readPose();
        bioloid.interpolateSetup(500);
        
        while(bioloid.interpolating > 0)
        {
            bioloid.interpolateStep();
            delay(3);
        }
    }
    
    void loop()
    {
        // check for new messages over the serial port
        if(char x = serial.Read () )
        {   
            // toggle LED so we know johnny5 is alive
            digitalWrite(0,HIGH-digitalRead(0));
        
            // only process if we aren't currently doing a sequence
            if(bioloid.playing == 0)
            {               
                if(x== 'w') //if I press w crawl forward
                {
                    bioloid.playSeq(CrawlForward);
                }
                else if(x== 'x') //if I press x crawl backward
                {
                    bioloid.playSeq(CrawlBackward);
                }
                else if(x== 'a') //if I press a side crawl left
                {
                    bioloid.playSeq(CrawlSideLeft);    
                }
                else if(x== 'd')//if I press d side crawl right
                {
                    bioloid.playSeq(CrawlSideRight);
                }
          
                else if(x== 'f') //if I press f open the flower
                {
                    bioloid.playSeq(openFlower); 
                }
          
                else if(x== 'v') //if I press v close the flower
                {
                    bioloid.playSeq(closeFLower);
                }
          
                else if(x== 's') //if I press s stand up
                {
                    bioloid.playSeq(Crawl2Stand);
                }
            } 
        
        if(bioloid.playing > 0)
        {
            // continue sequence
            bioloid.play();  
        }
      
    }
    }
    In function 'void loop()':
    error: 'serial' was not declared in this scope

    Thanks in advance for any help.

    DB

  10. #40
    Join Date
    May 2008
    Posts
    2,228
    Images
    155
    Rep Power
    126

    Re: Biayered-X

    Code:
    #include <ax12.h>
    #include <BioloidController.h>
    #include "poses.h"  // exported from PyPose
    
    BioloidController bioloid = BioloidController(1000000);
    
    void setup()
    {  
        // need to start the serial port
        Serial.begin(38400);
    
        // recommended pause
        delay(100);
    
        // stand up slowly    
        bioloid.loadPose(QuadStart);
        bioloid.readPose();
        bioloid.interpolateSetup(500);
        
        while(bioloid.interpolating > 0)
        {
            bioloid.interpolateStep();
            delay(3);
        }
    }
    
    void loop()
    {
        // check for new messages over the serial port
        int x = Serial.read();
        if( x >= 0 )
        {   
            // toggle LED so we know johnny5 is alive
            digitalWrite(0,HIGH-digitalRead(0));
        
            // only process if we aren't currently doing a sequence
            if(bioloid.playing == 0)
            {               
                if(x== 'w') //if I press w crawl forward
                {
                    bioloid.playSeq(CrawlForward);
                }
                else if(x== 'x') //if I press x crawl backward
                {
                    bioloid.playSeq(CrawlBackward);
                }
                else if(x== 'a') //if I press a side crawl left
                {
                    bioloid.playSeq(CrawlSideLeft);    
                }
                else if(x== 'd')//if I press d side crawl right
                {
                    bioloid.playSeq(CrawlSideRight);
                }
          
                else if(x== 'f') //if I press f open the flower
                {
                    bioloid.playSeq(openFlower); 
                }
          
                else if(x== 'v') //if I press v close the flower
                {
                    bioloid.playSeq(closeFLower);
                }
          
                else if(x== 's') //if I press s stand up
                {
                    bioloid.playSeq(Crawl2Stand);
                }
            } 
        
        if(bioloid.playing > 0)
        {
            // continue sequence
            bioloid.play();  
        }
      
    }
    }
    A couple errors in capitalization made it not compile -- also, without begin(), it wouldn't actually work.

    -Fergs
    Last edited by lnxfergy; 08-18-2010 at 10:26 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •