Exemplo n.º 1
0
// Returns the tick value of the right motor
int32_t FPGA_GetRightMotorTicks()
{
	int32_t ticks;
	NiFpga_MergeStatus(&FPGA_Status,NiFpga_ReadI32(FPGA_Session,NiFpga_mainFPGA_IndicatorI32_RPosMotor,&ticks));
	if (NiFpga_IsError(FPGA_Status))
	{
		LOG.ERR("Get Right Motor Ticks Failed.");
	}
	return ticks;
}
Exemplo n.º 2
0
// Returns the tick value on the right wheel
int32_t FPGA_GetRightWheelTicks()
{
	int32_t ticks;
	NiFpga_MergeStatus(&FPGA_Status,NiFpga_ReadI32(FPGA_Session,NiFpga_mainFPGA_IndicatorI32_RPosWheel,&ticks));
	if (NiFpga_IsError(FPGA_Status))
	{
		LOG.ERR("Get Right Wheel Ticks Failed.");
	}
	LOG.DATA("RwT  = %d",ticks);
	return ticks;
}
Exemplo n.º 3
0
void lia_readI32(double control[], int32_t value[])
{
	
	/* Create status, initialize to good */
	NiFpga_Status status = NiFpga_Status_Success;
	
	/* Create a session variable */
	NiFpga_Session session;
	
	/* Load the NiFpga library */
	NiFpga_Initialize();
	
	/* Load bitfile */
	NiFpga_Open(NiFpga_lockin_fpga_Bitfile, NiFpga_lockin_fpga_Signature, "RIO0", NiFpga_OpenAttribute_NoRun,&session);
	
	/* Read value from control */
	NiFpga_ReadI32(session, control[0], value);
	
	/* Close session */
	NiFpga_Close(session,0);
	
	NiFpga_Finalize();
}
Exemplo n.º 4
0
int main()
{
	double desired_angle;
	int32_t desired_tick;
	int32_t Kd = .5 * ACCURACY;
	int32_t Kp = 5 * ACCURACY; 
	int32_t Ki = .0001 * ACCURACY;  
	int32_t error=0xFFFF; 
   /* must be called before any other calls */
   printf("Initializing...\n");
   NiFpga_Status status = NiFpga_Initialize();
   if (NiFpga_IsNotError(status))
   {
      NiFpga_Session session;
      /* opens a session, downloads the bitstream, and runs the FPGA */
      printf("Opening a session...\n");
      NiFpga_MergeStatus(&status, 
			NiFpga_Open(NiFpga_Math_Pid_Bitfile, NiFpga_Math_Pid_Signature,
                     "rio://146.6.84.251/RIO0",
                      NiFpga_OpenAttribute_NoRun,&session));
      if (NiFpga_IsNotError(status))
      {
         /* run the FPGA application */
         printf("Running the FPGA...\n");
         NiFpga_MergeStatus(&status, NiFpga_Run(session, 0));	
/********************************************************************/
			/* Code goes here */
			NiFpga_MergeStatus(&status,
							NiFpga_WriteBool(session,NiFpga_Encoder_Reset,0)); 
			NiFpga_MergeStatus(&status, 
							NiFpga_WriteI32(session,NiFpga_Kd,Kd));
			NiFpga_MergeStatus(&status, 
							NiFpga_WriteI32(session,NiFpga_Kp,Kp));
			NiFpga_MergeStatus(&status, 
							NiFpga_WriteI32(session,NiFpga_Ki,Ki));
			NiFpga_MergeStatus(&status, 
							NiFpga_WriteI32(session,NiFpga_Accuracy,ACCURACY));
			printf("Enter Desired(in degrees): ");
			scanf("%lf",&desired_angle); 
			desired_tick = degree_tick(desired_angle); 
			printf("Desired(in ticks) %d\n", desired_tick);  
			NiFpga_MergeStatus(&status, 
					NiFpga_WriteI32(session,NiFpga_Desired,desired_tick));
			printf("Entering loop\n"); 
			while(error != 0) {
				NiFpga_MergeStatus(&status, 
							NiFpga_ReadI32(session,NiFpga_RealError,&error));   				printf("Error:%d\n", error); 
			}	
/********************************************************************/
			/* Stopping */
			printf("Press <Enter> to stop and quit...");
         getchar(); 
         /* stop the FPGA loops */
         printf("Stopping the FPGA...\n");
	 		/* close the session now that we're done */
         printf("Closing the session...\n");
         NiFpga_MergeStatus(&status, NiFpga_Close(session, 0));
      }
      /* must be called after all other calls */
      printf("Finalizing...\n");
      NiFpga_MergeStatus(&status, NiFpga_Finalize());
   }
   /* check if anything went wrong */
   if (NiFpga_IsError(status))
   {
      printf("Error %d!\n", status);
      printf("Press <Enter> to quit...\n");
      getchar();
   }
   return status;
}
Exemplo n.º 5
0
bool nifpga::ReadI32(uint32_t indicator, int32_t* value) {
	if (sessionOpen) return HandleStatus(NiFpga_ReadI32(sessionHandle, indicator, value));
	return false;
}