Example #1
0
/**
 * Reads the number of steps that the encoder has gone through. The behavior
 * depends on the SignalMode.
 *
 * ENC_QUAD_PHASE:
 * The counter increments when phase A leads phase B and decrements when phase
 * B leads phase A.
 *
 * ENC_SET_AND_DIRECTION:
 * The counter increments when the direction input is low and decrements when
 * the direction input is high.
 *
 * @param[in]  channel  A struct containing the registers on the encoder channel
 *                      to read.
 * @return              The status as a bit field.
 */
uint32_t Encoder_Counter(MyRio_Encoder* channel)
{
     NiFpga_Status status;
     uint32_t counterValue;

    /*
     * Get the value of the counter register.
     *
     * The returned NiFpga_Status value is stored for error checking.
     */
    status = NiFpga_ReadU32(myrio_session, channel->cntr, &counterValue);

    /*
     * Check if there was an error reading from the encoder register.
     *
     * If there was an error then the value of the counter is undefined
     * so print an error message to stdout and return 0.
     */
    MyRio_ReturnValueIfNotSuccess(status, 0,
            "Could not read from the encoder counter register!");

    /*
     * Return the value of the counter.
     */
    return counterValue;
}
Example #2
0
float FPGA_GetCompassHeading(void)
{
	uint32_t current;
	NiFpga_MergeStatus(&FPGA_Status,NiFpga_ReadU32(FPGA_Session,NiFpga_mainFPGA_IndicatorU32_HeadingFloat,&current));
	if(NiFpga_IsError(FPGA_Status))
	{
		LOG.ERR("Get Compass Heading Failed");
	}
	float out;
	out = *((float *)&current);
	LOG.DATA("Compass %f",out);
	return out;
}
Example #3
0
uint32_t FPGA_IsCompassNew(void)
{
	uint32_t current;
	NiFpga_MergeStatus(&FPGA_Status,NiFpga_ReadU32(FPGA_Session,NiFpga_mainFPGA_IndicatorU32_CompassResponseCount,&current));
	if(NiFpga_IsError(FPGA_Status))
	{
		LOG.ERR("Get Compass Counter Failed");
	}
	if(current != FPGA_IsCompassNewPrevious)
	{
		current = FPGA_IsCompassNewPrevious;
		return 1;
	}
	return 0;
}
Example #4
0
uint32_t FPGA_IsGPSNew(void)
{
	uint32_t current;
	NiFpga_MergeStatus(&FPGA_Status,NiFpga_ReadU32(FPGA_Session,NiFpga_mainFPGA_IndicatorU32_GPSPOSCount,&current));
	if(NiFpga_IsError(FPGA_Status))
	{
		LOG.ERR("Get GPS Counter Failed");
	}
	if(current != FPGA_IsGPSNewPrevious)
	{
            FPGA_IsGPSNewPrevious = current;
            return 1;
	}
	return 0;
}
Example #5
0
uint32_t FPGA_GetSonarPing_5() {
	uint32_t value;
	NiFpga_MergeStatus(&FPGA_Status, NiFpga_ReadU32(FPGA_Session, NiFpga_mainFPGA_IndicatorU32_Sonar5PWM, &value)); 
	LOG.DATA("SonarPing 5= %d", value);
	return value;
}
Example #6
0
bool nifpga::ReadU32(uint32_t indicator, uint32_t* value) {
	if (sessionOpen) return HandleStatus(NiFpga_ReadU32(sessionHandle, indicator, value));
	return false;
}