![]() |
Limiting PWM in pbasic
Posted by Alan Federman at 2/11/2001 9:59 AM EST
Engineer on team #255, Odyssey, from Foothill HS, San Jose and NASA. Which is the best way to limit the maximum amount of power to a PWM driven motor? is it: pwm1 = (pwm1 - 127) * .25 + 127 or pwm1 = (pwm1 MAX 160 MIN 94) |
Re: Limiting PWM in pbasic
Posted by Matt Leese at 2/11/2001 1:59 PM EST
Other on team #73, Tigerbolt, from Edison Technical HS and Alstom & Fiber Technologies & RIT. In Reply to: Limiting PWM in pbasic Posted by Alan Federman on 2/11/2001 9:59 AM EST: Well, you need to remember that PBasic doesn't support floating point numbers. It only does integer math so multiplying times .25 (if it even compiles) won't ever do what you want. Dividing by 4 (or better yet, right shifting two places) will work. This however just scales down the output value. By using a MAX and MIN you put a fixed limit and the slope of the input is the same. When you scale down you change the slope of the data. When scaling, be careful with being greater than 127 or less than 127 as PBasic also doesn't support negative numbers so that will definatley give you bad data. So for stricked limiting of values MAX and MIN is better but if you want to slow down the robot totally, scaling works better. Matt |
Re: Limiting PWM in pbasic
Posted by Mark Pierce at 2/13/2001 12:59 PM EST
Other on team #288, RoboDAWGS, from Grandville High School and X-Rite, Delphi, and others. In Reply to: Limiting PWM in pbasic Posted by Alan Federman on 2/11/2001 9:59 AM EST: Another way to limit PWMs, especially if you are driving it from a joystick or analog input is to use a look up table. Build a table of values that has the desired shape and range of values. This also eliminates the need for deadband handling code and can be adjusted to give the operators more natural control. See Steve's page: http://sharingfirst.mit.edu/users/st...%20Control.htm |
That seems a bit complicated.
Posted by Joe at 2/14/2001 9:10 PM EST
Student on team #506 from St. Anthony's HS. In Reply to: Re: Limiting PWM in pbasic Posted by Mark Pierce on 2/13/2001 12:59 PM EST: : Another way to limit PWMs, especially if you are driving it from a joystick or analog input is to use a look up table. Build a table of values that has the desired shape and range of values. This also eliminates the need for deadband handling code and can be adjusted to give the operators more natural control. See Steve's page: : http://sharingfirst.mit.edu/users/st...%20Control.htm After sitting looking at the code for about 45 I decided to come here looking for answeres. I saw your post and investigated. It looks to me like you know what your doing well beyond my teams comprehension (were a rookie team with no programming experience). I decided to combine the ideas listed in a previous post (the one you responded to i think) with the tank drive system. Hopefully this will alow the tank drive to run at a slower, scaled speed. Please tell me if this works and if it has similar effects to what your program did. PWM1 = (((((2000 + p1_y - p1_x + 127) Min 2000 Max 2254) - 2000) - 127) / 2 + 127) PWM2 = (((((2000 + p1_y + p1_x - 127) Min 2000 Max 2254) - 2000) - 127) / 2 + 127) notice the adition of the -127) / 2 + 127) at the end of both lines. This is untested and i'll be trying it out tomorrow. If anyone sees a problem or an even easier way please let me know. also: if this works the degree of the scale can be adjusted by simply changing the / 2 to another number. |
Re: That seems a bit complicated.
Posted by Mark Pierce at 2/15/2001 10:14 PM EST
Other on team #288, RoboDAWGS, from Grandville High School and X-Rite, Delphi, and others. In Reply to: That seems a bit complicated. Posted by Joe on 2/14/2001 9:10 PM EST: What you have should work, be careful about changing the 2 and 127 to ensure that rounding errors don't cause over flow (this is a whole number only processor). In my first post I was thinking about limiting PWMs used to drive devices other than the drive. We always want to have our drive motors to have max. speed available and reduce speed with gearing. I wasn't thinking about tank drive, but a look up table can be used to simplify this as well. As an attempt at explaining: First, build a table with 128 - 0 values, followed by 256 values that range from 0 to 254, followed by 128 - 254 values: PWMTBL Data 000, 000, 000, 000, 000, 000, 000, 000 ' 0 (repeat the above line 15 times) Data 000, 001, 002, 003, 004, 005, 006, 007 ' 128 Data 008, 009, 010, 011, 012, 013, 014, 015 ' 136 Data 016, 017, 018, 019, 020, 021, 022, 023 ' 144 Data 024, 025, 026, 027, 028, 029, 030, 031 ' 152 Data 032, 033, 034, 035, 036, 037, 038, 039 ' 160 Data 040, 041, 042, 043, 044, 045, 046, 047 ' 168 Data 048, 049, 050, 051, 052, 053, 054, 055 ' 176 Data 056, 057, 058, 059, 060, 061, 062, 063 ' 184 Data 064, 065, 066, 067, 068, 069, 070, 071 ' 192 Data 072, 073, 074, 075, 076, 077, 078, 079 ' 200 Data 080, 081, 082, 083, 084, 085, 086, 087 ' 208 Data 088, 089, 090, 091, 092, 093, 094, 095 ' 216 Data 096, 097, 098, 099, 100, 101, 102, 103 ' 224 Data 104, 105, 106, 107, 108, 109, 110, 111 ' 232 Data 112, 113, 114, 115, 116, 117, 118, 119 ' 240 Data 120, 121, 122, 123, 124, 125, 126, 127 ' 248 Data 127, 128, 129, 130, 131, 132, 133, 134 ' 256 Data 135, 136, 137, 138, 139, 140, 141, 142 ' 264 Data 143, 144, 145, 146, 147, 148, 149, 150 ' 272 Data 151, 152, 153, 154, 155, 156, 157, 158 ' 280 Data 159, 160, 161, 162, 163, 164, 165, 166 ' 288 Data 167, 168, 169, 170, 171, 172, 173, 174 ' 296 Data 175, 176, 177, 178, 179, 180, 181, 182 ' 304 Data 183, 184, 185, 186, 187, 188, 189, 190 ' 312 Data 191, 192, 193, 194, 195, 196, 197, 198 ' 320 Data 199, 200, 201, 202, 203, 204, 205, 206 ' 328 Data 207, 208, 209, 210, 211, 212, 213, 214 ' 336 Data 215, 216, 217, 218, 219, 220, 221, 222 ' 344 Data 223, 224, 225, 226, 227, 228, 229, 230 ' 352 Data 231, 232, 233, 234, 235, 236, 237, 238 ' 360 Data 239, 240, 241, 242, 243, 244, 245, 246 ' 368 Data 247, 248, 249, 250, 251, 252, 253, 254 ' 376 Data 254, 254, 254, 254, 254, 254, 254, 254 ' 384 (repeat the last line 15 times) Then your equations can be re-written as follows: READ 256+p1_y-p1_x,PWM1 READ p1_y+p1_x,PWM2 To adjust the scale, change the zeros and 254s to some other numbers centered on 127 and scale the middle numbers accordingly. We use a spreadsheet to calculate these, but doing it by hand isn't difficult either. Good Luck, Mark |
| All times are GMT -5. The time now is 04:39. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi