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

Question: setMotorDirection(theMotors, direction);
http://robotc.net/forums/viewtopic.php?f=1&t=119
Page 1 of 1

Author:  larzw [ Wed Apr 04, 2007 10:13 am ]
Post subject:  Question: setMotorDirection(theMotors, direction);

I'm trying to use the function:
setMotorDirection(theMotors, direction);

What do i use for the direction parameter if i'd like to reverse the natural direction of the motor? (i assume this is what the function does)

thanks

Author:  vnguyen [ Wed Apr 04, 2007 2:04 pm ]
Post subject:  Re: Question: setMotorDirection(theMotors, direction);

larzw wrote:
I'm trying to use the function:
setMotorDirection(theMotors, direction);

What do i use for the direction parameter if i'd like to reverse the natural direction of the motor? (i assume this is what the function does)

thanks


You should actually use this function:

Code:
bMotorReflected[motorA] = true;


Obviously, if you don't want to flip motorA then you should set it to the motor you want to flip. Hope this helps..

Author:  Dick Swan [ Wed Apr 04, 2007 2:53 pm ]
Post subject: 

Mindstorms bricks can also be programmed using the graphical Robolab system. Robolab shares similar firmware with RobotC for both the RCX and NXT bricks.

'setMotorDirection' is a legacy feature required for Robolab compatibility. In Robolab, there's a series of common functions for manipulating motors that was the original RCX motor functions commands. Some of these functinos are not "natural" for the NXT and some emulation and conversion "glue" code was written to behave as close as possible to the legacy functions.

"setMotorDirection" is one of these legacy compatibility functions and it is not recommended for use in new RobotC programs.

To change motor direction you use either positive or negative power
Code:
levels to set the direction. For example
motor[motorA] =  50; // 50% of full speed, forward
motor[motorA] = -50; // 50% of full speed, reverse

// Assume 'power' is a positive integer representing the target power level
motor[motorA] =   power; // forward
motor[motorA] = -power;  // reverse

// "Flip" existing direction
motor[motorA][ = - motor[motorA];


The 'motorReflected' function is a nifty feature to chang the motor performance. Suppose you've got your robot built and you find the configuation is that one (or more) motors ends up moving in the logically opposite direction due to mechanical orientatino of the motor. On the RCX, this was easy to fix -- you simply rotated the black connector a quarter turn and this would reverse the way the pair of wires was connected to the RCX.

Connectors on the NXT are polarized and you can't use the RCX trick of physically flipping the way the wires are connected. So, the variable "bMotorReflection' is used to achieve the same effect in software.

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