TBH help

So I’m using Jpearman’s TBH code and it doesn’t matter the target velocity I set for the motors, they always end up in 127 and I can’t turn off the flywheel motors with the joystick although I can use my other motors while the flywheel is on.

Im new to RobotC so feel free to make any suggestions
Specs
-Quad encoder on Port 1 geared 1:5 from the Flywheel Axle attached in motors and sensors to port 4 (FlyMaster)
-4 motor single flywheel slaved to port 4 named Flymaster
Also in this lines…

long
FwMotorEncoderGet()
{
    return( FlyEnc );
}

Should I used


return( FlyEnc);

or should I use the next line if motor FlyMaster is attached to the the quad encoder FlyEnc on motors and sensors setup (The Encoder and the motor are not in the same “stage”)


return{nmotorencoder(FlyMaster);

Another question is if how do I start this program on my robot while the robot is plugged to RobotC so I can see the variables and sensors because so far I can view the variables and sensors on the debugger but the flywheel doesn’t move.

You need to configure the FlyMaster motor to use the quad encoder, it’s still using an IME in your code.
You will need to set fw->ticks_per_rev accordingly. If the encoder is not on the motor axle then change to take account of any gearing.
Use nMotorEncoder FlyMaster ] to read the encoder once it is configured properly for the motor. returning FlyEnc from the FwMotorEncoderGet function is only returning the enoder port number, you have to either use nMotorEncoder (after assigning to the correct motor) or SensorValue (in which case you may need to negate it).
Make sure there is no wiring reversal, that is, motors reversed by using red-black wires connections. Reverse motors in the Motor&sensor setup as necessary.
Make sure the encoder increments when given positive command values, if it does not then swap the ports the two encoder wires are connected to so as to reverse direction.

Thanks for the reply @jpearman ,

The encoder axles spins 3 times as fast as the motors so I would have to divide the encoder count by 3.
Where should I make this calculation?

Also, Do I need to plug in both of the Optical Shaft Encoder cables for this program ?
Because one of the cables is broken.

With external 3:1 gearing counts/rev will will three times greater. fw->tick_per_rev will be 1080, remember this is the number of ticks for each revolution of the motor. However, if you have only connected one of the two quad encoder wires then actual ticks/rev will be half that, so 540.

Ok, I tried using the shaft encoder but it isn’t counting progressively up or down
I connected the shaft encoder FlyEnc with motor FlyMaster(in the menu) and used

long
FwMotorEncoderGet()
{
    return( nMotorEncoder[FlyMaster]);
}

but when I checked the debugger and moved the flywheel variable


 flywheel.e_current

changed but was only giving me values of 1 or 2
Then I tried using


return (SensorValue[FlyEnc]);

but the same thing happened with values of -1 and 0

This happens if one of the wires on a 2 wire encoder is not correctly configured. Either broken or unplugged from the correct port.

Thanks Tabor
I fixed the wire and now the encoder is counting and the program is working.

Perfect. So the reasoning 1 wire missing causes this issue, is the program notices the shift between the 4 states
00 01 10 11.
It uses the direction of change from those 4 states to measure direction and distance.
If only 1 wire is connected all the program sees
00 01 00 01 00 01 as you spin at full speed which makes it appear to be “vibrating” in place.