laurensvalk / segway

Code for robots balancing on two wheels, made with various robotics platforms.
MIT License
42 stars 22 forks source link

Not balancing and no remote control #4

Closed cboucher2021 closed 7 years ago

cboucher2021 commented 8 years ago

I have copied and pasted this code with no success. The robot moves very jerkily and I have no control with me remote. What am I doing wrong?

laurensvalk commented 8 years ago

with no success

Actually, if your robot is balancing (even though not so smoothly), that's quite a success, and a good starting point for making it smoother.

I have copied and pasted this code

Have a look through the code and comments as well, and this part especially:

  const float gainGyroAngle                  = 1000, //For every radian (57 degrees) we lean forward,            apply this amount of duty cycle.
              gainGyroRate                   = 40,   //For every radian/s we fall forward,                       apply this amount of duty cycle.
              gainMotorAngle                 = 15,   //For every radian we are ahead of the reference,           apply this amount of duty cycle
              gainMotorAngularSpeed          = 9.6,  //For every radian/s drive faster than the reference value, apply this amount of duty cycle
              gainMotorAngleErrorAccumulated = 3;    //For every radian x s of accumulated motor angle,          apply this amount of duty cycle

These values represent the amount of "compensation power" we provide for deviations from the ideal balance point (0 angle, 0 rate, 0 motor angle, 0 motor speed).

For example, decreasing "gainGyroAngle" should make it respond less aggressively. You can't go too low, however, or it will fall.

This is a process of trial and error. But since your robot is already at least balancing, this should make the remaining process easier.

cboucher2021 commented 8 years ago

Well actually, it doesn't balance. It might stay upright for one second, then it falls. It doesn't act like it the video at all. I have tried to modify the numbers, doesn't seem to change anything...

laurensvalk commented 8 years ago

Ah, wait -- Which RobotC version are you using?

There was going to be an update that changed something to the VEX IQ gyro, and I'd have to check if it's already out.

UPDATE: The change below has already been accounted for in the latest version of the code, so you shouldn't make this change.

This might do the trick. Find the line:

radiansPerSecondPerRawGyroUnit = 1

And replace it with

radiansPerSecondPerRawGyroUnit = 1/64.0
frederik12 commented 8 years ago

Using RobotC 4.54.

I have the same problem as above, even when changing the line u mention.

When the line is changed it seems like the gyro is not reacting properly, cause when tilting the robot different ways, the wheels dont drive opposite to correct the tilt.

laurensvalk commented 8 years ago

Okay. In that case, I'll have to give it a try myself with RobotC 4.54. Hopefully later this week.

laurensvalk commented 8 years ago

@cboucher2021 @frederik12:

Also, what kind of batteries are you using? Is it the rechargeable battery pack that comes with the Super/Starter kits, or the retail version with 6 AA batteries?

frederik12 commented 8 years ago

Thank you very much, the kids is looking forward to driving "their own" segwaybot

Im using the rechargeable battery

laurensvalk commented 8 years ago

It seems to be working here.

To be sure, I also updated everything with the latest VEXos, which appears to be their new firmware update tool.

Could you try that, if you haven't already done so?

laurensvalk commented 8 years ago

I've also updated the Segway code to reflect the necessary change to "radiansPerSecondPerRawGyroUnit", so you won't need to make any changes if you take the latest code.

In summary

cboucher2021 commented 8 years ago

The line change has worked wonders for us. Thanks!

sscole commented 7 years ago

Hi Laurens,

Similar issue here where we copied the code and the behavior is as follows:

Per your note above, we tried to set the "radiansPerSecondPerRawGyroUnit = 1" since the code indicates that it is essentially equal to PI/180 (significantly smaller value than 1). Doesn't help. Any other thoughts?

Thanks Steve

laurensvalk commented 7 years ago

@sscole: You shouldn't need to make any changes to the code if you're using the latest versions of all software involved as listed above.

Please double check all the cables, and ensure that the gyro is mounted on the robot just like in the instructions (check that the gyro sensor and Touch LED weren't accidentally interchanged, placed at the opposite sides of the robot).

Also be sure not to hold the robot too tightly when running the program, as per the instructions given in the code.

Please do not hesitate to ask further questions. But please do so in the new issue thread I just opened.

I will be closing this issue, as the original bug in the code has been resolved. By keeping this thread open, I might be confusing new users who already have the fixed code to start with.