|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
change pwm range preserve input sensitivity
I am using analog input (pot) from the user console to control a motor speed through a victor speed control. The analog gets converted to PWM_1= 0 to 254. I want my PWM (PWM_2) output to the victor to be 100 to 254. We are controlling ball distance by changing speed of ball shot with victor to a motor. I want input to this to be from the pot and want to presrve the ability to be able to go in reverse a little if the shooter gets jammed. I have come up with a formula for the conversion:
(PWM_1*154/254) + 100 =PWM_2. My questions are 1) will this be excessively taxing on the RC program 2) is this the best way to make full use of the 0 to 5 volt analog input 3) do I need to use the terms PMW_1 and PMW_2 or can I use a term (PMW_1 temp) Thanks in advance, please take it easy on me I am just starting out. Last edited by Superstitions : 07-02-2006 at 21:49. |
|
#2
|
||||
|
||||
|
Re: change pwm range preserve input sensitivity
Well lets start with the basics:
127 is nuetral 127-254 is one direction 0-127 is in another direction so you want the to have a range control between either 0-127 or 127 - 254 (depending on the direction you want to spin) second analog input form the OI (operator interface gets converted into) to one of the these values defined in 'ifi_aliases.h' not PWMs 2) This controller can do floating point trig calculations so I dought this will be taxing in anyway. If fact this is the type of code is quite basic. 3)All the physical variables you can use are defined in ifi_aliases.h. p1_y and so on are the values form the OI ports(joysticks for example). pwms are the this being outputed at the pins. Look at the default_code in the user_routines.c. You can add tons more software variables like the ones you stated. Read:http://ifirobotics.com/docs/legacy/2...2-apr-2004.pdf Quote:
px_y px_x px_wheel are available on the joysticks Read this completely before you start soddering. http://ifirobotics.com/docs/oi-ref-guide-11-21-05.pdf Last edited by 6600gt : 07-02-2006 at 21:15. |
|
#3
|
||||
|
||||
|
Re: change pwm range preserve input sensitivity
Hi, to clarify the output I want, the shooter direction I want is my forward from 127 to 254, I also want to preserve part of the reverse from the 126 down to 100. Hope this helps clarify. I have chosen to use #define p3_aux rxdata.oi_analog15 as the input via the pot on the console. The pot is a stand-alone device on the console not related to the two joysticks
Thanks Jeff Last edited by Superstitions : 07-02-2006 at 21:33. |
|
#4
|
|||||
|
|||||
|
Re: change pwm range preserve input sensitivity
To be more specific, you should range the PWM from about 136 to 232. The Victor has a deadband from 117 to 137, and it reaches 100% output at 232. All detailed at the IFI FAQ:
http://www.ifirobotics.com/forum/viewtopic.php?t=317 EDIT: Strike that, didn't see you still wanted reverse on there. You can range from 100 to 232. Note that you'll get a max of about 20% power in the reverse direction. Last edited by Kevin Sevcik : 07-02-2006 at 21:42. |
|
#5
|
|||||
|
|||||
|
Re: change pwm range preserve input sensitivity
You have exactly the right idea -- multiply by the desired output range, divide by the available input range, and add an offset to get it to start where you want.
I will give you two warnings. First, the OI doesn't really want to see a potentiometer giving it a voltage. It wants to see a variable resistance. You won't necessarily get the full 0-254 range of values in either case, so you might need to tweak your formula slightly to compensate. Second, the compiler is notorious for overflowing intermediate results when you do things like multiplying values that each fit in eight bits. A bit of (int)-casting will force the code to do 16-bit arithmetic, and you should be fine. Code:
pwm02 = (int)p3_aux * 154 / 254 + 100; |
|
#6
|
||||
|
||||
|
Re: change pwm range preserve input sensitivity
Quote:
unsigned char PWM_1; // 0-255 input from joystick unsigned char PWM_2; // 100-255 output to victor unsigned int temp; // temporary storage temp = 39 * (unsigned int)PWM_1; temp >>= 6; // right shift six bits, which is the same as dividing by 64 PWM_2 = (unsigned char)temp + 100; Notice that 39/64 is an approximation of 155/255. -Kevin Last edited by Kevin Watson : 07-02-2006 at 22:36. Reason: icky math |
|
#7
|
||||
|
||||
|
Re: change pwm range preserve input sensitivity
This helped greatly, thanks to all involved, we are off to the test arena.
Thanks, Jeff |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Accelerometer code | ImmortalAres | Programming | 28 | 04-06-2005 01:02 |
| Change joystick to pwm mapping | Joe Lewis | Programming | 3 | 30-03-2005 19:27 |
| Compiling Failed | Teh Mike | Programming | 7 | 09-02-2005 13:27 |
| heres the code. y this not working | omega | Programming | 16 | 31-03-2004 15:18 |
| Some EDURobotics Problems | squide | Robotics Education and Curriculum | 9 | 20-01-2004 10:27 |