Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   potentiometer/ analog inputs (http://www.chiefdelphi.com/forums/showthread.php?t=82971)

whatabouteve 18-02-2010 08:29

potentiometer/ analog inputs
 
We are having trouble getting our potentiometer code to work.

we declare it
AnalogInput *potemtiometer;


later
potentiometer = new AnalogInput(2);

and we can't figure out the last part. We don't have anything to go off of because last year was an easy 1,2,3 robot.

Zme 18-02-2010 09:04

Re: potentiometer/ analog inputs
 
try using AnalogChannel instead of input

whatabouteve 18-02-2010 09:54

Re: potentiometer/ analog inputs
 
okay we'll try that.

whatabouteve 18-02-2010 15:58

Re: potentiometer/ analog inputs
 
attempting analog channel didn't work when we added

float anglesh = pot1.GetVoltage();

Racer26 18-02-2010 16:49

Re: potentiometer/ analog inputs
 
shouldn't it be pot1->GetVoltage();?

whatabouteve 18-02-2010 18:41

Re: potentiometer/ analog inputs
 
i'm trying to make the code right and it compiles but we'll see if i get something.

i haven't actually had a potentiometer until now.

Zme 18-02-2010 22:40

Re: potentiometer/ analog inputs
 
1075guy is right, because you declared it using a pointer you must use -> instead of .

byteit101 19-02-2010 15:06

Re: potentiometer/ analog inputs
 
use pot1->GetValue() for a 0-1023 range value, pot1->GetVoltage() for 0.0-5.0 range. Try both and see which one you like better

whatabouteve 20-02-2010 21:40

Re: potentiometer/ analog inputs
 
i try printing the values to the screen and i get really big values sometimes. Why would this be? is it because i might run the loops they are in too quuickly. i set them to .02 seconds and i think its doing better.

I actually disabled the watchdog for the autonomous because it won't run through long waits in the system. this worked until just now when it started giving me watchdog not fed errors that have never happened before.

Alan Anderson 21-02-2010 00:45

Re: potentiometer/ analog inputs
 
Quote:

Originally Posted by whatabouteve (Post 924919)
i try printing the values to the screen and i get really big values sometimes. Why would this be?

Perhaps there's a digit or two left over on the screen from a previous print step? For example, if one value is 1003 and the next one is 996, it might end up on screen looking like 9963 if you aren't careful.

whatabouteve 21-02-2010 09:11

Re: potentiometer/ analog inputs
 
this could be i will try to fix this.
would printing

printf(" =angletop");
printf("%d",angletop);

would this work in the correct format assuming it prints on line 1 and the %d writes over it?

byteit101 21-02-2010 09:27

Re: potentiometer/ analog inputs
 
Quote:

Originally Posted by whatabouteve (Post 925184)
this could be i will try to fix this.
would printing

printf(" =angletop");
printf("%d",angletop);

would this work in the correct format assuming it prints on line 1 and the %d writes over it?

no, this will output something like this:
Code:

        =angletop23        =angletop85        =angletop712        =angletop465        =angletop84        =angletop6        =angletop4586        =angletop589        =angletop486
i would recommend one printf a loop (if possible): printf("angletop=%d\r\n",angletop);

whatabouteve 21-02-2010 09:32

Re: potentiometer/ analog inputs
 
we only need the number to print when autonomous is done. basically we have a 5 second waiting period where we find the values.

right now i just found out that the pot is mounted so up is down and down is up. so i'll need to get someone to remount it.

mikets 22-02-2010 18:23

Re: potentiometer/ analog inputs
 
Or you can correct it in software.
Code:

angletop = max - angletop;


All times are GMT -5. The time now is 12:24.

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