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

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
onewinged
Posts: 11
Joined: 02 Dec 2011, 15:50

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

Post 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?
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

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

Post 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!
onewinged
Posts: 11
Joined: 02 Dec 2011, 15:50

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

Post 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 ^_^"
h-g-t
Posts: 552
Joined: 07 Jan 2011, 08:59
Location: Albania

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

Post 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);
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.
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

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

Post 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/
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

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

Post 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
onewinged
Posts: 11
Joined: 02 Dec 2011, 15:50

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

Post 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 ?
spillerrec
Posts: 358
Joined: 01 Oct 2010, 06:37
Location: Denmark
Contact:

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

Post 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°.
My blog: http://spillerrec.dk/category/lego/
RICcreator, an alternative to nxtRICeditV2: http://riccreator.sourceforge.net/
onewinged
Posts: 11
Joined: 02 Dec 2011, 15:50

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

Post 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
Post Reply

Who is online

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