Go to Post MAVERICKS, do ride horses...all while building robots. They also build horses. - Corey Balint [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

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 13-12-2007, 01:54
amateurrobotguy's Avatar
amateurrobotguy amateurrobotguy is offline
Lead Programmer/Senior Engineer
no team
 
Join Date: Feb 2005
Rookie Year: 2000
Location: ****
Posts: 136
amateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these parts
Re: How to manipulate a variable value using an array?

So i have to say that my array of buttons is going to be holding addresses by declaring it like this:
Code:
int (*)joystickbuttons[8] = {&p1_sw_trig, &p1_sw_top, &pl_sw_aux1, &p1_sw_aux2, &p2_sw_trig, &p2_sw_top, &p2_sw_aux1, &p2_sw_aux2};
And thus the * in the declaration indicates that the variable is "special" in that it will indeed be holiding addresses and not just numbers and crap.

And the 2nd half of the above code:
Code:
if ((*)joystickbuttons[arrayindexer[1]] == 1)
Will my above 2 pieces of code work?

I don't get some of your example:

Code:
void idouble(int * input){  Input the address and convert it to the data "input"
   *input += input ; I don't get the use of *input
}

void main(){
    int x ;
    x = 5 ;
    idouble(&x) ;  Call the above function giving it an address as a parameter
    print(x); I don't get how the idouble() returns x
}
__________________
I quit FRC over 2 years ago (more if you're reading this past 2010).

Last edited by amateurrobotguy : 13-12-2007 at 02:11.
  #2   Spotlight this post!  
Unread 13-12-2007, 02:23
Tom Bottiglieri Tom Bottiglieri is offline
Registered User
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Jan 2004
Rookie Year: 2003
Location: San Francisco, CA
Posts: 3,186
Tom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond reputeTom Bottiglieri has a reputation beyond repute
Re: How to manipulate a variable value using an array?

Quote:
Originally Posted by amateurrobotguy View Post

I don't get some of your example:

Code:
void idouble(int * input){  Input the address and convert it to the data "input"
   *input *= 2 ; I don't get the use of *input
}

void main(){
    int x ;
    x = 5 ;
    idouble(&x) ;  Call the above function giving it an address as a parameter
    print(x); I don't get how the idouble() returns x
}
input is a pointer. it holds an address. in this particular case, it holds the address of x. putting a * in front of a pointer means that you want to look at the value held at the address of the pointer. if input = &x, *input = x. so modifying *input will actually be modifying the value held in x. (input is a pointer, so it has no real value attached to it.) By doing this, you can modify variables in your main function without returning ANYTHING from a called function. idouble returns nothing, but because you are telling it where x is in memory and not just the value of x, you can actually change x from another function. Make sense?
  #3   Spotlight this post!  
Unread 13-12-2007, 02:27
amateurrobotguy's Avatar
amateurrobotguy amateurrobotguy is offline
Lead Programmer/Senior Engineer
no team
 
Join Date: Feb 2005
Rookie Year: 2000
Location: ****
Posts: 136
amateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these parts
Re: How to manipulate a variable value using an array?

Oh you sly bastard You are basically bypassing the whole naming system of variables with input and directly puting data to addresses. I like this The int *input is just the declaration of input and not the actual conversion of &x to data....that was the confusing part. I can see why google refers to pointers as "advanced c".

Can you check the code i posted above the above post to tell me if that will work fine?
__________________
I quit FRC over 2 years ago (more if you're reading this past 2010).

Last edited by amateurrobotguy : 13-12-2007 at 02:29.
  #4   Spotlight this post!  
Unread 13-12-2007, 20:13
amateurrobotguy's Avatar
amateurrobotguy amateurrobotguy is offline
Lead Programmer/Senior Engineer
no team
 
Join Date: Feb 2005
Rookie Year: 2000
Location: ****
Posts: 136
amateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these parts
Re: How to manipulate a variable value using an array?

This code isn't working:

int *joystickbuttons[8] = {&p1_sw_trig, &p1_sw_top, &pl_sw_aux1, &p1_sw_aux2, &p2_sw_trig, &p2_sw_top, &p2_sw_aux1, &p2_sw_aux2};

it errors me saying

I:\Robot\2007\MPLAB\Current\2007_2005\user_routine s.c:411:Error [1200] cannot reference the address of a bitfield
I:\Robot\2007\MPLAB\Current\2007_2005\user_routine s.c:411:Error [1200] cannot reference the address of a bitfield
I:\Robot\2007\MPLAB\Current\2007_2005\user_routine s.c:411:Error [1105] symbol 'pl_sw_aux1' has not been defined
I:\Robot\2007\MPLAB\Current\2007_2005\user_routine s.c:411:Error [1101] lvalue required
I:\Robot\2007\MPLAB\Current\2007_2005\user_routine s.c:411:Error [1200] cannot reference the address of a bitfield
I:\Robot\2007\MPLAB\Current\2007_2005\user_routine s.c:411:Error [1200] cannot reference the address of a bitfield
I:\Robot\2007\MPLAB\Current\2007_2005\user_routine s.c:411:Error [1200] cannot reference the address of a bitfield
I:\Robot\2007\MPLAB\Current\2007_2005\user_routine s.c:411:Error [1200] cannot reference the address of a bitfield
I:\Robot\2007\MPLAB\Current\2007_2005\user_routine s.c:411:Error [1200] cannot reference the address of a bitfield
I:\Robot\2007\MPLAB\Current\2007_2005\user_routine s.c:411:Error [1218] extraneous initializer values
__________________
I quit FRC over 2 years ago (more if you're reading this past 2010).
  #5   Spotlight this post!  
Unread 13-12-2007, 20:31
kevin.li.rit's Avatar
kevin.li.rit kevin.li.rit is offline
Imaginary Friend
AKA: Kevin Li
FRC #0596 (SciClones)
Team Role: Student
 
Join Date: Jan 2003
Rookie Year: 2001
Location: Hopkinton, Massachusetts
Posts: 936
kevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond repute
Send a message via Yahoo to kevin.li.rit
Re: How to manipulate a variable value using an array?

Well I see you have a pl instead of a p1
__________________
Kevin Li

596 - Sciclones
1405 - Finney Falcons
2262 - Holliston Panthers
  #6   Spotlight this post!  
Unread 13-12-2007, 20:48
amateurrobotguy's Avatar
amateurrobotguy amateurrobotguy is offline
Lead Programmer/Senior Engineer
no team
 
Join Date: Feb 2005
Rookie Year: 2000
Location: ****
Posts: 136
amateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these parts
Re: How to manipulate a variable value using an array?

I fixed that but it still says

I:\Robot\2007\MPLAB\Current\2007_2005\user_routine s.c:411:Error [1200] cannot reference the address of a bitfield
I:\Robot\2007\MPLAB\Current\2007_2005\user_routine s.c:411:Error [1200] cannot reference the address of a bitfield
I:\Robot\2007\MPLAB\Current\2007_2005\user_routine s.c:411:Error [1200] cannot reference the address of a bitfield
I:\Robot\2007\MPLAB\Current\2007_2005\user_routine s.c:411:Error [1200] cannot reference the address of a bitfield
I:\Robot\2007\MPLAB\Current\2007_2005\user_routine s.c:411:Error [1200] cannot reference the address of a bitfield
I:\Robot\2007\MPLAB\Current\2007_2005\user_routine s.c:411:Error [1200] cannot reference the address of a bitfield
I:\Robot\2007\MPLAB\Current\2007_2005\user_routine s.c:411:Error [1200] cannot reference the address of a bitfield
I:\Robot\2007\MPLAB\Current\2007_2005\user_routine s.c:411:Error [1200] cannot reference the address of a bitfield
__________________
I quit FRC over 2 years ago (more if you're reading this past 2010).
  #7   Spotlight this post!  
Unread 13-12-2007, 21:04
kevin.li.rit's Avatar
kevin.li.rit kevin.li.rit is offline
Imaginary Friend
AKA: Kevin Li
FRC #0596 (SciClones)
Team Role: Student
 
Join Date: Jan 2003
Rookie Year: 2001
Location: Hopkinton, Massachusetts
Posts: 936
kevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond repute
Send a message via Yahoo to kevin.li.rit
Re: How to manipulate a variable value using an array?

not a 100% but I think it may have something to do with the fact that the p1, p2 etc switches are defined to structures. They're defined in the C preprocessor but they were never declared as variables anywhere else(atleast not anywhere I could find)

I'm thinking that you can't do this with those variables...
__________________
Kevin Li

596 - Sciclones
1405 - Finney Falcons
2262 - Holliston Panthers

Last edited by kevin.li.rit : 13-12-2007 at 21:08.
  #8   Spotlight this post!  
Unread 13-12-2007, 21:25
lukevanoort lukevanoort is offline
in between teams
AKA: Luke Van Oort
no team
 
Join Date: Oct 2005
Rookie Year: 2005
Location: Waterloo, ON, Canada
Posts: 1,873
lukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond repute
Send a message via AIM to lukevanoort
Re: How to manipulate a variable value using an array?

The problem is what MPLAB says it is, you cannot reference (aka have a pointer to) a bitfield, relay outputs and, I assume, joystick switch states are stored in bitfields.
__________________
Team 1219: 2009 - Mentor
Team 587: 2005 - Animator, 2006-2008 - Team Captain
  #9   Spotlight this post!  
Unread 13-12-2007, 21:28
amateurrobotguy's Avatar
amateurrobotguy amateurrobotguy is offline
Lead Programmer/Senior Engineer
no team
 
Join Date: Feb 2005
Rookie Year: 2000
Location: ****
Posts: 136
amateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these parts
Re: How to manipulate a variable value using an array?

I know they are defined in ifi_aliases.h with the #define. So how do I get them out of bitfields? Do i need to "redeclare" them as ints?
__________________
I quit FRC over 2 years ago (more if you're reading this past 2010).
  #10   Spotlight this post!  
Unread 13-12-2007, 21:44
lukevanoort lukevanoort is offline
in between teams
AKA: Luke Van Oort
no team
 
Join Date: Oct 2005
Rookie Year: 2005
Location: Waterloo, ON, Canada
Posts: 1,873
lukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond reputelukevanoort has a reputation beyond repute
Send a message via AIM to lukevanoort
Re: How to manipulate a variable value using an array?

When I was trying to write a generalized, modular library for FRC robots (something like WPIlib, but not as high level), I ran into this same issue, but with relay outputs. My solution was to use a structure for storing the values then, at the end of the program loop, call a function that assigned the values in the structure to the actual relays. I think you could do something similar in your case; for example, you could just assign the values of the switches to the various variables in your array at the beginning of every program cycle.
__________________
Team 1219: 2009 - Mentor
Team 587: 2005 - Animator, 2006-2008 - Team Captain
  #11   Spotlight this post!  
Unread 13-12-2007, 22:54
kevin.li.rit's Avatar
kevin.li.rit kevin.li.rit is offline
Imaginary Friend
AKA: Kevin Li
FRC #0596 (SciClones)
Team Role: Student
 
Join Date: Jan 2003
Rookie Year: 2001
Location: Hopkinton, Massachusetts
Posts: 936
kevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond reputekevin.li.rit has a reputation beyond repute
Send a message via Yahoo to kevin.li.rit
Re: How to manipulate a variable value using an array?

Quote:
Originally Posted by amateurrobotguy View Post
I know they are defined in ifi_aliases.h with the #define. So how do I get them out of bitfields? Do i need to "redeclare" them as ints?
I don't think you can redefine them to an INT since it's using a structure.
__________________
Kevin Li

596 - Sciclones
1405 - Finney Falcons
2262 - Holliston Panthers
  #12   Spotlight this post!  
Unread 13-12-2007, 23:29
Phil Mack Phil Mack is offline
Registered User
FRC #0836 (RoboBees)
Team Role: Mentor
 
Join Date: May 2007
Rookie Year: 2007
Location: Maryland
Posts: 30
Phil Mack is a splendid one to beholdPhil Mack is a splendid one to beholdPhil Mack is a splendid one to beholdPhil Mack is a splendid one to beholdPhil Mack is a splendid one to beholdPhil Mack is a splendid one to beholdPhil Mack is a splendid one to behold
Re: How to manipulate a variable value using an array?

Quote:
Originally Posted by amateurrobotguy View Post
cannot reference the address of a bitfield
Each of these names refers to a single bit, not a byte. Because each symbol is referring to a bit and not a byte, an address is insufficient to identify the symbol. The wikipedia article http://en.wikipedia.org/wiki/Bitfield explains the concept very well.

Quote:
Originally Posted by amateurrobotguy
So how do I get them out of bitfields?
You must look to where the bit field is defined, and manipulate the struct. However, that seems somewhat counter to what you are attempting.

~Phil
  #13   Spotlight this post!  
Unread 14-12-2007, 00:17
amateurrobotguy's Avatar
amateurrobotguy amateurrobotguy is offline
Lead Programmer/Senior Engineer
no team
 
Join Date: Feb 2005
Rookie Year: 2000
Location: ****
Posts: 136
amateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these partsamateurrobotguy is infamous around these parts
Re: How to manipulate a variable value using an array?

So much for elegant coding...

But i think lukevanoort's workaround will work, just as long as I put it all in a separate function. My goal with this was just to clean up a billion if-thens into a for loop but i guess a if-then function will make the code easier to read anyways.
__________________
I quit FRC over 2 years ago (more if you're reading this past 2010).

Last edited by amateurrobotguy : 14-12-2007 at 00:23.
Closed Thread


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
turning inputs into outputs Huron Warriors Programming 4 19-04-2007 22:10
How do the Analog Inputs work? JBotAlan Electrical 3 07-01-2005 00:11
How to put Inventor pics on the web Andrew Schuetze Inventor 7 05-01-2005 13:59
How much time do you put into building your robot Wayne Doenges General Forum 16 29-01-2002 19:30
put effort into thread subject Brandon Martus General Forum 12 28-01-2002 19:12


All times are GMT -5. The time now is 00:21.

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