Skip to content

Commit ad83d1a

Browse files
SMC Fixes for Correction handling and 3D Points
1 parent b3281e5 commit ad83d1a

File tree

5 files changed

+50
-20
lines changed

5 files changed

+50
-20
lines changed

Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcconfiguration.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ void CSMCConfiguration::SetCorrectionFile(const LibMCDriver_ScanLabSMC_uint64 nC
131131

132132
}
133133

134+
m_pDriverEnvironment->LogMessage("Correction file data loaded from memory, size: " + std::to_string(m_CorrectionFileData.size()));
135+
134136
}
135137

136138
void CSMCConfiguration::SetCorrectionFileResource(const std::string& sResourceName)
@@ -151,10 +153,12 @@ void CSMCConfiguration::SetCorrectionFileResource(const std::string& sResourceNa
151153
throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_RTCCORRECTIONRESOURCENOTFOUND, "RTC correction resource not found: " + sResourceName);
152154
}
153155

156+
m_pDriverEnvironment->LogMessage ("Correction file data loaded from resource " + sResourceName + ", size: " + std::to_string (m_CorrectionFileData.size()));
154157

155158
}
156159

157160

161+
158162
void CSMCConfiguration::SetConfigurationTemplateResource(const std::string& sResourceName)
159163
{
160164
if (sResourceName.empty())
@@ -299,14 +303,17 @@ void CSMCConfiguration::SetFirmwareResources(const std::string& sFirmwareDataRes
299303

300304
}
301305

302-
std::string CSMCConfiguration::buildConfigurationXML(LibMCEnv::CWorkingDirectory* pWorkingDirectory, LibMCEnv::PWorkingFile& newCorrectionFile, LibMCDriver_ScanLabSMC::eSMCConfigVersion configVersion, const std::string& sRTCIPAddress)
306+
std::string CSMCConfiguration::buildConfigurationXML(LibMCEnv::CWorkingDirectory* pWorkingDirectory, LibMCDriver_ScanLabSMC::eSMCConfigVersion configVersion, const std::string& sRTCIPAddress, LibMCEnv::PWorkingFile pCorrectionFileToUse)
303307
{
304308

305309
if (pWorkingDirectory == nullptr)
306310
throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDPARAM);
307311
if ((m_nSerialNumber < SMCCONFIGURATION_MINSERIALNUMBER) || (m_nSerialNumber > SMCCONFIGURATION_MAXSERIALNUMBER))
308312
throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDRTCSERIALNUMBER);
309-
if (m_CorrectionFileData.size () == 0)
313+
if (pCorrectionFileToUse.get() == nullptr)
314+
throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDPARAM);
315+
316+
if (pCorrectionFileToUse->GetSize () == 0)
310317
throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCCORRECTIONFILE);
311318

312319
if (!sRTCIPAddress.empty()) {
@@ -315,8 +322,6 @@ std::string CSMCConfiguration::buildConfigurationXML(LibMCEnv::CWorkingDirectory
315322
throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDIPADDRESS, "invalid RTC IP Address: " + sRTCIPAddress);
316323
}
317324

318-
newCorrectionFile = pWorkingDirectory->StoreCustomDataInTempFile("ct5", m_CorrectionFileData);
319-
320325
pWorkingDirectory->StoreCustomData("RTC6RBF.rbf", m_FPGAData);
321326
if (sRTCIPAddress.empty()) {
322327
pWorkingDirectory->StoreCustomData("RTC6OUT.out", m_FirmwareData);
@@ -328,7 +333,7 @@ std::string CSMCConfiguration::buildConfigurationXML(LibMCEnv::CWorkingDirectory
328333
pWorkingDirectory->StoreCustomData("RTC6DAT.dat", m_AuxiliaryData);
329334

330335
std::string sBaseDirectoryPath = pWorkingDirectory->GetAbsoluteFilePath();
331-
std::string sCorrectionFilePath = newCorrectionFile->GetAbsoluteFileName();
336+
std::string sCorrectionFilePath = pCorrectionFileToUse->GetAbsoluteFileName();
332337
std::string sLogFilePath = pWorkingDirectory->GetAbsoluteFilePath() + "/log.txt";
333338

334339
std::string sSimulationDirectory = sBaseDirectoryPath + "/";
@@ -573,4 +578,9 @@ std::string CSMCConfiguration::buildConfigurationXML(LibMCEnv::CWorkingDirectory
573578
//m_pDriverEnvironment->Sleep(100000);
574579

575580
return sXMLString;
576-
};
581+
};
582+
583+
std::vector<uint8_t> & CSMCConfiguration::getCorrectionFileData()
584+
{
585+
return m_CorrectionFileData;
586+
}

Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcconfiguration.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ class CSMCConfiguration : public virtual ISMCConfiguration, public virtual CBase
126126

127127
void SetFirmwareResources(const std::string& sFirmwareDataResource, const std::string& sFPGADataResource, const std::string& sAuxiliaryDataResource) override;
128128

129-
std::string buildConfigurationXML(LibMCEnv::CWorkingDirectory * pWorkingDirectory, LibMCEnv::PWorkingFile & newCorrectionFile, LibMCDriver_ScanLabSMC::eSMCConfigVersion configVersion, const std::string & sRTCIPAddress);
129+
std::string buildConfigurationXML(LibMCEnv::CWorkingDirectory * pWorkingDirectory, LibMCDriver_ScanLabSMC::eSMCConfigVersion configVersion, const std::string & sRTCIPAddress, LibMCEnv::PWorkingFile pCorrectionFileToUse);
130+
131+
std::vector<uint8_t> & getCorrectionFileData ();
130132

131133
};
132134

Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccontextinstance.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ CSMCContextInstance::CSMCContextInstance(const std::string& sContextName, ISMCCo
115115

116116
m_sIPAddress = pSMCConfiguration->GetIPAddress();
117117

118-
m_bSendToHardware = pSMCConfiguration->GetSendToHardware();
119-
120-
auto pCorrectionFile = m_pWorkingDirectory->StoreCustomStringInTempFile("ct5", "");
118+
m_bSendToHardware = pSMCConfiguration->GetSendToHardware();
121119

122120
eSMCConfigVersion configVersion = eSMCConfigVersion::Unknown;
123121
auto versionInfo = m_pSDK->slsc_cfg_get_scanmotioncontrol_version();
@@ -143,8 +141,18 @@ CSMCContextInstance::CSMCContextInstance(const std::string& sContextName, ISMCCo
143141
throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_UNKNOWNSMCMAJORVERSION, "unknown smc major version: " + sVersionString);
144142
}
145143

144+
std::vector<uint8_t> & correctionFileBuffer = pCastedConfiguration->getCorrectionFileData();
145+
146+
m_pDriverEnvironment->LogMessage("RTC Correction file data loaded, size: " + std::to_string(correctionFileBuffer.size()));
147+
148+
if (correctionFileBuffer.empty ())
149+
throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCCORRECTIONFILE);
150+
151+
m_pCorrectionFileInUse = m_pWorkingDirectory->StoreCustomDataInTempFile("ct5", correctionFileBuffer);
152+
153+
m_pDriverEnvironment->LogMessage("RTC Correction file name " + m_pCorrectionFileInUse->GetAbsoluteFileName ());
146154

147-
std::string sConfigurationXML = pCastedConfiguration->buildConfigurationXML(m_pWorkingDirectory.get (), pCorrectionFile, configVersion, m_sIPAddress);
155+
std::string sConfigurationXML = pCastedConfiguration->buildConfigurationXML(m_pWorkingDirectory.get (), configVersion, m_sIPAddress, m_pCorrectionFileInUse);
148156

149157
std::vector<uint8_t> Buffer (sConfigurationXML.begin (), sConfigurationXML.end ());
150158

@@ -180,6 +188,7 @@ CSMCContextInstance::~CSMCContextInstance()
180188
{
181189
m_pContextHandle = nullptr;
182190
m_pSDK = nullptr;
191+
m_pCorrectionFileInUse = nullptr;
183192

184193
m_pWorkingDirectory = nullptr;
185194

Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccontextinstance.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class CSMCContextInstance {
5757

5858
LibMCEnv::PDriverEnvironment m_pDriverEnvironment;
5959
LibMCEnv::PWorkingDirectory m_pWorkingDirectory;
60+
LibMCEnv::PWorkingFile m_pCorrectionFileInUse;
6061
std::string m_sSimulationSubDirectory;
6162

6263
std::string m_sIPAddress;

Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.cpp

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ CSMCJobInstance::CSMCJobInstance(PSMCContextHandle pContextHandle, double dStart
8787
// Set digital output to 1
8888
m_pSDK->checkError(contextHandle, m_pSDK->slsc_job_write_digital_x(contextHandle, slsc_DigitalOutput::slsc_DigitalOutput_1, 1, 0 ) );
8989

90-
slsc_RecordSet eRecordSetA = slsc_RecordSet::slsc_RecordSet_HeadAPosition;
90+
slsc_RecordSet eRecordSetA = slsc_RecordSet::slsc_RecordSet_SetPositions;
9191
slsc_RecordSet eRecordSetB = slsc_RecordSet::slsc_RecordSet_LaserSwitches;
9292

9393
m_pSDK->checkError(contextHandle, m_pSDK->slsc_job_start_record(contextHandle, eRecordSetA, eRecordSetB));
@@ -140,9 +140,10 @@ void CSMCJobInstance::drawPolylineEx(slscHandle contextHandle, const uint64_t nP
140140
m_pSDK->checkError(contextHandle, m_pSDK->slsc_job_write_analog_x(contextHandle, slsc_AnalogOutput::slsc_AnalogOutput_1, dPowerFactor, 0.0));
141141

142142
auto& startPoint = pPointsBuffer[0];
143-
std::array<double, 2> startPosition;
143+
std::array<double, 3> startPosition;
144144
startPosition[0] = startPoint.m_X;
145145
startPosition[1] = startPoint.m_Y;
146+
startPosition[2] = 0.0;
146147
m_pSDK->checkError(contextHandle, m_pSDK->slsc_job_jump(contextHandle, startPosition.data()));
147148

148149
slsc_PolylineOptions polyLineOptions;
@@ -157,9 +158,10 @@ void CSMCJobInstance::drawPolylineEx(slscHandle contextHandle, const uint64_t nP
157158

158159
for (size_t nPointIndex = 1; nPointIndex < nPointsBufferSize; nPointIndex++) {
159160
auto& nextPoint = pPointsBuffer[nPointIndex];
160-
std::array<double, 2> nextPosition;
161+
std::array<double, 3> nextPosition;
161162
nextPosition[0] = nextPoint.m_X;
162163
nextPosition[1] = nextPoint.m_Y;
164+
nextPosition[2] = 0.0;
163165
m_pSDK->checkError(contextHandle, m_pSDK->slsc_job_line(contextHandle, nextPosition.data()));
164166
}
165167

@@ -235,13 +237,15 @@ void CSMCJobInstance::drawHatchesEx(const LibMCDriver_ScanLabSMC_uint64 nHatches
235237

236238
for (uint64_t nHatchIndex = 0; nHatchIndex < nHatchesBufferSize; nHatchIndex++) {
237239
auto& hatch = pHatchesBuffer[nHatchIndex];
238-
std::array<double, 2> point1;
240+
std::array<double, 3> point1;
239241
point1[0] = hatch.m_X1;
240242
point1[1] = hatch.m_Y1;
243+
point1[2] = 0.0;
241244

242-
std::array<double, 2> point2;
245+
std::array<double, 3> point2;
243246
point2[0] = hatch.m_X2;
244247
point2[1] = hatch.m_Y2;
248+
point2[2] = 0.0;
245249

246250

247251
m_pSDK->checkError(contextHandle, m_pSDK->slsc_job_jump(contextHandle, point1.data()));
@@ -276,13 +280,15 @@ void CSMCJobInstance::drawHatchesExLinearPower(const LibMCDriver_ScanLabSMC_uint
276280

277281
for (uint64_t nHatchIndex = 0; nHatchIndex < nHatchesBufferSize; nHatchIndex++) {
278282
auto& hatch = pHatchesBuffer[nHatchIndex];
279-
std::array<double, 2> point1;
283+
std::array<double, 3> point1;
280284
point1[0] = hatch.m_X1;
281285
point1[1] = hatch.m_Y1;
286+
point1[2] = 0.0;
282287

283-
std::array<double, 2> point2;
288+
std::array<double, 3> point2;
284289
point2[0] = hatch.m_X2;
285290
point2[1] = hatch.m_Y2;
291+
point2[2] = 0.0;
286292

287293
std::array<double, 1> paraPower1;
288294
paraPower1[0] = PowerValuesInWatts1.at (nHatchIndex) / m_dMaxPowerInWatts;
@@ -325,13 +331,15 @@ void CSMCJobInstance::drawHatchesExNonLinearPower(const LibMCDriver_ScanLabSMC_u
325331

326332
for (uint64_t nHatchIndex = 0; nHatchIndex < nHatchesBufferSize; nHatchIndex++) {
327333
auto& hatch = pHatchesBuffer[nHatchIndex];
328-
std::array<double, 2> point1;
334+
std::array<double, 3> point1;
329335
point1[0] = hatch.m_X1;
330336
point1[1] = hatch.m_Y1;
337+
point1[2] = 0.0;
331338

332-
std::array<double, 2> point2;
339+
std::array<double, 3> point2;
333340
point2[0] = hatch.m_X2;
334341
point2[1] = hatch.m_Y2;
342+
point2[2] = 0.0;
335343

336344
double dX = point2[0] - point1[0];
337345
double dY = point2[1] - point1[1];

0 commit comments

Comments
 (0)