|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
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) |
|
#2
|
|||
|
|||
|
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(); |
|
#3
|
||||
|
||||
|
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 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(); |
|
#4
|
||||
|
||||
|
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. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |