Enumerator Question

We have had to add velocityUnits:: to our code anytime we use pct as an argument. Not sure why that one enumerator is acting up, but it sure is annoying. We are using 2.0.5 which is the latest V5 Pro.

This gives us an error:

rightMotorA.spinFor(fwd, 1, rev, 100, pct, true);

This does not.

rightMotorA.spinFor(fwd, 1, rev, 100, velocityUnits::pct, true);

The directionType and rotationUnits enumerators don’t require us to add that to the code. Any ideas?

The reason why it works for other units but speed is because there is only one type of deg or fwd but there is multiple types of speed that use pct.
Ex:percentageUnits::pct,voltageUnits::pct,velocityUnits::pct and so on. In C you can not use a keyword that is defined in mutiple types , namespaces,or enumerations that you are referencing without delcaring its type,namespace,or enumeration.

Hopefully that answers your question.

Well, pct is also a percent unit, which I think is why Vexcode has a problem with it. I’ve never had an issue with just typing out velocityUnits::, is there a reason it’s a big deal for your team?

1 Like

For convenience, You also could make your own keyword it will also fix it
Ex of defining a keyword: velocityUnits pctv = velocityUnits::pct;

You can put that before the functions and it will work as well(instead of typing velocityUnits::pct just type pctv)

That’s exactly what pct and fwd are, just global constants, for example.

namespace vex {
    const rotationUnits  degrees       = rotationUnits::deg;
    const rotationUnits  turns         = rotationUnits::rev;
    const percentUnits   percent       = percentUnits::pct;
    const timeUnits      seconds       = timeUnits::sec;
    const distanceUnits  inches        = distanceUnits::in;

etc.

3 Likes

This doesn’t explain why rev works. The value rev is used for reverse and revolutions. One is a directionType and the other is a rotationUnit.