View unanswered posts | View active topics It is currently Sat Oct 25, 2014 8:47 am






Reply to topic  [ 7 posts ] 
Teach me robotC please? 
Author Message
Rookie

Joined: Sat Aug 17, 2013 11:23 am
Posts: 4
Location: Malaysia
Post Teach me robotC please?
Hello, I am really interested in ROBOTC, and is actually using it to practice my C on robotics if I need it for competitions. I've made a program from NRC 2013 in ROBOTC, I know that since only NXT-G is allowed in the regular category, I'm not afraid of posting answers out that is in C. Well... I rarely see anyone posting this type of post, so I post this in to off-topic. Please provide any information on the following program, give me tips, hints, or tell me how to improve. Thanks and sorry for the trouble. Oh ya, I have not tested this on my robot yet(I'm having a holiday and my robot is not currently with me). And some values(i.e: hitacc, etc) is 0 because I have not tuned it for my robot yet. I plan to make this a fully functional program, but will reprogram the whole thing in NXT-G because the competition needs me to. And the endzone is left empty because I ran out of ideas on how to use it. :(

Code:
#pragma config(Sensor, S1,     color,          sensorCOLORFULL)
#pragma config(Sensor, S2,     light,          sensorLightActive)
#pragma config(Motor,  motorA,          hammer,        tmotorNXT, openLoop, encoder)
#pragma config(Motor,  motorB,          left,          tmotorNXT, openLoop, encoder)
#pragma config(Motor,  motorC,          right,         tmotorNXT, openLoop, encoder)

void accmove(int movecm);
void hammerhit(int hitacc);
int ballcount();
void high1();
void startzone();
int lightcheck();
int colorcheck();
void low();
void high2();
void endzone();

task main()
{
   startzone();
   high1();
   accmove(0);
   low();
   accmove(0);
   high2();
   accmove(0);
   high1();
   accmove(0);
   low();
   accmove(0);
   high2();
   endzone();
}

void accmove(int movecm) //To move accurately, via CM
{
   int moverotation;
   int time = 0;
   int movetime;

   moverotation = movecm * 0.1225;
   movetime = moverotation / time;

   motor[left] = 100;
   motor[right] = 100;
   wait1Msec(movetime);
   motor[left] = 0;
   motor[right] = 0;
}

void hammerhit(int hitacc) //To determine hit accuracy of hammer
{
   motor[hammer] = 100;
   wait1Msec(hitacc);
   motor[hammer] = 0;
   wait1Msec(100);
   motor[hammer] = 90;
   wait1Msec(hitacc);
   motor[hammer] = 0;
   ballcount();
}

int ballcount() //To calculate amount of balls taken
{
   int balltotal;
   balltotal = balltotal + 1;
   return balltotal;
}

void startzone() //To move from starting zone to first zone with ease
{
   int startacc = 0;

   motor[left] = 100;
   motor[right] = 100;
   wait1Msec(startacc);
   motor[left] = 0;
   motor[right] = 0;
}

int lightcheck() //To check and determine red ball via light sensor
{
   int lightvalue;

   if(SensorValue(light) > 30)
      {
         lightvalue = 1;
      }
   else
      {
         lightvalue = 0;
      }
   return lightvalue;
}

int colorcheck() //To check and determine red ball via color sensor
{
   int colorcode;

   if(SensorValue(color) == REDCOLOR)
      {
         colorcode = 1;
      }
   else
      {
         colorcode = 0;
      }
   return colorcode;
}

void high1() //To go through high1 with ease
{
   int lightresult;
   int colorresult;

   lightcheck();
   lightresult = lightcheck();
   if(lightresult == 1)
      {
         hammerhit(0);
      }
   accmove(2);
   colorcheck();
   colorresult = colorcheck();
   if(colorresult == 1)
      {
         hammerhit(0);
      }
}

void low() //To go through low with ease
{
   int lightresult;
   int colorresult;

   lightcheck();
   lightresult = lightcheck();
   if(lightresult == 1)
      {
         hammerhit(0);
      }
   accmove(2);
   colorcheck();
   colorresult = colorcheck();
   if(colorresult == 1)
      {
         hammerhit(0);
      }
      accmove(2);
      lightcheck();
   lightresult = lightcheck();
   if(lightresult == 1)
      {
         hammerhit(0);
      }
}

void high2() //To go through high2 with ease
{
   int lightresult;
   int colorresult;

   colorcheck();
   colorresult = colorcheck();
   if(colorresult == 1)
      {
         hammerhit(0);
      }
      accmove(2);
      lightcheck();
   lightresult = lightcheck();
   if(lightresult == 1)
      {
         hammerhit(0);
      }
}

void endzone()
{
   
}


P/S: Spoilers not allowed? :S


Sat Aug 17, 2013 11:34 am
Profile
Rookie

Joined: Sat Aug 17, 2013 11:23 am
Posts: 4
Location: Malaysia
Post Re: Teach me robotC please?
Anyone? =/


Tue Aug 20, 2013 7:51 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: Teach me robotC please?
I've moved this topic to the right place.

= 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]


Wed Aug 21, 2013 8:21 am
Profile WWW
Rookie

Joined: Sat Aug 17, 2013 11:23 am
Posts: 4
Location: Malaysia
Post Re: Teach me robotC please?
mightor wrote:
I've moved this topic to the right place.

= Xander

Thank you. :3


Wed Aug 21, 2013 9:08 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: Teach me robotC please?
The code in your program looks pretty good. If you're keen to get more acquainted with ROBOTC, you should check the ROBOTC website for the curriculum, Other than that, there are plenty of example programs that are shipped with ROBOTC. Take a look at them and see if you can understand what they're doing, change them to suit your own needs :)

= 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]


Wed Aug 21, 2013 12:24 pm
Profile WWW
Rookie

Joined: Sat Aug 17, 2013 11:23 am
Posts: 4
Location: Malaysia
Post Re: Teach me robotC please?
mightor wrote:
The code in your program looks pretty good. If you're keen to get more acquainted with ROBOTC, you should check the ROBOTC website for the curriculum, Other than that, there are plenty of example programs that are shipped with ROBOTC. Take a look at them and see if you can understand what they're doing, change them to suit your own needs :)

= Xander

Check where? Could you please give me some links to get started? Thank you and sorry for the trouble. :D


Wed Sep 04, 2013 10:47 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: Teach me robotC please?
http://www.robotc.net/education/curriculum/nxt/

= 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]


Wed Sep 04, 2013 11:12 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 7 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:  



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