View unanswered posts | View active topics It is currently Wed Jul 30, 2014 11:22 pm






Reply to topic  [ 2 posts ] 
Inconsistent Virtual Worlds 
Author Message
Rookie

Joined: Thu Jul 18, 2013 7:22 pm
Posts: 4
Post Inconsistent Virtual Worlds
Hello!

I am just beginning the Summer of Learning Robotics course and am trying to complete the Labrynth and Robo 500 challenges. I am having trouble with the Virtual Worlds program being consistent. After I found a time value that made the robot turn exactly 90 degrees, I moved on and continued with the rest of the program. To my dismay, I discovered that the robot now turned to much, even though I hadn't done anything to that part of the code. I tried to correct, but every time I thought I had fixed it, the robot would over or under turn again. I also had problems with moving straight a consistent amount. When keeping the same time value, it would move forward to little or too much.

I have discovered that if I don't close the Virtual Worlds program between code changes, the drastic over and under turns weren't near as pronounced, although they were still there.

Here is the code for Robo 500 Challenge...


Code:
 


#pragma config(StandardModel, "Virtual Worlds NXT")
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

/* Virtual Worlds Configuration (Type - Name):
Motor Port A: NXT Motor - gripperMotor
Motor Port B: NXT Motor - rightMotor
Motor Port C: NXT Motor - leftMotor
Sensor Port 1: Touch Sensor - touch
Sensor Port 2: Compass Sensor - compass
Sensor Port 3: Light Sensor - light
Sensor Port 4: Sonar Sensor - sonar
*/

task main()
{

   motor[leftMotor] = 100;                     //Forward
   motor[rightMotor] = 100;
   wait1Msec(21000);

   motor[leftMotor] = 0;                        //Pause
   motor[rightMotor] = 0;
   wait1Msec(2000);

   motor[leftMotor] = 50;                     //1st right turn
   motor[rightMotor] = 0;
   wait1Msec(8550);

   motor[leftMotor] = 0;                        //Pause
   motor[rightMotor] = 0;
   wait1Msec(2000);

   motor[leftMotor] = 100;                     //Up the left side of box
   motor[rightMotor] = 100;
   wait1Msec(20000);

   motor[leftMotor] = 0;               //Pause
   motor[rightMotor] = 0;
   wait1Msec(2000);

   motor[leftMotor] = 50;                     //2nd right turn
   motor[rightMotor] = 0;
   wait1Msec(8550);

   motor[leftMotor] = 0;                        //Pause
   motor[rightMotor] = 0;
   wait1Msec(2000);

   motor[leftMotor] = 100;                     //Forward on top side of box
   motor[rightMotor] = 100;
   wait1Msec(19500);

   motor[leftMotor] = 0;               //Pause
   motor[rightMotor] = 0;
   wait1Msec(2000);

   motor[leftMotor] = 50;                     //3rd right turn
   motor[rightMotor] = 0;
   wait1Msec(8545);

   motor[leftMotor] = 0;                        //Pause
   motor[rightMotor] = 0;
   wait1Msec(2000);

   motor[leftMotor] = 100;                     //Down the right side of box
   motor[rightMotor] = 100;
   wait1Msec(20000);

   motor[leftMotor] = 0;               //Pause
   motor[rightMotor] = 0;
   wait1Msec(2000);

   motor[leftMotor] = 50;                     //4th right turn
   motor[rightMotor] = 0;
   wait1Msec(8500);

   motor[leftMotor] = 0;                        //Pause
   motor[rightMotor] = 0;
   wait1Msec(2000);

   //REPEAT

   motor[leftMotor] = 100;                     //Forward
   motor[rightMotor] = 100;
   wait1Msec(20000);

   motor[leftMotor] = 0;                        //Pause
   motor[rightMotor] = 0;
   wait1Msec(2000);

   motor[leftMotor] = 50;                     //1st right turn
   motor[rightMotor] = 0;
   wait1Msec(8500);

   motor[leftMotor] = 0;                        //Pause
   motor[rightMotor] = 0;
   wait1Msec(2000);

   motor[leftMotor] = 100;                     //Up the left side of box
   motor[rightMotor] = 100;
   wait1Msec(20000);

   motor[leftMotor] = 0;               //Pause
   motor[rightMotor] = 0;
   wait1Msec(2000);

   motor[leftMotor] = 50;                     //2nd right turn
   motor[rightMotor] = 0;
   wait1Msec(8550);

   motor[leftMotor] = 0;                        //Pause
   motor[rightMotor] = 0;
   wait1Msec(2000);

   motor[leftMotor] = 100;                     //Forward on top side of box
   motor[rightMotor] = 100;
   wait1Msec(19000);

   motor[leftMotor] = 0;               //Pause
   motor[rightMotor] = 0;
   wait1Msec(2000);

   motor[leftMotor] = 50;                     //3rd right turn
   motor[rightMotor] = 0;
   wait1Msec(8550);

   motor[leftMotor] = 0;                        //Pause
   motor[rightMotor] = 0;
   wait1Msec(2000);

   motor[leftMotor] = 100;                     //Down the right side of box
   motor[rightMotor] = 100;
   wait1Msec(20000);

   motor[leftMotor] = 0;               //Pause
   motor[rightMotor] = 0;
   wait1Msec(2000);

   motor[leftMotor] = 50;                     //Final right turn
   motor[rightMotor] = 0;
   wait1Msec(8600);

}
 
 






Thanks!
Lacey


Fri Jul 19, 2013 12:45 pm
Profile
Moderator
Moderator

Joined: Mon Oct 04, 2010 2:18 pm
Posts: 180
Post Re: Inconsistent Virtual Worlds
Hi Lacey,

A few things. First, try not to have your robot move forward at 100% power. Basically, the robot moves in a very unreliable fashion when it is moving at full power. I always make an analogy with a baseball pitcher throwing a baseball. It is hard to locate a pitch that you throw at top speed. The same concept also applies to your turns. You can slow them down a touch and they will probably become a little more reliable.

Second, you are currently using timing (wait1Msec) to control the movements of your robot. As you progress through the ROBOTC Curriculum, you are going to learn more advanced ways to program your robot (using sensors and encoders, for example) that are much, much more reliable than timing. You are right, when programming your robot with timing, the robot does move unreliably. The thing is, this would also transfer over to a physical robot. Programming with wait1Msec commands isn't the most reliable. But, fear not, you are going to learn some more advanced ways in the very near future.

Your code looks good. You included a stop after each of your movements. Many people when they first start out make the mistake of not including those. I made that mistake often myself when I started.

For the Robo 500 challenge, my recommendation would be to first slow down. Also, make sure that you are going far enough ahead to give yourself a little more room for error on your turns.

You are off to a great start. Please don't be afraid to continue to use the forums as you progress.


Fri Jul 19, 2013 6:44 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.