ROBOTC.net forums
http://www.robotc.net/forums/

Teach me robotC please?
http://www.robotc.net/forums/viewtopic.php?f=1&t=6547
Page 1 of 1

Author:  tommy71394 [ Sat Aug 17, 2013 11:34 am ]
Post subject:  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

Author:  tommy71394 [ Tue Aug 20, 2013 7:51 am ]
Post subject:  Re: Teach me robotC please?

Anyone? =/

Author:  mightor [ Wed Aug 21, 2013 8:21 am ]
Post subject:  Re: Teach me robotC please?

I've moved this topic to the right place.

= Xander

Author:  tommy71394 [ Wed Aug 21, 2013 9:08 am ]
Post subject:  Re: Teach me robotC please?

mightor wrote:
I've moved this topic to the right place.

= Xander

Thank you. :3

Author:  mightor [ Wed Aug 21, 2013 12:24 pm ]
Post subject:  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

Author:  tommy71394 [ Wed Sep 04, 2013 10:47 am ]
Post subject:  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

Author:  mightor [ Wed Sep 04, 2013 11:12 am ]
Post subject:  Re: Teach me robotC please?

http://www.robotc.net/education/curriculum/nxt/

= Xander

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/