View unanswered posts | View active topics It is currently Fri Sep 19, 2014 7:53 am






Reply to topic  [ 3 posts ] 
Issues with Autonomous Code 
Author Message
Rookie

Joined: Fri Feb 10, 2012 9:07 pm
Posts: 2
Post Issues with Autonomous Code
Hello, im new to both the forums and using ROBOTC. I am in a competition in college where we have to build and program an NXT robot to do the following:

1) Avoid obstacles
2) Find objects, small canisters, and tell whether they are trash(dont beep) or nuclear(beep)
3) Take the trash to the corner with a bright light(got this down perfect)
4) Take the nuclear canister to the corner across from the light corner

So I began with just a simple go forward until touch sensor is pressed finding strategy, but once I tried to alter the code to include a turn in while loop, the robot doesnt seem to notice there is a canister in its claw, or at least doesnt for awhile. I know the while condition isnt assesed until after the statement is run, but is there any way i can have it always checking for the canister and keep going 3 feet forward and then turn 195 degrees?

Code:
while( SensorValue[touch] == 0 ) {        // While there is nothing in the claw, keep on moving
        motor[Left] = 80;                       
        motor[Right] = 80;
        wait10Msec(2000);
       
        motor[Left] = 20;                       // Turn
        motor[Right] = 65;
        wait1Msec(1950);
      }
     
      motor[Left] = 0;
      motor[Right] = 0;


Also, in developing the code to find the nuclear deposit zone, I ran into some issues because one simply cant have the robot find the light corner and then turn 180 degrees and go forward for awhile bc the canisters can be placed anywhere on the field and thus the robot can be at various different angles in respect to the light source. My idea was to have the robot find the light, then slowly turn and as it turns, take in values using the ultrasonic sensor to determine where it is in terms of cardinal directions. So having lots of 'leftwall = true', 'bottomwall = false' type of statements. If you have any ideas or hints that would be wonderful. I look forward to your responce(s)!

Thanks,

Knox.


Fri Feb 10, 2012 9:33 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: Issues with Autonomous Code
The lag you notice is because you have wait statements in your while loop. The boolean statement in the while loop isn't being tested while you're waiting. By the way, I don't know if this is a typo when posting your code, but you have used "wait10Msec(2000)" when moving forward. This will wait for 20 seconds, which sounds like an awfully long time to move 3 feet. I don't quite understand what you mean by "have it always checking for the canister and keep going 3 feet forward and then turn 195 degrees". What do you want to happen when the button is pressed? Does the robot stop? Maybe something like this?
Code:
task main(){
  ClearTimer(T1);
  while((SensorValue[touch] == 0) && (time1[T1] < 2000)) {        // While there is nothing in the claw, keep on moving
        motor[Left] = 80;
        motor[Right] = 80;
  }
  ClearTimer(T1);
  while((SensorValue[touch] == 0) && (time1[T1] < 1950)){
    motor[Left] = 20;                       // Turn
    motor[Right] = 65;
  }

  motor[Left] = 0;
  motor[Right] = 0;
}


You are running all of this with timing, a strategy called "dead reckoning". This is usually very imprecise, and does not seem to fit your what you want to do. For example, you want to "turn 195 degrees". This level of precision is usually not possible without using sensors. As for turning and travelling directly across the field from the light source, I don't think that the strategy that you have described would work. Using the lego ultrasonic sensor to determine angles in that way doesn't seem feasible to me. At most, you could estimate the direction, and then correct yourself when you get near the other corner. Are you allowed to go down the sides of the field instead of cutting through the middle? That seems much more doable.

_________________
sudo rm -rf /


Last edited by magicode on Sat Feb 11, 2012 12:44 am, edited 3 times in total.



Fri Feb 10, 2012 11:27 pm
Profile
Rookie

Joined: Fri Feb 10, 2012 9:07 pm
Posts: 2
Post Re: Issues with Autonomous Code
The wait10Msec was a mistake, but im trying to have it run a continuous loop looking for the objects I need to sort. So it has to move 3 or so feet forward and then turn to make that next 3 or so feet at a slight angle as to not make a oval like shape, but a flower type pattern covering a large area. I have the actual movement down, i just needed the touch sensor to always stop the robot and close my claw when it was pressed. I'll try the code you wrote and get back to you about it.

Also, for the navigation, ive wrote some code utilizing the walls and the fact that if i turn towards the light and figure out which walls my robot is by, i can get a rough estimate of where I am and then use the walls and left hand turns to get me to the nuclear corner.


Thanks for the response!

-Knox


Fri Feb 10, 2012 11:47 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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:  
cron



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