Go to Post FIRST is hard. It's supposed to be. We can't keep giving people a check and expecting them to succeed. We need to stop this model. It takes a village to raise a child but it takes a community to build a FIRST team. - Andrew Schreiber [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 11-01-2008, 08:24
Tom Line's Avatar
Tom Line Tom Line is offline
Raptors can't turn doorknobs.
FRC #1718 (The Fighting Pi)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 1999
Location: Armada, Michigan
Posts: 2,521
Tom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond reputeTom Line has a reputation beyond repute
Variable Typing

My team wants to subtract 127 from each joystick to change the range from 0 to 255 to -127 to 127. We originally had trouble with this statement:

x_joy_1 = p1_x - 127; // Makes the range -127 to 127
y_joy_1 = p1_y - 127;

p1_x is a defined term from the rcdata. x_joy_1 is an int. I'm not precisely sure why we had trouble - I suspect it's because p1_x is of the wrong type (it's a define, not an int).

Changing it as one of the team members suggested:

int(p1_x) and int(p1_y) resulted in a syntax error.

Our final result was this, which works fine:

x_joy_1 = p1_x;
y_joy_1 = p1_y;

x_joy_1 = x_joy_1 - 127; // Makes the range -127 to 127
y_joy_1 = y_joy_1 - 127;

printf("x_joy_1 is %d\r\n",x_joy_1);
printf("y_joy_1 is %d\r\n",y_joy_1);

Could someone shine some light on why this works the way it does? I'm sick of trial and error with variable int types Isn't there a much more elegant way of coding this?
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
disabled typing Devo1098 Programming 2 22-03-2007 18:43
variable? manodrum Programming 11 01-04-2003 17:20
26 variable limit Gusman1188 Programming 9 12-02-2003 22:38
PBasic Variable Matt Reiland Programming 4 15-01-2002 13:16


All times are GMT -5. The time now is 23:18.

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


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