[NXC]Questions from a newbie :-)

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
jojoguy14
Posts: 155
Joined: 29 Sep 2010, 12:49
Contact:

[NXC]Questions from a newbie :-)

Post by jojoguy14 »

Hello people!

I' starting to learn NXC (slowly!) I have John Hansen's book and I've been using it as a reference.
I'm an NXT-G guy. I LOVE graphical programming languages :) . So, I've started "copying" the NXT-G Robot Center programs to NXC. I'm on the ShooterBot with the Color Sensor program (but, I'm using a light sensor in my program).
1. I need help (in general) how to setup a sensor and using/reading from it.
2. How to use a While loop to control when I want the program to stop.
Here's the code (MUCH easier pasting NXC code than NXT-G code, lol! :) )

Code: Select all

task main() {
  SetSensorType(S3, SENSOR_TYPE_LIGHT_INACTIVE);
  SetSensorMode(S3, SENSOR_MODE_PERCENT);
    while (ButtonState(BTNCENTER) = false) {
    if (Sensor(S3) < 50) {
      RotateMotor(OUT_B, 75, 954);
      RotateMotor(OUT_C, 75, -954);
      RotateMotor(OUT_BC, 75, 1440);
    } else {
    OnFwd(OUT_BC, 50);
    }
  }
}
I hope you can help me out!
Joey "jojoguy10"
Creator of LEGO-X TechN'XT! (http://lego-x.com http://techn-xt.blogspot.com)
Known as jojoguy10
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: [NXC]Questions from a newbie :-)

Post by mattallen37 »

This compiles:

Code: Select all

task main() {
  SetSensorType(S3, SENSOR_TYPE_LIGHT_INACTIVE);
  SetSensorMode(S3, SENSOR_MODE_PERCENT);
    while (ButtonState(BTNCENTER) == false) {        // For comparison use == and not =
    if (Sensor(S3) < 50) {
      RotateMotor(OUT_B, 75, 954);
      RotateMotor(OUT_C, 75, -954);
      RotateMotor(OUT_BC, 75, 1440);
    } 
    else {
      OnFwd(OUT_BC, 50);
    }
  }
}
When you're comparing values, you need to use 2 equals signs, instead of one.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
jojoguy14
Posts: 155
Joined: 29 Sep 2010, 12:49
Contact:

Re: [NXC]Questions from a newbie :-)

Post by jojoguy14 »

Thanks a bunch!
Another question:
How do I make a point turn in NXC (both motors move in opposite directions at the same time)?
Creator of LEGO-X TechN'XT! (http://lego-x.com http://techn-xt.blogspot.com)
Known as jojoguy10
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: [NXC]Questions from a newbie :-)

Post by mattallen37 »

Like this?

Code: Select all

OnFwd(OUT_B, 100);
OnRev(OUT_C, 100);
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
jojoguy14
Posts: 155
Joined: 29 Sep 2010, 12:49
Contact:

Re: [NXC]Questions from a newbie :-)

Post by jojoguy14 »

mattallen37 wrote:Like this?

Code: Select all

OnFwd(OUT_B, 100);
OnRev(OUT_C, 100);
Yes, but how do you do that for a certain amount of degrees?
Creator of LEGO-X TechN'XT! (http://lego-x.com http://techn-xt.blogspot.com)
Known as jojoguy10
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

Re: [NXC]Questions from a newbie :-)

Post by h-g-t »

A sophistical rhetorician, inebriated with the exuberance of his own verbosity, and gifted with an egotistical imagination that can at all times command an interminable and inconsistent series of arguments to malign an opponent and to glorify himself.
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: [NXC]Questions from a newbie :-)

Post by mattallen37 »

For absolute position control, I usually use the APR functions that are FW implemented. I don't think I have ever really used RotateMotor before, so I'm not exactly sure how it works.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
jojoguy14
Posts: 155
Joined: 29 Sep 2010, 12:49
Contact:

Re: [NXC]Questions from a newbie :-)

Post by jojoguy14 »

h-g-t wrote:You need to use rotate motor - RotateMotor(OUT_AC, 50,360 );

See http://css.engineering.uiowa.edu/~cie/L ... torial.pdf

and http://bricxcc.sourceforge.net/nbc/nxcdoc/NXC_Guide.pdf
Well....thanks, but that didn't help with turning the motors in OPPOSITE directions. But, thanks to you, I looked it up and found something similar: RotateMotorEx. With that, I can define the "turnpct" :-). I set that to 100% and it worked like a charm!

Thanks!
Creator of LEGO-X TechN'XT! (http://lego-x.com http://techn-xt.blogspot.com)
Known as jojoguy10
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 8 guests