|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Re: using mplab with vex
Basically, you would use Kevin Watson's FRC code and use that as your project file, since VEX and FRC both use the PIC8717F22 as a base.
Analog inputs (used for analog sensors like a light sensor) are defined as rc_ana_in01, etc. But to get an input from them you need to use the ADC function, so you would do Get_ADC_Result(rc_ana_in01) to get that value. Digital inputs are a lot simpler, and you can simply retrun rc_dig_in01. Digital outputs are rc_dig_out01 etc, but only certain ports can be used as digital outputs. Motors and servos, are controlled by pwm definitions so you would say, pwm01 = 255 for the motor on motor input one to go full forward (255 full forward, 127 neutral, 0 full backward) Transmitters i.e., the joysticks, are defined as PWM_in1 and so on. Your defintions can go up to PWM_in12 since you can use two tranmitters, with the second tranmitter using the range from 7 to 12. The good thing about the joysticks is that they map directly to the motors, so when pwm01 = PWM_in1, if PWM_in1 = 255 (full forward), then you have pwm01 going full forward. The buttons on the back of the VEX transmitter (Channel 5 and 6) are defined using BUTTON_FWD_THRESH as the button on the top, and BUTTON_REV_THRESH as the button on the bottom. if(PWM_in6 > BUTTON_FWD_THRESH) pwm06 = 255; else if (PWM_in6 < BUTTON_REV_THRESH) pwm06= 0; else pwm06=127; The above code says that if the button on the top is pushed the motor goes full forward, if the button on the bottom is pushed, full backward, otherwise stay on neutral. The most important thing about this code is knowing where to place it. ALL teleop code that needs to be executed must be placed in user_routines.c in Proccess_Data_from_Master_uP(). You can obviously make functions in other files in order to modularize your code, but if it's run in teleop mode (with the transmitter) you need to place the function calls in here. Autonomous code is found in user_routines_fast.c and in the if case "if(autonomous_mode)" or something like that. Autonomous code can only be implemented if called in that if case, since this prevents sabotage during the competition. Make sure that if you do write your own functions to handle the robot, like with the transmitter, that you comment out Default_Routine() in Process_Data_from_Master so that you don't have multiple definitions getting passed, and your robot not moving. There is a lot of documentation in Kevin's code, like aliases, so it would be good to read through it, and there is always the documentation on the VEXLabs site. |
|
#2
|
||||
|
||||
|
Re: using mplab with vex
just a quick correction:
DONT comment out Process_Data_from_Master_uP(), as that is where the pwms are updated from. comment out default_routine, and call your own custom functions. |
|
#3
|
|||
|
|||
|
Re: using mplab with vex
right that's what i meant
![]() |
|
#4
|
|||
|
|||
|
Re: using mplab with vex
thanks for all of your help guys. as soon as i get home from school today ill have to try it out. ill let you know how it goes
|
|
#5
|
|||
|
|||
|
Re: using mplab with vex
Another option is to use the WPILib library (EasyC uses it) and MPLab. Do a Google search for WPILib. There is an excellent doc on how to use it and what functions are available.
You can't get quite as low level as you can with the default FRC code, as it insulates you from needing to know some of the low level details, but it is quite usable. I thought the Vex used the 18F8520 like the old 2004/2005 FRC boards? |
|
#6
|
|||
|
|||
|
Re: using mplab with vex
as far as i know, its the same one as the current board, and the same default code runs
|
|
#7
|
||||
|
||||
|
Re: using mplab with vex
The Vex Controller is definately based on the PIC18F8520 not the PIC18F8722 plus some of the aliases are named different for the rxData and txData data structures. The PWM stuff is different as well.
But just use the VEX default code, set the MLABS IDE device to PIC18F8520 and load the 8520 library and linker script and you should be set to go. Some of Kevin's code, particularly the serial stuff has an include for the 8722.h file so this should be changed to 8520.h. Oh, and remember the slow loop is not 26ms is more like 18ms. I have ported over the new structure that Kevin wrote this year to the VEX but I have not been able to get more than 4 PWM's working. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using a VEX Receiver with Non-Vex Equipment | akaria | VEX | 26 | 06-09-2008 00:55 |
| Can't enter Vex autonomous mode when using MPLab | Redneck | Programming | 4 | 23-11-2007 01:16 |
| Encoder Help with VEX and MPLAB | qnetjoe | Programming | 5 | 11-03-2007 21:04 |
| Vex Programming with MPLAB and IF loader | Joohoo | Programming | 3 | 27-07-2006 18:18 |
| using the MPLAB IDE MPLAB SIM simulator | WizardOfAz | Programming | 1 | 03-11-2003 01:24 |