View unanswered posts | View active topics It is currently Sun Aug 31, 2014 7:18 am






Reply to topic  [ 2 posts ] 
Help! NQC code trouble 
Author Message
Rookie

Joined: Thu Feb 21, 2013 6:07 pm
Posts: 1
Post Help! NQC code trouble
Hi,
I am new here so I apologize in advance if I am posting in the wrong section.
I am working on a code for a tankbot with a light sensor and a touch sensor. It has to follow a black line, and make turns at t intersections. It will bump into a small object, back up and turn. It has to stop at a green pad at the end of a track. This is my code so far:

#define THRESHOLD 39

int x=0;

task main()
{
SetUserDisplay(x,0);
SetSensor(SENSOR_1,SENSOR_TOUCH);
SetSensor(SENSOR_2,SENSOR_LIGHT);
start turn;
OnFwd(OUT_A+OUT_C);
while(true)
{
if(SENSOR_2 > THRESHOLD)
{OnRev(OUT_C);
OnFwd(OUT_A);
until(SENSOR_2 <=THRESHOLD);}

}
}
task turn()
{
if(x == 0 && SENSOR_1 == 1) //first turn
{
until(SENSOR_1 == 0);
x=x+1;
OnRev(OUT_A+OUT_C);
Wait(20);
OnFwd(OUT_A);
OnRev(OUT_C);
until(SENSOR_2 <= THRESHOLD);}
if(x == 1 && SENSOR_1 == 1) //second turn
{
until(SENSOR_1 == 0);
x=x+1;
OnRev(OUT_A+OUT_C);
Wait(20);
OnFwd(OUT_C);
OnRev(OUT_A);
until(SENSOR_2 <= THRESHOLD);
}



if(x == 2 && SENSOR_1 == 1) //third turn
{until(SENSOR_1 == 0);
x=x+1;
OnRev(OUT_A+OUT_C);
Wait(20);
OnFwd(OUT_A);
OnRev(OUT_C);
until(SENSOR_2 <= THRESHOLD);
}
}

-------------------

Can somebody help me? It is not working correctly and I have no idea how to improve it.

Here is the link to the track

http://i.imgur.com/XPIRBD3.jpg


Thu Feb 21, 2013 6:14 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3205
Location: Rotterdam, The Netherlands
Post Re: Help! NQC code trouble
Hey there,

This is a ROBOTC forum, questions about NQC and NXC are best off asked on the Mindboards forums :) You can find them here: https://sourceforge.net/apps/phpbb/mindboards/index.php

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Feb 22, 2013 1:56 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 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.