Flywheel velocity control

When attempting to view said code I encountered a “You Need Permission” permissions error.

Not sure why that is. I haven’t placed any permissions on it. Any tips on how to remove the permissions?

it is automatically password protected under your google account, to give permission you need to right click on the flile, then click share

this will bring up a popup window, in the top left corner, press “get shareable link” this will bring up a new popup, copy the link there, press done, then give us that link

Here you go.

Did you manage to get a look at the code? I need that by saturday since that is my competition. I really appreciate all the help.

Explain again what the issue is. I see two source code files, each with a main task. What’s the purpose of each?

(also, which competition are you attending on Saturday ?)

Currently we are competing in the Jordan High School competition but I only need the TBH code that I’ve modified to work with out shooter to be explained to me. I don’t know where to place the motor value that we are trying to keep consistent. I’ve also added driver control and I don’t know how or where to place any of this in the final competiton control.

So I have the TBH running in my robot but the issue is that it will only run at 127 and i can not turn off the flywheel. HELP?!

If you download the program to your robot than your debugger window should come up, from there you can go to global variables. In your global variables there will be you flywheels current speed and target speed, make sure that your flywheel isn’t going a negative while the TBH program is looking for a positive.
If your flywheel is running the wrong direction you will need to switch wires around and mess with it in the motor and sensor setup until you can make it run the right direction. Sorry if this does not help much, it’s just that we had the same problem awhile back and it turned out that our flywheel was running negative.

Hey thanks for the help we will try it tomorrow!

I’ve implemented the RobotC version of the code into my robot my when executing I get a divide by zero exception in the calculate speed task. This specifically occurs when setting motor_velocity in the task. I have no idea why this is as my code is almost exactly the same. Any ideas?

Can you post that bit of code? You might have a problem with time - timeLast evaluating to zero. One solution is to catch that error with an if statement.


void fw_calculateSpeed( fw_controller *fw )
{
    int     delta_ms;
    int     delta_enc;
    
    // Get current encoder value
    fw->e_current = fw_motorEncoderGet();

    // This is just used so we don't need to know how often we are called
    // how many mS since we were last here
    delta_ms   = nSysTime - fw->v_time;
    fw->v_time = nSysTime;

    // Change in encoder count
    delta_enc = (fw->e_current - fw->e_last);

    // save last position
    fw->e_last = fw->e_current;

    // Calculate velocity in rpm
    fw->v_current = (1000.0 / delta_ms) * delta_enc * 60.0 / fw->ticks_per_rev;
}

I’m using a quad encoder as well. I also think it may be a bad encoder, would that affect it? Encoder has been returning values of zero but the exception occurs before any of that.

Okay, then this error has nothing to do with the encoder as the exception occurs, then nothing happens. In the debugger I have to resume processing to even go to driver mode. At that point I have 0 control over the flywheel, I can adjust motor drive values in the debugger but actual setting velocity and adjustments simply don’t work. So exception occurs, control task stops.

The only thing i’d see it being would be delta_ms, how does this result in a zero though? I’m a tad baffled.

Sorry, in my earlier post I realized I was looking at another post thinking it was yours. Let me try seeing if your code gives me an error. I have been using an IME for TBH, so I do not know how much of a help I can be.

EDIT: Are you using the exact code jpearman posted?

Is “fw->ticks_per_rev” set correctly?

Currently, yes.

I just realized I have it set to the turbo motor ticks when I’m using the torque motors. Would that result in the exception?

No, if you are getting a divide by zero error then “something” has to be zero. When the code stops on the exception look at all the variables in the debugger to see which one it is, if it is stopping in fw_calculateSpeed then it’s either delta_ms or ticks_per_rev.

If you don’t have a wait statement anywhere in there, you might be executing the task so quickly that delta_ms evaluates to 0.
Try putting your velocity calculation in an if statement, like this:


if(delta_ms == 0) {
  fw->v_current = 0;
}
else {
  fw->v_current = (1000 / delta_ms) * delta_enc * 60.0 / fw->ticks_per_rev;
}

This will catch the divide by zero error before it occurs and instead of letting it happen, the Cortex will set the velocity to 0. It’s not the best solution, especially if it happens frequently, but it’s better than nothing.
Also, make sure you have a wait statement in the task somewhere. If you don’t, then you a) only release the Cortex CPU when forced to, and b) run code so quickly that delta_ms is 0.
As for the encoder sometimes returning a value of zero, when that happens, does the value change to zero, or is delta_enc zero? If delta_enc is zero, you might be reading the encoder twice before it registers one tick.

Okay, I’ll run through everything when I’m home again, I think it may be that I didn’t define my motor ticks properly and it’d be safe to stick it in an error catch anyways, thanks for the help! Will update when I’ve tried it.

With the encoder, it is simply the encoder always reading 0 and at random times, -1.