vexCode Text Help

20191223_153048 20191223_153106
I’m trying to figure out why I am getting this error. Thanks

Drive forward is not a command in vexcode.
It would be rotate or rotateFor.
Remember, code isnt quite like normal english :wink:

Also you might want to take a clearer picture. I can’t really see anything.

This is my other account, having issues with my other one. driveForward is a function that I made

1 Like

Can you post a pic of your drive forward function?

57 PM At the top of the picture

In the future, please copy and paste your code in to the forum (remembering to wrap it in [code]...[/code] tags), or zip up the project folder and upload it as an attachment, rather than posting photos or screenshots. In this case it happened that the relevant parts were visible in the images you uploaded, but that’s not always the case, and it’s much easier to debug code if you can copy and edit it.

Anyway, there are several problems with your code:

  • The parameters you’re passing to driveForward do not match the parameters you’ve defined it as taking. In your definition of the function, dir is a string, but when you call the function you’re passing fwd, which is of type vex::directionType.
  • I notice also that you’re checking to see if the dir is the literal string "rev", and setting some values to -1 if so. This probably won’t work the way you want it to, since (a) you’re not passing a string as that parameter (see above), (b) if the dir parameter is “rev” then you travel for a negative number of revolutions at a negative speed, which will be equivalent to moving forwards.
  • Your parameters are in a different order in the function definition than when you actually call the function.

Here’s some code that probably does what you want:

void driveForward(directionType dir, int speed, int dist, int timeout, bool blocking){
    double revolutions = dist/wheelCircumference;
    if (timeout >= 15) timeout *= .001;
    driveMotors(timeout, timeUnits::sec);
    driveMotors.rotateFor(dir, revolutions, rotationUnits::rev, speed, velocityUnits::pct, blocking);
}
4 Likes

The parameters in your function dont match the parameters when you call the function

2 Likes

Ok, so I’m really dumb, forgot quotes around fwd.

And are you able to explain how putting directionType dir works please

Sure, I can try!

directionType is a variable type like any other (in this case an enum), and like any other variable type you can use it as a parameter in a function you write.

Just like rotateFor takes a directionType parameter, so too does the code I posted above, and it passes the parameter on to rotateFor to indicate which direction the motors should spin.

1 Like

Ok thank you, that helps. I just wanted to understand why I’m doing that before I just put in

Also, if timeout is declared as int then when you multiply it by 0.001 it will always truncate to whole seconds.

It may be better to use timeUnits::msec when setting timeout.

https://api.vexcode.cloud/v5/html/namespacevex.html#a50d26e49f5c2c9a4acf9f35985f63de8

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.