Page 1 of 1

plz Help; How to make a robot follow Distance? (NXC)

Posted: 02 Dec 2011, 15:59
by onewinged
Dear memebers,
I'm a college student who's new in programming with NXC
but I came across a problem which is ,I don't know how to make an NXT robot walk for a specific distance ?
for instance: I want to make the robot move forward 7 meters ??
what's the code?

Re: plz Help; How to make a robot follow Distance? (NXC)

Posted: 02 Dec 2011, 16:30
by HaWe
if you mean "go ahead" by wheels :
you may calculate how many rotations you need for each wheel to go 7 meters.
for instance, if the wheel circumference is 20 cm, you need 35 rotations with 360° each = 35*360 = 12600 encoder counts

so start your engines
monitor the rotation counts
and if rotation counts >= 12600 then stop your engines.

If you mean "walk" for a humanoid robot, you will have to count the step size analogously instead of wheel rotations.

Of course more advanced navigation algorithms are possible, based on odometry, compass, and gyro sensor - such a project is already discribed in the projects subforum.

HTH!

Re: plz Help; How to make a robot follow Distance? (NXC)

Posted: 02 Dec 2011, 22:41
by onewinged
doc-helmut wrote:if you mean "go ahead" by wheels :
you may calculate how many rotations you need for each wheel to go 7 meters.
for instance, if the wheel circumference is 20 cm, you need 35 rotations with 360° each = 35*360 = 12600 encoder counts

so start your engines
monitor the rotation counts
and if rotation counts >= 12600 then stop your engines.
it's exactly as you said
but I'm using NXC and the code for moving forward is like this one >>

Code: Select all

OnFwd(OUT_C, 75);
Wait(4000);
as I studied, I conclude that it means move forward with a speed of 75 for 4 seconds :)
but I need is to make it move by distance not speed ?
I thought maybe to use the equation (D=S x T T=D/S S= D/T /=divide x=multiply. D=distance. S=speed. T=time) by calculating the amount of time the robot takes to do 1 meter with a speed of 75 ...
but I need a better solution coz Im not sure if that will work
thank you so much ,,,and sorry for my poor english ^_^"

Re: plz Help; How to make a robot follow Distance? (NXC)

Posted: 03 Dec 2011, 08:17
by h-g-t
From the NXC Programmer's Guide byJohn Hansen

RotateMotor(outputs, pwr, angle) Function

Run the specified outputs forward for the specified number of degrees.
Outputs can be a constant or a variable containing the desired output ports.
Predefined output port constants are defined in Table 20.

RotateMotor(OUT_A, 75, 45); // forward 45 degrees
RotateMotor(OUT_A, -75, 45); // reverse 45 degrees

RotateMotorEx(outputs, pwr, angle, turnpct, sync, stop) Function


Run the specified outputs forward for the specified number of degrees.
Outputs can be a constant or a variable containing the desired output ports.
Predefined output port constants are defined in Table 20.
If a non-zero turn percent is specified then sync must be set to true or no turning will occur.
Specify whether the motor(s) should brake at the end of the rotation using the stop parameter.

RotateMotorEx(OUT_AB, 75, 360, 50, true, true);

Re: plz Help; How to make a robot follow Distance? (NXC)

Posted: 03 Dec 2011, 08:23
by spillerrec
You can find all commands in the documentation, the most up-to-date version is found here: http://bricxcc.sourceforge.net/nbc/nxcdoc/nxcapi/. The motor commands are found in "Modules->NXT Firmware Modules->Output module". Be aware that some commands require the latest test version of BCC and the enhanced firmware in order to work. You can get the test releases here: http://bricxcc.sourceforge.net/test_releases/

Re: plz Help; How to make a robot follow Distance? (NXC)

Posted: 03 Dec 2011, 08:54
by HaWe
you also may use OnFwd, but as I mentioned, you also have to monitor the encoder:

Code: Select all

OnFwd(OUT_C, 75); // start motor C by power 75%
while (MotorRotationCount(OUT_C)<12600); // wait until target count reached
Off(OUT_C); // then switch off motor
Maybe you wish to have a look at the NXC tutorial by Daniele Benedettelli? http://bricxcc.sourceforge.net/nbc/nxcd ... torial.pdf

Re: plz Help; How to make a robot follow Distance? (NXC)

Posted: 04 Dec 2011, 21:05
by onewinged
THANKS A LOT GUYS FOR THE HELP

doc-helmut wrote:you also may use OnFwd, but as I mentioned, you also have to monitor the encoder:

Code: Select all

OnFwd(OUT_C, 75); // start motor C by power 75%
while (MotorRotationCount(OUT_C)<12600); // wait until target count reached
Off(OUT_C); // then switch off motor
I guess I'll be following the counting method
but..
I just have one more questions if you may! :)
20 cm, you need 35 rotations with 360° each = 35*360 = 12600 encoder counts
I don't get how you interpreted the 35 rotations? can you explain it plz ?

Re: plz Help; How to make a robot follow Distance? (NXC)

Posted: 04 Dec 2011, 21:38
by spillerrec
If one full rotation (360°) moves the robot 20 cm forward, the amount of rotations to go the full distance would be 700 cm / 20 cm = 35. So in degrees it would be 35 * 360° = 12600°.

Re: plz Help; How to make a robot follow Distance? (NXC)

Posted: 04 Dec 2011, 22:29
by onewinged
spillerrec wrote:If one full rotation (360°) moves the robot 20 cm forward, the amount of rotations to go the full distance would be 700 cm / 20 cm = 35. So in degrees it would be 35 * 360° = 12600°.
aha! now I get it !
thanks a million ;D