RobotC help needed!

This is a discussion on RobotC help needed! within the Game Programming forums, part of the General Programming Boards category; ok, so i have a robotc that is to navigate a course, find a colored block and deliver it to ...

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    22

    RobotC help needed!

    ok, so i have a robotc that is to navigate a course, find a colored block and deliver it to the correct corner. there is red, blue, and red.

    this is the program i have so far and it is a failure... any pointers on how to get my robot to do this would be greatly appreciated!!

    Code:
    #pragma config(Sensor, S4,lightSensor, sensorLightActive)
    #pragma config(Sensor, S3,  sonarSensor1, sensorSONAR)//side
    #pragma config(Sensor, S1,  colorPort, sensorCOLORFULL)
    #pragma config(Sensor, S2, sonarSensor2, sensorSONAR)
    //Function
    
    
    // robot goes back and forth across the area
    void BackandForth()
    {
      while(sensorValue[sonarSensor1 || sonarSensor2] > 12)
    {
      motor(motorB)=20;
      motor(motorC)=20;
    }
    
    
      //Left Turn
      motor(motorB)=16.665;
      motor(motorC)=-16.665;
      wait1Msec(1150);
    
    
      //forward for 1 sec
      motor(motorB)=20;
      motor(motorC)=20;
      wait1Msec(100);
    
    
      //Left Turn
      motor(motorB)=16.665;
      motor(motorC)=-16.665;
      wait1Msec(1150);
    
    
      //forward for 5 sec
      motor(motorB)=20;
      motor(motorC)=20;
      wait1Msec(500);
    
    
      while(sensorValue[sonarSensor1 || sonarSensor2] > 8)
    {
      motor(motorB)=20;
      motor(motorC)=20;
    }
    
    
      //Right Turn
      motor(motorB)=-16.665;
      motor(motorC)=16.665;
      wait1Msec(1150);
    
    
      motor(motorB)=20;
      motor(motorC)=20;
      wait1Msec(100);
    
    
      //Right turn
      motor(motorB)=-16.665;
      motor(motorC)=16.665;
      wait1Msec(1150);
    
    
      motor(motorB)=20;
      motor(motorC)=20;
      wait1Msec(500);
    
    
      while(sensorValue[sonarSensor1 || sonarSensor2] > 8)
    {
      motor(motorB)=20;
      motor(motorC)=20;
    }
    
    
      //Left Turn
      motor(motorB)=16.665;
      motor(motorC)=-16.665;
      wait1Msec(1150);
    
    
      motor(motorB)=20;
      motor(motorC)=20;
      wait1Msec(100);
    
    
      //Left Turn
      motor(motorB)=16.665;
      motor(motorC)=-16.665;
      wait1Msec(1150);
    
    
      motor(motorB)=20;
      motor(motorC)=20;
      wait1Msec(500);
    
    
    
    
      while(sensorValue[sonarSensor1 || sonarSensor2] > 8)
    {
      motor(motorB)=20;
      motor(motorC)=20;
    }
    
    
      //Right Turn
      motor(motorB)=-16.665;
      motor(motorC)=16.665;
      wait1Msec(1150);
    
    
      motor(motorB)=20;
      motor(motorC)=20;
      wait1Msec(100);
    
    
      //Right turn
      motor(motorB)=-16.665;
      motor(motorC)=16.665;
      wait1Msec(1150);
    
    
      motor(motorB)=20;
      motor(motorC)=20;
      wait1Msec(500);
    }
    
    
    
    
    void stayNearWall()
    {
      
    while(SensorValue[sonarSensor1 || sonarSensor2] => 10)
    {
      motor(motorB)=20;
      motor(motorC)=0;
      wait1Msec(100);
      
      motor(motorB)=20;
      motor(motorC)=20;
      
      
    }
      while(SensorValue[sonarSensor1 || sonarSensor2]=< 12)
    {
      motor(motorB)=20;
      motor(motorC)=0;
      wait1Msec(100);
      
      motor(motorB)=20;
      motor(motorC)=20;
    }
    
    
    }
    
    
    void ClampClaw()
    {
        motor(motorA)=25;
        wait1Msec(100);
    }
    
    
    void ReleaseClaw()
    {
        motor(motorA)=-25;
        wait1Msec(100);
    }
    task main()
    {
      do 
      motor(motorB)=25;
      motor(motorC)=25;
     
      while(SensorValue[sonarSensor1 || sonarSensor2] >5)
    {
        if(SensorValue[colorPort]== BLUECOLOR)
    {
    
    
        ClampClaw();
        stayNearWall();
          if (SensorValue[lightSensor] >8 || <11)
        {
          ReleaseClaw();
          motor(motorB)=-50;
          motor(motorC)=-50;
          wait1Msec(500);
          BackandForth();
        }
          else
        {  stayNearWall();
        }  
       if else(SensorValue[colorPort]== REDCOLOR)
        {
          ClampClaw();
          stayNearWall();
          if (SensorValue[lightSensor] >12 || >15)
       {
          ReleaseClaw();
          motor(motorB)=-50;
          motor(motorC)=-50;
          wait1Msec(500);
          BackandForth();
      }  
          else
          { stayNearWall();
          }
       if else(SensorValue[colorPort] == GREENCOLOR)
        {
          ClampClaw();
          stayNearWall();
          if (SensorValue[lightSensor] >15 || <13)
       {
           ReleaseClaw();
           motor(motorB)=-50;
           motor(motorC)=-50;
           wait1Msec(500);
           BackandForth();
        }
      }
        else
    {
        motor(motorB)=50;
        motor(motorC)=50;
    }
    }

  2. #2
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    Are you asking a question or...?

    Not knowing the API, but at face value, you should definitely turn a lot of those repeated blocks into macros and/or functions, to make your code more readable.

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    22
    i just dont know what to do to get it to run. im not sure what you mean. im pretty new to programming... i made the 4 functions for clamping with the claw, releasing with the claw, going back and forth and staying near a wall. when i try to run it, it will go in a circle... thats about it

  4. #4
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    So follow the control flow of the program, and see where it's going in a circle. Add printf()s before and after where you think it should be moving the claw/going back and forth/etc.

    But it will be a lot easier to do this if you don't have a ton of repeated code. I see
    Code:
      motor(motorB)=-16.665;  motor(motorC)=16.665;
      wait1Msec(1150);
     
     
      motor(motorB)=20;
      motor(motorC)=20;
      wait1Msec(100);
    repeated a bunch, so make that its own function and call it whenever you need to. Repeat as needed with other often-used bits of code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. some help needed here
    By n3cr0_l0rd in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2009, 11:38 AM
  2. Help needed
    By TheNinja in forum C Programming
    Replies: 2
    Last Post: 10-13-2005, 04:25 PM
  3. More help needed
    By Niq in forum C++ Programming
    Replies: 2
    Last Post: 04-20-2003, 05:41 PM
  4. Some Help Needed!
    By ob1cnobe in forum C++ Programming
    Replies: 7
    Last Post: 05-29-2002, 04:08 PM
  5. needed help please..( C++ in AV)
    By amebakit in forum C++ Programming
    Replies: 3
    Last Post: 05-22-2002, 08:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21