PWM Problem with Default Code

This is our fist year modifying the code and I am having a problem. If I take the code that is marked as default for 2007, compile, and download, I am having a problem with PWM1. It seems that the X and Y axis are swapped.

When using 2 joysticks, the x axis activated the red and green output LED’s on the OI but the motor drive and the PWM levels on the Dashboard program are correct. This wasn’t a big deal until I wanted to try 1 joystick mode. Again it seems as if they are swapped, if I push foward or backward the motors go in the opposite direction like its trying to turn, if I push left or right they both go in the same direction.

I thought maybe we had something hooked up wrong so I reloaded the .bin file I pulled off before modifying anything. I am not too familiar with how the PWM’s are generated in the library files, but the code in the user section all seems to be correct.

Thanks,

Kevin

have u tried another controller? is it the one FIRST gave u guys, cuz the ones u get are always crappy. Maybe u have a bad joystick:)

OH!!! i think i noe ur problem!! … wat pwms do u have ur motors set in?? Left should be pwm13 & pwm14 while RIGHT should be pwm15 & pwm16…Now its either that! or u have ur motors set opposite on the victors… what i recommend doing… is hooking 1 motor up at a time on pwm01, and pressing forward on the joystick 1… if it goes forwards … High Five … do the same for the other motor… if it goes backwards… swap the + and - terminals of the wires from the motor on the victor…

i hope i did not confuse u in anyway :stuck_out_tongue:

We had this problem earlier and what we had to do was switch the output wires of one of the drive victors. Once we did this, our drive worked properly.

Please try to respond in a somewhat more grammatically conscience way. It is critical to speak clearly in order to achieve effective communication. If you really don’t know that “know” is not spelled “noe”, okay. At the very least then, start with the capitalization of “I,” then work your way to spelling. I’m not trying to be mean, I just want you all to have good communication skills when you come into the professional world.

If the motors go in reverse, you may want to switch the + and - motor leads on the speed controller.

If that doesn’t fix it, check the speed controller calibration.

Guys, thanks for the responses.

It is the controller that first gave us.

If I leave the code in that came on it from the factory the lights for PWM1 work correctly, red and green at neutral, green full forward, red full reverse. One joystice mode useing PWM 13 or 14 and 15 or 16 work correctly as well.

If I compile the code labeled as FrcCode_2007_8722 or last years code, PWM1 operates correctly, but the lights now map to the X axis, all the way left gives me green and all the way right gives me red. I wasnt worried about this, I actually corrected this with code, but when we tried using 1 joystick with PWM 13 and 15 we saw the same issue as the lights, all the way left seemed to be all the way forward and all the way right seemed to be all the way reverse.

I know the higher PWMs are calculated differently, do the light functions and the higher PWM’s use a similar function call?

just to reiterate, PWM1 operates correctly, regardless of the lights, and the dashboard is correct. 1 joystick mode even shows incorrectly in the dashboard program.

Thanks again,

Kevin

I didnt answer all the questions, sorry, it was 2AM.

Since the unit operates perfectly fine with code that shipped on the controller I dont think any of the items are bad. We have 4 joysticks we used with no luck, the Motor controllers operate as needed with the code that shipped on it so they are connected correctly and calibrated.

Even the PWM LEDs are mapped wrong so it shows that its something internal, and they are correct with the code that shipped on the controller.

I have even tried downloading the default.hex file they give you with the default code and it does the same thing.

Same here, you should check all of your connections just to make sure. WE spent about 30 minutes trying to figure out why we couldnt turn left or right…maybe the PWM cables should be in the right spot…:eek:

The cables are all correct, we have the robot driving fine with the code that shipped on the the RC. Its only when I download a different .hex file where things change, even the one that came with the code, default.hex.

It has to be something internal because the lights on the OI for PWM1 are mapped to the x axis and not the y axis like they should be.

Also, when I open dashboard, the code that shipped on the robot is fine, any new code i can watch the values for PWM13 and PWM15 and as I push the joystick forward they both should climb to 255 and they do not, one goes to 255 and the other goes to 0. If i push right both climb to 255 and if I push left they both climb to 0. This indicates that in the program somewhere the x and y axis are getting swapped. This completely rules out any wiring or calibration issues.

Some of your code is messed up then, you should double check some of your code to see what is wrong. If you posted the drive part of your code maybe(im sure) someone on here can help you.

Its completely unmodified code, I have taken both the hex file they send as well as recompile the unmodified code and I get the same error. If this is supposed to be the default code what am I missing?

I am not very familiar with the code, where is the drive code located? I was searching for what calculates the PWM values but I could not find it. I found a spot that said it was in a library file but I couldnt find that file.

Thanks,

Kevin

Here is the section of source code that is found in file user_routines.c that maps the joystick inputs to the PWMs

/*---------- Analog Inputs (Joysticks) to PWM Outputs-----------------------
*--------------------------------------------------------------------------

  • This maps the joystick axes to specific PWM outputs.
    */
    pwm01 = p1_y;
    pwm02 = p2_y;
    pwm03 = p3_y;
    pwm04 = p4_y;
    pwm05 = p1_x;
    pwm06 = p2_x;
    pwm07 = p3_x;
    pwm08 = p4_x;
    pwm09 = p1_wheel;
    pwm10 = p2_wheel;
    pwm11 = p3_wheel;
    pwm12 = p4_wheel;

/*---------- 1 Joystick Drive ----------------------------------------------
*--------------------------------------------------------------------------

  • This code mixes the Y and X axis on Port 1 to allow one joystick drive.
  • Joystick forward = Robot forward
  • Joystick backward = Robot backward
  • Joystick right = Robot rotates right
  • Joystick left = Robot rotates left
  • Connect the right drive motors to PWM13 and/or PWM14 on the RC.
  • Connect the left drive motors to PWM15 and/or PWM16 on the RC.
    */
    p1_x = 255 - p1_y;
    p1_y = 255 - pwm05;

pwm13 = pwm14 = Limit_Mix(2000 + p1_y + p1_x - 127);
pwm15 = pwm16 = Limit_Mix(2000 + p1_y - p1_x + 127);

Note that if you are using two joystick drive, that pwm01 and pwm02 should be connected to the motor speed controler, but if you want to use 1 joystick drive, the motor speed controlers should be contected to pwm13 and the other to pwm15. You would not have to modify the code one bit.

However, if you want to modify the code to change the way the joysticks control the pwms, then the above section of the source code is the place to do it.

That is exactly where I have been looking and see nothing wrong. I did not modify anything whatsoever, everything there is the default.

There is a new beta relase of the firmware, maybe that will fix my problem, I will be able to try it this afternoon.

Like I said, if I download the .bin file I pulled from the RC when we recieved it, it works fine. This updates both the RC and OI, if I dowload just the .hex file, it only changes the RC. There may be an incompatibility issue, just strange that no one else is seeing it.

kbregler,

Try deleting those two lines from the default code and see if it works:

p1_x = 255 - p1_y;
p1_y = 255 - pwm05;

I have no idea why IFI chose to include them this year, but they make no sense to me and have caused some teams we mentor problems, too.

Let us know if you need further help.

Deleting those 2 lines of code seemed to fix the 1 joystick problem, thanks.

Now I just need to figure out why the PWM1 light is mapped to the x axis

Kevin

The axes were kind of swapped by that code you just deleted (and using pwm05 as a temporary variable, terrible programming practice), so you should have fixed the PWM1 LEDs as well. Could you test it again?