本文整理汇总了C++中MatrixXf::setZero方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixXf::setZero方法的具体用法?C++ MatrixXf::setZero怎么用?C++ MatrixXf::setZero使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatrixXf
的用法示例。
在下文中一共展示了MatrixXf::setZero方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReferenceTrajectory
LQRControler::LQRControler() {
trajectory=new ReferenceTrajectory();
Ke=Gain(4);
deltaxsiant.setZero();
xsiant.setZero();
ts=0.012;
}
示例2: init_opencv_fcns
void init_opencv_fcns()
{
cout << "Initializing OpenCV Module" << endl;
img_dbg.setTo(white);
pt_img_temp.setZero();
cout << "Completed Initializing OpenCV Module"<<endl<<endl;
}
示例3: getSampleMatrixValue
bool GUSBAmpDriver::getSampleMatrixValue(MatrixXf& sampleMatrix)
{
sampleMatrix.setZero(); // Clear matrix - set all elements to zero
return true;
}
示例4: getSampleMatrixValue
bool TMSIDriver::getSampleMatrixValue(MatrixXf& sampleMatrix)
{
//Check if the driver DLL was loaded
if(!m_bDllLoaded)
return false;
//Check if device was initialised and connected correctly
if(!m_bInitDeviceSuccess)
{
cout << "Plugin TMSI - ERROR - getSampleMatrixValue() - Cannot start to get samples from device because device was not initialised correctly" << endl;
return false;
}
sampleMatrix.setZero(); // Clear matrix - set all elements to zero
uint iSamplesWrittenToMatrix = 0;
int channelMax = 0;
int sampleMax = 0;
int sampleIterator = 0;
//get samples from device until the complete matrix is filled, i.e. the samples per block size is met
while(iSamplesWrittenToMatrix < m_uiSamplesPerBlock)
{
//Get sample block from device
LONG ulSizeSamples = m_oFpGetSamples(m_HandleMaster, (PULONG)m_lSignalBuffer, m_lSignalBufferSize);
LONG ulNumSamplesReceived = ulSizeSamples/(m_uiNumberOfAvailableChannels*4);
//Only do the next steps if there was at least one sample received, otherwise skip and wait until at least one sample was received
if(ulNumSamplesReceived > 0)
{
int actualSamplesWritten = 0; //Holds the number of samples which are actually written to the matrix in this while procedure
//Write the received samples to an extra buffer, so that they are not getting lost if too many samples were received. These are then written to the next matrix (block)
for(int i=0; i<ulNumSamplesReceived; i++)
{
for(uint j=i*m_uiNumberOfAvailableChannels; j<(i*m_uiNumberOfAvailableChannels)+m_uiNumberOfChannels; j++)
m_vSampleBlockBuffer.push_back((double)m_lSignalBuffer[j]);
}
//If the number of available channels is smaller than the number defined by the user -> set the channelMax to the smaller number
if(m_uiNumberOfAvailableChannels < m_uiNumberOfChannels)
channelMax = m_uiNumberOfAvailableChannels;
else
channelMax = m_uiNumberOfChannels;
//If the number of the samples which were already written to the matrix plus the last received number of samples is larger then the defined block size
//-> only fill until the matrix is completeley filled with samples. The other (unused) samples are still stored in the vector buffer m_vSampleBlockBuffer and will be used in the next matrix which is to be sent to the circular buffer
if(iSamplesWrittenToMatrix + ulNumSamplesReceived > m_uiSamplesPerBlock)
sampleMax = m_uiSamplesPerBlock - iSamplesWrittenToMatrix + sampleIterator;
else
sampleMax = ulNumSamplesReceived + sampleIterator;
//Read the needed number of samples from the vector buffer to store them in the matrix
for(; sampleIterator < sampleMax; sampleIterator++)
{
for(int channelIterator = 0; channelIterator < channelMax; channelIterator++)
{
sampleMatrix(channelIterator, sampleIterator) = ((m_vSampleBlockBuffer.first() * (m_bUseUnitGain ? m_vUnitGain[channelIterator] : 1)) + (m_bUseUnitOffset ? m_vUnitOffSet[channelIterator] : 0)) * (m_bUseChExponent ? pow(10., (double)m_vExponentChannel[channelIterator]) : 1);
m_vSampleBlockBuffer.pop_front();
}
actualSamplesWritten ++;
}
iSamplesWrittenToMatrix = iSamplesWrittenToMatrix + actualSamplesWritten;
}
if(m_outputFileStream.is_open() && m_bWriteDriverDebugToFile)
{
m_outputFileStream << "samples in buffer: " << m_vSampleBlockBuffer.size()/m_uiNumberOfChannels << endl;
m_outputFileStream << "ulSizeSamples: " << ulSizeSamples << endl;
m_outputFileStream << "ulNumSamplesReceived: " << ulNumSamplesReceived << endl;
m_outputFileStream << "sampleMax: " << sampleMax << endl;
m_outputFileStream << "sampleIterator: " << sampleIterator << endl;
m_outputFileStream << "iSamplesWrittenToMatrix: " << iSamplesWrittenToMatrix << endl << endl;
}
}
if(/*m_outputFileStream.is_open() &&*/ m_bWriteDriverDebugToFile)
{
//Get device buffer info
ULONG ulOverflow;
ULONG ulPercentFull;
m_oFpGetBufferInfo(m_HandleMaster, &ulOverflow, &ulPercentFull);
m_outputFileStream << "Unit offset: " << endl;
for(int w = 0; w<<m_vUnitOffSet.size(); w++)
cout << float(m_vUnitOffSet[w]) << " ";
m_outputFileStream << endl << endl;
m_outputFileStream << "Unit gain: " << endl;
for(int w = 0; w<<m_vUnitGain.size(); w++)
m_outputFileStream << float(m_vUnitGain[w]) << " ";
m_outputFileStream << endl << endl;
m_outputFileStream << "----------<See output file for sample matrix>----------" <<endl<<endl;
m_outputFileStream << "----------<Internal driver buffer is "<<ulPercentFull<<" full>----------"<<endl;
m_outputFileStream << "----------<Internal driver overflow is "<<ulOverflow<< ">----------"<<endl;
}
return true;
//.........这里部分代码省略.........
示例5: Controler
Eigen::MatrixXf LQRControler::Controler(Eigen::MatrixXf states,Eigen::MatrixXf ref,bool stop){
if(stop){
xs.setZero();
xr.setZero();
deltaxsi.setZero();
xsi.setZero();
xsiant.setZero();
deltaxsi.setZero();
deltaxsiant.setZero();
deltaxs.setZero();
xs_aumented.setZero();
deltaxs.setZero();
xsi.setZero();
deltaU.setZero();
xs_aumented.setZero();
ur.setZero();
auxu.setZero();
ur.setZero();
deltaU.setZero();
xsiant.setZero();
xsi.setZero();
deltaxsiant.setZero();
deltaxsi.setZero();
}else{
//Vectors of reference trajectory and control
xs<<0,0,states(2),states.block(3,0,5,1),0,0,states(10),states.block(11,0,5,1);
xr=trajectory->TrajetoryReference_LQR(ref);
//Vector integration of error(Trapezoidal method)
deltaxsi<<xs(2,0)-xr(2,0),xs(5,0)-xr(5,0);
xsi=xsiant+ts*(deltaxsi+deltaxsiant)/2;
// Error state vector
deltaxs=xs-xr;
// augmented error state vector
xs_aumented<<deltaxs,xsi;
//Control action variation
deltaU=Ke*xs_aumented;
//Control reference
ur<<9857.54,9837.48,0,0;
// Total control action
auxu=ur+deltaU;
//Variable update
xsiant=xsi;
deltaxsiant=deltaxsi;
}
if(auxu(0,0)>15000 ){
auxu(0,0)=15000;
}
if(auxu(1,0)>15000 ){
auxu(1,0)=15000;
}
/*The mass in the mathematical model was taken in grams,
for this reason the controller calculate the forces in g .m/s^2 and the torque in g .m^2/s^2.
But, the actuators are in the international units N and N. m for this reason the controls
actions are transforming from g to Kg*/
u(0,0)=auxu(0,0)/1000;
u(1,0)=auxu(1,0)/1000;
u(2,0)=auxu(2,0)/1000;
u(3,0)=auxu(3,0)/1000;
return u;
}
示例6: Gain
//.........这里部分代码省略.........
Ke(3,1)=-0.000539;
Ke(3,2)=-0.111553;
Ke(3,3)=5.822244;
Ke(3,4)=-70.549998;
Ke(3,5)=490.165027;
Ke(3,6)=77.591946;
Ke(3,7)=-354.399256;
Ke(3,8)=-0.489745;
Ke(3,9)=-0.039581;
Ke(3,10)=-0.010310;
Ke(3,11)=1.145871;
Ke(3,12)=-17.037510;
Ke(3,13)=69.500655;
Ke(3,14)=0.441369;
Ke(3,15)=-12.937294;
Ke(3,16)=-0.338912;
Ke(3,17)=1298.506592;
break;
case 4:
// lambda=[ 0.000000 0.000000 0.000000 0.000000]
// rho=[ 0.000000 0.000000 20.000000 40.528473 81.056947 50.660592 4.052847 4.052847 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 400.000000 60.792710]
Ke(0,0)=-1.125831;
Ke(0,1)=-19.778281;
Ke(0,2)=-575993.163298;
Ke(0,3)=247883.643143;
Ke(0,4)=-21557.884892;
Ke(0,5)=-12854.879116;
Ke(0,6)=-2000.372074;
Ke(0,7)=-539.375599;
Ke(0,8)=-137.504190;
Ke(0,9)=-1794.787886;
Ke(0,10)=-41404.251389;
Ke(0,11)=8775.389726;
Ke(0,12)=-880.584294;
Ke(0,13)=-526.328810;
Ke(0,14)=-18.226381;
Ke(0,15)=-13.000127;
Ke(0,16)=-2772222.571130;
Ke(0,17)=-26362.179696;
Ke(1,0)=1.136584;
Ke(1,1)=19.881801;
Ke(1,2)=-575069.626305;
Ke(1,3)=-249177.147919;
Ke(1,4)=21767.189875;
Ke(1,5)=12956.111576;
Ke(1,6)=2010.509412;
Ke(1,7)=541.553128;
Ke(1,8)=138.805751;
Ke(1,9)=1804.217013;
Ke(1,10)=-41327.000766;
Ke(1,11)=-8793.228301;
Ke(1,12)=892.822556;
Ke(1,13)=531.631795;
Ke(1,14)=18.306742;
Ke(1,15)=13.058151;
Ke(1,16)=-2768057.387627;
Ke(1,17)=26569.044856;
Ke(2,0)=-0.137396;
Ke(2,1)=0.012876;
Ke(2,2)=-0.063661;
Ke(2,3)=-165.713137;
Ke(2,4)=-2732.126769;
Ke(2,5)=-2784.165149;
Ke(2,6)=-1276.475398;
Ke(2,7)=-160.102664;
Ke(2,8)=-16.443170;
Ke(2,9)=1.154133;
Ke(2,10)=-0.001965;
Ke(2,11)=-16.969634;
Ke(2,12)=-246.881269;
Ke(2,13)=-298.509866;
Ke(2,14)=-22.869671;
Ke(2,15)=-3.848760;
Ke(2,16)=-0.350008;
Ke(2,17)=-5020.319210;
Ke(3,0)=-0.138113;
Ke(3,1)=0.000406;
Ke(3,2)=-0.015478;
Ke(3,3)=-5.231209;
Ke(3,4)=-2743.690755;
Ke(3,5)=2778.132469;
Ke(3,6)=-158.824748;
Ke(3,7)=-1280.010522;
Ke(3,8)=-16.535203;
Ke(3,9)=0.035779;
Ke(3,10)=-0.000020;
Ke(3,11)=0.383136;
Ke(3,12)=-247.180538;
Ke(3,13)=297.468933;
Ke(3,14)=-3.836858;
Ke(3,15)=-22.898607;
Ke(3,16)=-0.101312;
Ke(3,17)=5001.332919;
break;
default:
Ke.setZero();
break;
}
return Ke;
}
示例7: getSampleMatrixValue
bool GUSBAmpDriver::getSampleMatrixValue(MatrixXf& sampleMatrix)
{
sampleMatrix.setZero(); // Clear matrix - set all elements to zero
for(int queueIndex=0; queueIndex<m_QUEUE_SIZE; queueIndex++)
{
//receive data from each device
for (int deviceIndex = 0; deviceIndex < m_numDevices; deviceIndex++)
{
HANDLE hDevice = m_callSequenceHandles[deviceIndex];
//wait for notification from the system telling that new data is available
if (WaitForSingleObject(m_overlapped[deviceIndex][queueIndex].hEvent, 1000) == WAIT_TIMEOUT)
{
//throw string("Error on data transfer: timeout occurred.");
cout << "Error on data transfer: timeout occurred." << "\n";
return 0;
}
//get number of received bytes...
GetOverlappedResult(hDevice, &m_overlapped[deviceIndex][queueIndex], &m_numBytesReceived, false);
//...and check if we lost something (number of received bytes must be equal to the previously allocated buffer size)
if (m_numBytesReceived != m_bufferSizeBytes)
{
//throw string("Error on data transfer: samples lost.");
cout << "Error on data transfer: samples lost." << "\n";
return 0;
}
}
//store received data from each device in the correct order (that is scan-wise, where one scan includes all channels of all devices) ignoring the header
//Data is aligned as follows: element at position destBuffer(scanIndex * (m_chNumberOfChannels + m_bTrigger) + channelIndex) * sizeof(float) + HEADER_SIZE is sample of channel channelIndex (zero-based) of the scan with zero-based scanIndex.
//channelIndex ranges from 0..numDevices*numChannelsPerDevices where numDevices equals the number of recorded devices and numChannelsPerDevice the number of channels from each of those devices.
//It is assumed that all devices provide the same number of channels.
for (int scanIndex = 0; scanIndex < m_iNumberOfScans; scanIndex++)
{
for (int deviceIndex = 0; deviceIndex < m_numDevices; deviceIndex++)
{
for(int channelIndex = 0; channelIndex<m_chNumberOfChannels; channelIndex++)
{
BYTE ByteValue[sizeof(float)];
float FloatValue;
for(int i=0;i<sizeof(float);i++)
{
ByteValue[i] = m_buffers[deviceIndex][queueIndex][(scanIndex * (m_chNumberOfChannels + m_bTrigger) + channelIndex) * sizeof(float) + HEADER_SIZE + i];
}
memcpy(&FloatValue, &ByteValue, sizeof(float));
//store float-value to Matrix
sampleMatrix(channelIndex + deviceIndex*int(m_chNumberOfChannels), scanIndex + queueIndex * m_iNumberOfScans) = FloatValue;
}
}
}
//add new GetData call to the queue replacing the currently received one
for (int deviceIndex = 0; deviceIndex < m_numDevices; deviceIndex++)
if (!GT_GetData(m_callSequenceHandles[deviceIndex], m_buffers[deviceIndex][queueIndex], m_bufferSizeBytes, &m_overlapped[deviceIndex][queueIndex]))
{
cout << "\tError on GT_GetData.\n";
return 0;
}
}
return true;
}