Go to Post Stop whining about something that can be fixed by working harder. - artdutra04 [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 20-12-2013, 16:18
RyanShoff RyanShoff is offline
Registered User
FRC #4143 (Mars Wars)
Team Role: Mentor
 
Join Date: Mar 2012
Rookie Year: 2012
Location: Metamora, IL
Posts: 145
RyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to beholdRyanShoff is a splendid one to behold
Analog potentiometer to counter

I'm trying to connect an analog pot to a counter to keep track of how many revolutions the pot has made. There are a just a few examples of this. Can anybody look at this class and see if there are obvious errors? I know AnalogTriggerOutput isn't the most tested code path.

getturns() currently doesn't return anything but zero. I want it to increase on a clockwise revolution and decrease on a counterclockwise revolution.

Code:
#include "AnalogChannelVolt.h"
#include <math.h>

static const float rev = 5.0;
static const float halfrev = rev/2;
static const float scale = rev/(4.8-.2);
static const int   ratio = 2; // ratio of pot to finished gear, must be int

#define INV



AnalogChannelVolt::AnalogChannelVolt(UINT8 modulenumber, UINT32 channel)
  : AnalogChannel(modulenumber, channel)
{
    m_trig = new AnalogTrigger(modulenumber, channel);
    m_trig->SetFiltered(true);
    m_trig->SetLimitsVoltage(0.5,4.5);

    m_count = new Counter();
    m_count->SetUpDownCounterMode();
    m_count->SetUpSource(m_trig, AnalogTriggerOutput::kRisingPulse);
    m_count->SetDownSource(m_trig, AnalogTriggerOutput::kFallingPulse);
    m_count->SetUpSourceEdge(true,false);
    m_count->SetDownSourceEdge(true,false);

    m_count->Reset();
    m_count->Start();
}

float AnalogChannelVolt::GetAverageVoltage()
{
    return GetVoltage();
}

void AnalogChannelVolt::ResetTurns()
{
    m_count->Stop();
    m_count->Reset();
    m_count->Start();
}

float AnalogChannelVolt::GetVoltage()
{
  float temp = AnalogChannel::GetVoltage();
  temp = (((temp - halfrev) * scale) + halfrev);  // scale
  if(temp < 0) temp = 0; // min
  if(temp > rev) temp = rev; // max
  temp = (temp / ratio) + ((m_count->Get() % ratio) * halfrev); // half scale
#ifdef INV
  temp = rev - temp; // inverse
#endif
  return temp;
}

int AnalogChannelVolt::getturns()
{
    return m_count->Get();
}
double AnalogChannelVolt::PIDGet()
{
  return GetVoltage();
}

AnalogChannelVolt::~AnalogChannelVolt()
{
  delete m_trig;
  delete m_count;
}
Ryan Shoff
4143
Reply With Quote
 


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


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

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