OCCRA [more] FRC Kickoff : 25d 01h 23m ...
Last year we saved a ton of money by using a good bit of square tubing for the frame of our robot, square tubing is a lot cheaper then C channel. We get to use so much raw material that the cost should go down in certain places. - Derrick Maust [more]
 Chief Delphi Program for variable speed
 User Name Remember Me? Password
 CD-Events CD-Media CD-Spy FRC-Spy
The Chief Delphi Forums are sponsored by Innovation First International, Inc.
ADVERTISEMENT

#1
01-12-2005, 03:17 AM
 cabbagekid2 Registered User #0368 (Kika Mana) Join Date: Jun 2001 Rookie Year: 2000 Location: Honolulu, HI Posts: 85
Program for variable speed

For our previous robots, we've been implementing variable speed for the drive motors by using the wheel on the player one joystick. Since we took a break from FIRST last year, we did not have a chance to convert our pbasic code for the variable speed to C. When we tried, the "robot" (platform with wheels) did not follow the code at all. What happened was when p1_y became greater than 147, p1_y, pwm13, pwm 15, and p1_x all became 127 no matter where the joystick was positioned. The same happened when p1_y became less than 107. Is the algorithm to calculated the new p1_y too complex?

Could someone look at our interpretation of the code and help us find our problem? Any help would be much appreciated, thanks!

Previous PBasic Code:

minfwd con c127+5
minbak con c127-5
c2k con 2000
c2kc254 con c2k+c254

XYAdjust:
Gosub WAdj_y
Gosub WAdj_x
return

WAdj_y:
if p1_y => minfwd then yForward
if p1_y <= minbak then yReverse

p1_y=c127 'yNeutral
return

yForward:
p1_y = (p1_wheel)*(p1_y-c127)/c254+c127 max c254
return

yReverse:
p1_y = c127-((p1_wheel)*(c127-p1_y)/c254)
return

WAdj_x:
if p1_x => minfwd then xForward
if p1_x <= minbak then xReverse

p1_x=c127 'yNeutral
return

xForward:
p1_x = (p1_wheel)*(p1_x-c127)/c254+c127 max c254
return

xReverse:
p1_x = c127-((p1_wheel)*(c127-p1_x)/c254)
return

PWM15 = (c2k + p1_y - p1_x + 127) Min c2k Max c2kc254 - c2k
PWM13 = (c2k + p1_y + p1_x - 127) Min c2k Max c2kc254 - c2k

C Code placed in user_routines.c:

unsigned char direction = 0;
unsigned char p1_top_last = 0;

if (p1_y >= 147)
p1_y = ((p1_wheel)*(p1_y - 127)/254) + 127;
else if (p1_y <= 107)
p1_y = 127 - ((p1_wheel)*(127 - p1_y)/254);
else p1_y = 127;

if (p1_x >= 147)
p1_x = ((p1_wheel)*(p1_x - 127)/254) + 127;
else if (p1_x <= 107)
p1_x = 127 - ((p1_wheel)*(127 - p1_x)/254);
else p1_x = 127;

pwm13 =Limit_Mix(2000 + p1_y + p1_x - 127);
pwm15 = Limit_Mix(2000 + p1_y - p1_x + 127);
#2
01-12-2005, 11:47 AM
 Alan Anderson Software Architect FRC #0045 (TechnoKats) Team Role: Mentor Join Date: Feb 2004 Rookie Year: 2004 Location: Kokomo, Indiana Posts: 7,169
Re: Program for variable speed

Quote:
 Originally Posted by cabbagekid2 if (p1_y >= 147) p1_y = ((p1_wheel)*(p1_y - 127)/254) + 127;
This is using integer arithmetic. The division by 254 gives an intermediate result of zero, so the final answer is always 127.

You need to either a) force floating point arithmetic by dividing by 254.0, or b) scale the intermediate calculations up by multiplying by a constant (e.g. 256) first and dividing by the same constant just before adding the 127.
#3
01-12-2005, 12:46 PM
 doy #1208 Ex-Lead Programmer AKA: Jesse Luehrs #1208 (The Super Critical Axe Men) Team Role: Alumni Join Date: Jan 2004 Location: O'Fallon, IL Posts: 27
Re: Program for variable speed

and for what its worth, sticking with integer division is almost always the best choice... floating point division on this processor is surprisingly slow, having no fpu.
#4
01-12-2005, 01:15 PM
 Matt Leese Been-In-FIRST-Too-Long FRC #1438 (The Aztechs) Team Role: Engineer Join Date: May 2001 Rookie Year: 1998 Location: Long Beach, CA Posts: 937
Re: Program for variable speed

Quote:
 Originally Posted by Alan Anderson This is using integer arithmetic. The division by 254 gives an intermediate result of zero, so the final answer is always 127. You need to either a) force floating point arithmetic by dividing by 254.0, or b) scale the intermediate calculations up by multiplying by a constant (e.g. 256) first and dividing by the same constant just before adding the 127.
The multiplication by p1_wheel should happen first by order of operations (left-to-right). You could try adding parenthesis around the (p1_wheel)*(p1_y - 127) part and that may fix it. My other thought is that you may be doing 8-bit arithmetic and not 16-bit arithmetic. You might want to move p1_y and p1_wheel into int's first so that it's guaranteed to be 16-bit arithmetic and not 8-bit.

Matt
#5
01-12-2005, 01:17 PM
 cabbagekid2 Registered User #0368 (Kika Mana) Join Date: Jun 2001 Rookie Year: 2000 Location: Honolulu, HI Posts: 85
Re: Program for variable speed

Quote:
 Originally Posted by Alan Anderson This is using integer arithmetic. The division by 254 gives an intermediate result of zero, so the final answer is always 127. You need to either a) force floating point arithmetic by dividing by 254.0, or b) scale the intermediate calculations up by multiplying by a constant (e.g. 256) first and dividing by the same constant just before adding the 127.

So would this be the same if I just added parenthesis and changed the formula to this:

if (p1_y >= 147)
p1_y = ((p1_wheel*(p1_y - 127))/254) + 127;

or is this what you were trying to say?

if (p1_y >= 147)
p1_y = ((p1_wheel*(p1_y - 127)*254)/(254*254)) + 127;

Thanks, I shall try these out!
#6
01-12-2005, 01:20 PM
 cabbagekid2 Registered User #0368 (Kika Mana) Join Date: Jun 2001 Rookie Year: 2000 Location: Honolulu, HI Posts: 85
Re: Program for variable speed

Quote:
 Originally Posted by Matt Leese The multiplication by p1_wheel should happen first by order of operations (left-to-right). You could try adding parenthesis around the (p1_wheel)*(p1_y - 127) part and that may fix it. My other thought is that you may be doing 8-bit arithmetic and not 16-bit arithmetic. You might want to move p1_y and p1_wheel into int's first so that it's guaranteed to be 16-bit arithmetic and not 8-bit. Matt

That was one of our thoughts about the problem....that it was doing the calculation and somehow losing the number. We didn't know how to solve this problem though. Thanks for the suggestion. We'll try creating new 16-bit variables and try this again.

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts vB code is On Smilies are On [IMG] code is On HTML code is Off
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     User Announcements FIRST     General Forum         FIRST E-Mail Blast Archive     Rumor Mill     Career     Robot Showcase     Moderated Discussion Technical     Technical Discussion     Robotics Education and Curriculum     Motors     Electrical         CAN     Programming         NI LabVIEW         WindRiver C++         Java         MATLAB & Simulink         Python     intelitek easyC/REC information         easyC v2 for Vex         easyC for FRC         REC/Learnmate         WPILib         easyC PRO     Control System         IFI Control System         FRC Control System         Sensors         USB Chicklet     Pneumatics     Kit & Additional Hardware     CAD         Inventor         SolidWorks         Pro ENGINEER / Creo     IT / Communications         3D Animation and Competition         Website Design/Showcase         Videography and Photography         Computer Graphics     National Instruments LabVIEW and Data Acquisition         LabView and Data Acquisition Competition     Awards         Chairman's Award     Rules/Strategy         Scouting         You Make The Call     Team Organization         Fundraising         Starting New Teams         Finding A Team         College Teams     Championship Event     Regional Competitions     FIRST in Michigan     Mid-Atlantic Robotics     Off-Season Events         Chief Delphi Invitational     Thanks and/or Congrats     FRC Game Design     OCCRA         OCCRA Q&A         OCCRA Programming Other     Unsung FIRST Heroes     Chit-Chat         Games/Trivia             Fantasy FIRST     Car Nack's Corner     College & University Education     Dean Kamen's Inventions     FIRST-related Organizations         Western Region Robotics Forum         Robot Chicks Union (RCU)         Southern California Regional Robotics Forum         FIRST Interactive Rural SupporT         FIRST Scouting Network         The Grand FIRST Team         FloridaFIRST         FIRSTwiki         Ultimate Robot Challenge         Team San Diego         Dream FIRST         The Blue Alliance             Video Archives     FIRST Historians     FIRST-A-Holic's Anonymous Mailbox     FIRST In the News...     FIRST Lego League         Lego Mindstorm Discussion     FIRST Tech Challenge     VEX         VEX Robotics Competition         VEX IQ     Televised Robotics     Math and Science         NASA Discussion ChiefDelphi.com Website     CD Forum Support     Extra Discussion Old Forum Archives     1999     2000     2001

 Similar Threads Thread Thread Starter Forum Replies Last Post initialization program and speed controllers rosebud Programming 15 10-05-2004 03:35 AM PID control loops - closed loop feedback KenWittlief Technical Discussion 56 04-26-2004 09:27 PM how to add steps in the provided encoder program for the edu Zaramel2002 Programming 3 02-11-2004 08:35 AM Fried program slots? Jeff Waegelin Programming 18 03-19-2003 06:08 PM Ahh! Program trick confusing! archiver 2001 9 06-24-2002 02:26 AM

All times are GMT -5. The time now is 10:36 PM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.

 -- English (12 hour) -- English (24 hour) Contact Us - Chief Delphi - Rules - Archive - Top

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi