Go to Post Don't let Dean's homework assignment enter into the equation; his homework is about spreading his organization and has nothing to do with you doing what you want to do. - jonathan lall [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 14-02-2013, 16:52
slibert slibert is offline
Software Mentor
AKA: Scott Libert
FRC #2465 (Kauaibots)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2005
Location: Kauai, Hawaii
Posts: 350
slibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud of
Custom Sensor objects and Live Window

We implemented two custom sensor classes so we could utilize some sensors not handled natively by the WPI Library.

In each, we register them with the LiveWindow; our goal is to see the sensor values in the LiveWindow after they have been transformed by our code to real-world values.

Internally, these sensor classes use an AnalogChannel.

We do see the AnalogChannel objects corresponding to our sensors in the Live Window. But we never see the sensor objects in the Live Window, even though we register them.

Attached below is code for one of the sensor classes.

My best guess is because the AnalogChannel objects use the same module/channel as our sensor class does, and the AnalogChannel is registered with LiveWindow first, our sensor class gets ignored for some reason.

If you have any ideas on how to solve this problem, please let me know....

- scott

*******

#include "ProximitySensor.h"
#include "NetworkCommunication/UsageReporting.h"
#include "Timer.h"
#include "WPIErrors.h"
#include "LiveWindow/LiveWindow.h"
#include <time.h>
#include <math.h>
#include "AnalogModule.h"

ProximitySensor:roximitySensor(UINT8 analog_module,UINT32 analog_channel, SensorRange range) :
input(analog_module, analog_channel)
{
this->range = range;
InitProximitySensor();
}

/**
* Initialize the ProximitySensor.
*/
void ProximitySensor::InitProximitySensor()
{
// Be careful not to set the average bits more than once.
UINT32 num_average_bits = 4;
if ( input.GetAverageBits() != num_average_bits )
{
input.SetAverageBits(num_average_bits); // 2^4 = 16-sample average
float sampleRate = 50.0 *
(1 << (num_average_bits));
input.GetModule()->SetSampleRate(sampleRate);
Wait(0.2);
}
LiveWindow::GetInstance()->AddSensor("Proximity", input.GetModuleNumber(), input.GetChannel(), this);
}

/**
* Delete the ProximitySensor.
*/
ProximitySensor::~ProximitySensor()
{
}

/**
* Return the actual distance in millimeters.
*
* @return the current distance in millimeters.
*/

float ProximitySensor::GetDistanceMM( void )
{
float voltage = input.GetAverageVoltage();

// Transform voltage to distance. Exponential values
// were derived from the datasheets:
//
// GP2D120XJ00F (Short Range [30cm]): https://www.sparkfun.com/datasheets/...20XJ00F_SS.pdf
// GP2Y0A21YK (Medium Range [80cm]): http://www.sparkfun.com/datasheets/C...GP2Y0A21YK.pdf
// GP2Y0A02YK0F (Long Range [150cm]): https://www.sparkfun.com/datasheets/...2y0a02yk_e.pdf

float distance_mm;
switch ( range )
{
case kShortRange:

distance_mm = 126.27 * pow(voltage, -1.102);
break;

case kMediumRange:
distance_mm = 267.1 * pow(voltage, -1.23);
break;

case kLongRange:
distance_mm = 0.0; // TODO
break;
}

return distance_mm;
}

/**
* Get the angle in degrees for the PIDSource base object.
*
* @return The angle in degrees.
*/
double ProximitySensor:IDGet()
{
return GetDistanceMM();
}

void ProximitySensor::UpdateTable() {
if (m_table != NULL) {
m_table->PutNumber("Value", GetDistanceMM());
}
}

void ProximitySensor::StartLiveWindowMode() {

}

void ProximitySensor::StopLiveWindowMode() {

}

std::string ProximitySensor::GetSmartDashboardType() {
return "ProximitySensor";
}

void ProximitySensor::InitTable(ITable *subTable) {
m_table = subTable;
UpdateTable();
}

ITable * ProximitySensor::GetTable() {
return m_table;
}
Reply With Quote
  #2   Spotlight this post!  
Unread 14-02-2013, 18:03
RufflesRidge RufflesRidge is offline
Registered User
no team
 
Join Date: Jan 2012
Location: USA
Posts: 989
RufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant futureRufflesRidge has a brilliant future
Re: Custom Sensor objects and Live Window

Quote:
Originally Posted by slibert View Post
std::string ProximitySensor::GetSmartDashboardType() {
return "ProximitySensor";
}
I think this needs to correspond to a known type in the SmartDashboard to work with LiveWindow.

List of types (actual type names I think are all the same -"type"): http://firstforge.wpi.edu/integratio...ystem=exsy1002
Reply With Quote
  #3   Spotlight this post!  
Unread 15-02-2013, 15:47
slibert slibert is offline
Software Mentor
AKA: Scott Libert
FRC #2465 (Kauaibots)
Team Role: Mentor
 
Join Date: Oct 2011
Rookie Year: 2005
Location: Kauai, Hawaii
Posts: 350
slibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud ofslibert has much to be proud of
Re: Custom Sensor objects and Live Window

Thanks, that really helps a lot.
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


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

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