Go to Post As much as you may want the ChiefDelphi community to see your argument, we may not want to see yours. - Amanda Morrison [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 19-01-2009, 15:16
sircedric4's Avatar
sircedric4 sircedric4 is offline
Registered User
AKA: Darren
no team (The SS Prometheus)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2006
Location: Lousiana
Posts: 245
sircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond repute
Angry Potentiometer on cRIO, Programming in Windriver

I am having a problem getting my program to compile because I apparantly do not know the magic hieroglyphs to call the method/function whatever I want from the WPI library. I am a very old school programmer and this object oriented stuff just hurts my head. (I had just got decent enough to program in the old C environment before they threw everything away. I am a mentor so I have to try and understand this stuff before I can help the students)

I want to hook a 10 turn pot to Analog Channel 1 on the Analog Breakout board and then get the value of this pot from my C code. I have set up a new control called TurretPosition, such that:

TurretPosition = new AnalogChannel(1)

Now I want to set a float variable TurretPosDumb equal to the value of the pot. (in the old code it would have been from 0-255, but now I understand it to be -1 to 1) I have tried:

float TurretPosDumb;

TurretPosDumb = TurretPosition->GetVoltage;
TurretPosDumb = TurretPosition.GetVoltage;

and various other scenarios but I keep getting compile errors. I am a native Visual basic programmer and I do not know how to get the magic C symbol to do what I want. (All these ;, ->, . , {} and stuff just seem arbitrary) I have not had C classes, and I am learning by translation from the programming I know and looking at examples in the default codes. They thankfully gave me an example for all my Digital Inputs but I can't find an example for Analog on the cRIO side. (I figured out how to use pots on the Driver Station)

Could someone please give me an example of how to get the value of my pot from the robot. Thank you. (Bare with us old fogeys that are used to just programming in a straight line and having stuff work)
Reply With Quote
  #2   Spotlight this post!  
Unread 19-01-2009, 16:11
Mike Mahar Mike Mahar is offline
Registered User
FRC #0138
 
Join Date: Jan 2007
Location: Amherst, NH
Posts: 64
Mike Mahar will become famous soon enough
Re: Potentiometer on cRIO, Programming in Windriver

I'm typing this in at home so it might have a few typos:

Code:
#include <AnalogChannel.h> // include all the AnalogChannel definitions

AnalogChannel  turretPosition * = new AnalogChannel(1) // declare a pointer to an Analog Channel and allocate a channel

float turretPosDumb;

turretPosDumb = turretPosition->GetVoltage();
The -> style of accessing a function tells the C++ compiler that you are using a pointer.
Reply With Quote
  #3   Spotlight this post!  
Unread 19-01-2009, 23:13
neutrino15's Avatar
neutrino15 neutrino15 is offline
plɹoʍ ollǝɥ
AKA: Jordan Perr
FRC #0694 (Stuypulse)
 
Join Date: Feb 2007
Rookie Year: 2007
Location: New York City
Posts: 162
neutrino15 is just really niceneutrino15 is just really niceneutrino15 is just really niceneutrino15 is just really nice
Re: Potentiometer on cRIO, Programming in Windriver

You are correct, but made a really bad typo.. Declare a pointer like this
Code:
AnalogChannel  *turretPosition = new AnalogChannel(1) // declare a pointer to an Analog Channel and allocate a channel
You wrote that a new variable equals itself times a new analog channel.. Which makes no sense..

The distinction is this, the -> operator accessed a member of an object pointed to by your variable. The dot operator accesses a member of an actual object variable
Code:
ptr_to_object->Drive();
object.Drive();
Nothing in code is arbitrary. You just have to read up on the language.
Reply With Quote
  #4   Spotlight this post!  
Unread 20-01-2009, 06:42
sircedric4's Avatar
sircedric4 sircedric4 is offline
Registered User
AKA: Darren
no team (The SS Prometheus)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2006
Location: Lousiana
Posts: 245
sircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond reputesircedric4 has a reputation beyond repute
Talking Re: Potentiometer on cRIO, Programming in Windriver

Thanks, the last post got it. Coming from an environment that corrects typos and capitalizes variables the right way instead of being case sensitive like the one that VB and VBA uses has just shown me how far the C environments we work with need to come still. Windchill is much better about some of that then MPLab was but it still has a ways to go towards user-friendliness.

Not everyone has a software or electrical expertise and has the time to get smart on a whole new system so it can be very frustrating to try and get stuff that seems so trivial working in this high pressure period. I fought this problem for 2 hours yesterday before breaking down and trying here. Chief Delphi really is a good resource and I don't know how anyone gets anything done without it if they are a limited resource team. Thanks again.

FIRST could have gone a long way towards helping us with the new system by having a default code that included samples and examples of each input and output type like they used to do. The code examples I have seen get the bot to move around but there isn't really anything about the other basic functions most teams use.

Last edited by sircedric4 : 20-01-2009 at 06:45.
Reply With Quote
Reply


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
Running the Motors Backward in WindRiver & cRIO Freezes kyungjin C/C++ 15 08-02-2009 14:24
WindRiver Programming dnrobotics11 C/C++ 4 19-01-2009 19:43
Getting Familiar with Programming in WindRiver kyungjin C/C++ 35 17-01-2009 13:04
CRIO not working with Windriver dpeterson3 C/C++ 7 07-01-2009 20:49
potentiometer programming help Chris1228 Programming 2 09-02-2008 21:30


All times are GMT -5. The time now is 14:08.

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