Joystick Button programming

Hi guys,
I have run into a sort of stupid problem. I can’t get the buttons on the joystick to work.


 if (p1_sw_top ==1)
 {
 pwm01=200;
 }
 

Even something simple like that wont work. I tried this also:


 //Somewhere in the top of the file
 int output =0;
 
 //Down in the file
 output = p1_sw_top;
 if (output = 1)
 {
 pwm01=200;
 }
 

Any help/advice?

Is it compiling correctly? Before you start yelling, let me explain… We were programming along over the weekend when things started going crazy on our robot. It took about 30 minutes before I realized that I was getting a compile error, but it was still building the .hex file for me to download even though it should abort. Double check for any error messages when you do your ‘Make All’ just in case.

Other than that, desk check your code and make sure you are actually getting to the the lines you are trying to run. Trust me, I’ve added the greatest routines ever written to some of my software over the years, only to have them not execute because I put them in the wrong place in my code. It’s quite embarrassing when your boss is expecting to see a simulated missile attack show up on the screen and nothing happens!

Hi,
Here is a couple of things to consider.

  1. Try a different joystick to verify that is okay.
  2. Modify the code to do something like this…

if (p1_sw_top == 1)
  pwm01 = 254;
else
  pwm01 = 0;

  1. jdhawg is right on. If the program is not actually building correctly (you don’t see the error messages) and you load, the IFI loader will download the last .hex file that was created…leading you to believe that your new code simply is not working. This has happened to us before.

  2. Try a different port to verify port 1 does not have a problem.

Let us know what you have learned.
Regards,
ChuckB

I have tried different ports, buttons, joysticks… it still doesnt work. I do agree I did not check to see if it builds correctly, but how do I tell? Here is the last output summary when I was building:


 Clean: Deleting intermediary and output files.
 Clean: Deleted file "C:\2005 Programming\frcV24\frc\main.o".
 Clean: Deleted file "C:\2005 Programming\frcV24\frc\user_SerialDrv.o".
 Clean: Deleted file "C:\2005 Programming\frcV24\frc\user_routines.o".
 Clean: Deleted file "C:\2005 Programming\frcV24\frc\user_routines_fast.o".
 Clean: Deleted file "C:\2005 Programming\frcV24\frc\ifi_utilities.o".
 Clean: Deleted file "C:\2005 Programming\frcV24\frc\ifi_startup.o".
 Clean: Deleted file "C:\2005 Programming\frcV24\frc\user_camera.o".
 Clean: Deleted file "FrcCode.cof".
 Clean: Deleted file "FrcCode.cod".
 Clean: Deleted file "FrcCode.hex".
 Clean: Deleted file "FrcCode.lst".
 Clean: Deleted file "C:\2005 Programming\frcV24\frc\FrcCode.mcs".
 Clean: Done.
 Executing: "C:\mcc18\bin\mcc18.exe" -p=18F8520 "main.c" -fo="main.o" /i"C:\mcc18\h" -D_FRC_BOARD -D_USE_CMU_CAMERA -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa- -nw=2066
 Executing: "C:\mcc18\bin\mcc18.exe" -p=18F8520 "user_SerialDrv.c" -fo="user_SerialDrv.o" /i"C:\mcc18\h" -D_FRC_BOARD -D_USE_CMU_CAMERA -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa- -nw=2066
 Executing: "C:\mcc18\bin\mcc18.exe" -p=18F8520 "user_routines.c" -fo="user_routines.o" /i"C:\mcc18\h" -D_FRC_BOARD -D_USE_CMU_CAMERA -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa- -nw=2066
 Executing: "C:\mcc18\bin\mcc18.exe" -p=18F8520 "user_routines_fast.c" -fo="user_routines_fast.o" /i"C:\mcc18\h" -D_FRC_BOARD -D_USE_CMU_CAMERA -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa- -nw=2066
 Executing: "C:\mcc18\bin\mcc18.exe" -p=18F8520 "ifi_utilities.c" -fo="ifi_utilities.o" /i"C:\mcc18\h" -D_FRC_BOARD -D_USE_CMU_CAMERA -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa- -nw=2066
 Executing: "C:\mcc18\bin\mcc18.exe" -p=18F8520 "ifi_startup.c" -fo="ifi_startup.o" /i"C:\mcc18\h" -D_FRC_BOARD -D_USE_CMU_CAMERA -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa- -nw=2066
 Executing: "C:\mcc18\bin\mcc18.exe" -p=18F8520 "user_camera.c" -fo="user_camera.o" /i"C:\mcc18\h" -D_FRC_BOARD -D_USE_CMU_CAMERA -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa- -nw=2066
 Executing: "C:\mcc18\bin\mplink.exe" /l"C:\mcc18\lib" "18f8520user.lkr" "C:\2005 Programming\frcV24\frc\main.o" "C:\2005 Programming\frcV24\frc\user_SerialDrv.o" "C:\2005 Programming\frcV24\frc\user_routines.o" "C:\2005 Programming\frcV24\frc\user_routines_fast.o" "C:\2005 Programming\frcV24\frc\ifi_utilities.o" "C:\2005 Programming\frcV24\frc\ifi_startup.o" "C:\2005 Programming\frcV24\frc\user_camera.o" "C:\2005 Programming\frcV24\frc\FRC_library.lib" /o"FrcCode.cof"
 MPLINK 3.90, Linker
 Copyright (c) 2004 Microchip Technology Inc.
 Errors	: 0
 
 MP2COD 3.90, COFF to COD File Converter
 Copyright (c) 2004 Microchip Technology Inc.
 Errors	: 0
 
 MP2HEX 3.90, COFF to HEX File Converter
 Copyright (c) 2004 Microchip Technology Inc.
 Errors	: 0
 
 Loaded C:\2005 Programming\frcV24\frc\FrcCode.cof
 BUILD SUCCEEDED: Fri Feb 18 09:28:05 2005
 
 

Does that look right? The only custom code I have on there is the brakes, nothing else.

Thanks for all the help you guys are offering,
-Bharat


 if (p1_sw_top ==1)
 {
 pwm01=200;
 }
 

That should work. Make sure nothing else is controlling pwm01 later, and that your motor is actually connected to a Victor on pwm01. If the Victor’s light is flashing, there’s a problem with the pwm cable. You can plug a servo directly onto the pwm pins to make sure the signal is getting out of the RC. Also, use the Dashboard program to make sure the top joystick button is being recognized by the OI.


 //Somewhere in the top of the file
 int output =0;
 
 //Down in the file
 output = p1_sw_top;
 if (output = 1)
 {
 pwm01=200;
 }
 

This will not work the way you intend, because you used a single equals sign in your if statement. That sets output to 1 every time, pwm01 will always be set to 200.

have you tried doing this?

 if (p1_sw_top ==1)
 {
 pwm01=200;
 }
pwm01=200;
 

what i mean is, RIGHT after the button code, you make it go foward anyway.
this way, if there’s anything that would change pwm01’s values, you will know, because the robot will still not move. if it does move, well then move on to another solution.