Skip to content

Commit d6dfe55

Browse files
Raylase driver: Enabled IO Cycles
1 parent c55b921 commit d6dfe55

8 files changed

Lines changed: 330 additions & 26 deletions

Drivers/RayLase/Implementation/libmcdriver_raylase_raylasecardimpl.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ CRaylaseCardImpl::CRaylaseCardImpl(PRaylaseSDK pSDK, const std::string& sCardNam
7070
throw ELibMCDriver_RaylaseInterfaceException(LIBMCDRIVER_RAYLASE_ERROR_INVALIDPARAM);
7171

7272
m_pNLightDriverImpl = std::make_shared<CNLightDriverImpl>(m_pSDK, m_pDriverEnvironment);
73+
m_pIOCycleMapping = std::make_shared<CRaylaseCardIOCycleMapping>();
7374

7475
if ((dMaxLaserPowerInWatts < RAYLASE_MINLASERPOWER) || (dMaxLaserPowerInWatts > RAYLASE_MAXLASERPOWER))
7576
throw ELibMCDriver_RaylaseInterfaceException(LIBMCDRIVER_RAYLASE_ERROR_INVALIDLASERPOWER, "invalid laser power: " + std::to_string (dMaxLaserPowerInWatts));
@@ -348,7 +349,7 @@ LibMCEnv::PDriverEnvironment CRaylaseCardImpl::getDriverEnvironment()
348349

349350
PRaylaseCardList CRaylaseCardImpl::createNewList()
350351
{
351-
return std::make_shared<CRaylaseCardList>(m_pSDK, m_Handle, m_dMaxLaserPowerInWatts, m_pCoordinateTransform, m_PartSuppressions, m_pNLightDriverImpl);
352+
return std::make_shared<CRaylaseCardList>(m_pSDK, m_Handle, m_dMaxLaserPowerInWatts, m_pCoordinateTransform, m_PartSuppressions, m_pNLightDriverImpl, m_pIOCycleMapping);
352353
}
353354

354355
void CRaylaseCardImpl::abortListExecution()
@@ -385,35 +386,25 @@ double CRaylaseCardImpl::getMaxLaserPowerInWatts()
385386

386387
PRaylaseIOCycleImpl CRaylaseCardImpl::createIOCycle(uint32_t nCycleID)
387388
{
388-
if (nCycleID == 0)
389-
throw ELibMCDriver_RaylaseInterfaceException(LIBMCDRIVER_RAYLASE_ERROR_INVALIDIOCYCLEID);
390-
391-
auto iIter = m_IOCycles.find(nCycleID);
392-
if (iIter != m_IOCycles.end())
393-
throw ELibMCDriver_RaylaseInterfaceException(LIBMCDRIVER_RAYLASE_ERROR_IOCYCLEALREADYEXISTS);
394-
395-
auto pIOCycle = std::make_shared<CRaylaseIOCycleImpl>(nCycleID);
396-
m_IOCycles.insert(std::make_pair(nCycleID, pIOCycle));
397-
398-
return pIOCycle;
389+
return m_pIOCycleMapping->createIOCycle(nCycleID);
399390
}
400391

401392
bool CRaylaseCardImpl::ioCycleExists(uint32_t nCycleID) const
402393
{
403-
auto iIter = m_IOCycles.find(nCycleID);
404-
return (iIter != m_IOCycles.end());
394+
return m_pIOCycleMapping->ioCycleExists(nCycleID);
405395
}
406396

407397
PRaylaseIOCycleImpl CRaylaseCardImpl::getIOCycle(uint32_t nCycleID) const
408398
{
409-
auto iIter = m_IOCycles.find(nCycleID);
410-
if (iIter == m_IOCycles.end())
411-
throw ELibMCDriver_RaylaseInterfaceException(LIBMCDRIVER_RAYLASE_ERROR_IOCYCLENOTFOUND);
412-
413-
return iIter->second;
399+
return m_pIOCycleMapping->getIOCycle(nCycleID);
414400
}
415401

416402
void CRaylaseCardImpl::removeIOCycle(uint32_t nCycleID)
417403
{
418-
m_IOCycles.erase(nCycleID);
404+
m_pIOCycleMapping->removeIOCycle(nCycleID);
405+
}
406+
407+
PRaylaseCardIOCycleMapping CRaylaseCardImpl::getIOCycleMapping()
408+
{
409+
return m_pIOCycleMapping;
419410
}

Drivers/RayLase/Implementation/libmcdriver_raylase_raylasecardimpl.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Abstract: This is the class declaration of CRaylaseCard
3939
#include "libmcdriver_raylase_sdk.hpp"
4040
#include "libmcdriver_raylase_raylasecardlist.hpp"
4141
#include "libmcdriver_raylase_nlightdriverimpl.hpp"
42-
#include "libmcdriver_raylase_raylaseiocycleimpl.hpp"
42+
#include "libmcdriver_raylase_raylaseiocyclemapping.hpp"
4343

4444
namespace LibMCDriver_Raylase {
4545
namespace Impl {
@@ -87,7 +87,7 @@ class CRaylaseCardImpl {
8787
PNLightDriverImpl m_pNLightDriverImpl;
8888

8989
std::map<std::string, ePartSuppressionMode> m_PartSuppressions;
90-
std::map<uint32_t, PRaylaseIOCycleImpl> m_IOCycles;
90+
PRaylaseCardIOCycleMapping m_pIOCycleMapping;
9191

9292
public:
9393

@@ -159,6 +159,8 @@ class CRaylaseCardImpl {
159159

160160
void removeIOCycle(uint32_t nCycleID);
161161

162+
PRaylaseCardIOCycleMapping getIOCycleMapping();
163+
162164
};
163165

164166
} // namespace Impl

Drivers/RayLase/Implementation/libmcdriver_raylase_raylasecardlist.cpp

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,16 @@ void CRaylaseCoordinateTransform::applyTransform(double& dX, double& dY)
8787
}
8888

8989

90-
CRaylaseCardList::CRaylaseCardList(PRaylaseSDK pSDK, rlHandle cardHandle, double dMaxLaserPowerInWatts, PRaylaseCoordinateTransform pCoordinateTransform, const std::map<std::string, ePartSuppressionMode>& partSuppressions, PNLightDriverImpl pNLightBoardImpl)
90+
CRaylaseCardList::CRaylaseCardList(PRaylaseSDK pSDK, rlHandle cardHandle, double dMaxLaserPowerInWatts, PRaylaseCoordinateTransform pCoordinateTransform, const std::map<std::string, ePartSuppressionMode>& partSuppressions, PNLightDriverImpl pNLightBoardImpl, PRaylaseCardIOCycleMapping pIOCycleMapping)
9191
: m_pSDK(pSDK),
9292
m_ListHandle(0),
9393
m_CardHandle(cardHandle),
9494
m_dMaxLaserPowerInWatts_Mode0(dMaxLaserPowerInWatts),
9595
m_nListIDOnCard (RAYLASE_LISTONCARDNOTSET),
9696
m_pCoordinateTransform (pCoordinateTransform),
9797
m_PartSuppressions (partSuppressions),
98-
m_pNLightBoardImpl (pNLightBoardImpl)
98+
m_pNLightBoardImpl (pNLightBoardImpl),
99+
m_pIOCycleMapping (pIOCycleMapping)
99100

100101
{
101102
if (pSDK.get() == nullptr)
@@ -165,6 +166,16 @@ void CRaylaseCardList::addLayerToList(LibMCEnv::PToolpathLayer pLayer, uint32_t
165166

166167
double dUnits = pLayer->GetUnits();
167168

169+
// Check if pre/post cycle attributes are present
170+
uint32_t nPreCycleAttributeID = 0;
171+
if (pLayer->HasCustomSegmentAttribute("http://schemas.raylase.com/iocontrol/2026/01", "precycleid"))
172+
nPreCycleAttributeID = pLayer->FindCustomSegmentAttributeID("http://schemas.raylase.com/iocontrol/2026/01", "precycleid");
173+
174+
uint32_t nPostCycleAttributeID = 0;
175+
if (pLayer->HasCustomSegmentAttribute("http://schemas.raylase.com/iocontrol/2026/01", "postcycleid"))
176+
nPostCycleAttributeID = pLayer->FindCustomSegmentAttributeID("http://schemas.raylase.com/iocontrol/2026/01", "postcycleid");
177+
178+
168179
m_pSDK->checkError(m_pSDK->rlListAppendLaserOff(m_ListHandle), "rlListAppendLaserOff");
169180

170181
uint32_t nSegmentCount = pLayer->GetSegmentCount();
@@ -196,6 +207,16 @@ void CRaylaseCardList::addLayerToList(LibMCEnv::PToolpathLayer pLayer, uint32_t
196207
bDrawSegment = false;
197208
}
198209

210+
211+
// Check for pre/postcycles to execute.
212+
int64_t nPreCycleID = 0;
213+
if (nPreCycleAttributeID != 0)
214+
nPreCycleID = pLayer->GetSegmentIntegerAttribute(nSegmentIndex, nPreCycleAttributeID);
215+
216+
int64_t nPostCycleID = 0;
217+
if (nPostCycleAttributeID != 0)
218+
nPostCycleID = pLayer->GetSegmentIntegerAttribute(nSegmentIndex, nPostCycleAttributeID);
219+
199220
// Check if part is not to be ignored
200221
std::string sSegmentPartUUID = pLayer->GetSegmentPartUUID(nSegmentIndex);
201222
ePartSuppressionMode suppressionMode = getPartSuppressionMode(sSegmentPartUUID);
@@ -230,6 +251,17 @@ void CRaylaseCardList::addLayerToList(LibMCEnv::PToolpathLayer pLayer, uint32_t
230251
}
231252

232253
}
254+
255+
256+
// Execute pre-cycle if specified
257+
if (nPreCycleID != 0) {
258+
if (m_pIOCycleMapping.get() == nullptr)
259+
throw ELibMCDriver_RaylaseInterfaceException(LIBMCDRIVER_RAYLASE_ERROR_IOCYCLENOTFOUND, "Pre-cycle ID " + std::to_string(nPreCycleID) + " specified but no IO cycle mapping available");
260+
if (!m_pIOCycleMapping->ioCycleExists((uint32_t)nPreCycleID))
261+
throw ELibMCDriver_RaylaseInterfaceException(LIBMCDRIVER_RAYLASE_ERROR_IOCYCLENOTFOUND, "Pre-cycle ID " + std::to_string(nPreCycleID) + " not found");
262+
auto pPreCycle = m_pIOCycleMapping->getIOCycle((uint32_t)nPreCycleID);
263+
executeIOCycle(pPreCycle);
264+
}
233265

234266

235267
double dJumpSpeedInMeterPerSecond = dJumpSpeedInMMPerSecond * 0.001;
@@ -345,6 +377,16 @@ void CRaylaseCardList::addLayerToList(LibMCEnv::PToolpathLayer pLayer, uint32_t
345377

346378
}
347379

380+
// Execute post-cycle if specified
381+
if (nPostCycleID != 0) {
382+
if (m_pIOCycleMapping.get() == nullptr)
383+
throw ELibMCDriver_RaylaseInterfaceException(LIBMCDRIVER_RAYLASE_ERROR_IOCYCLENOTFOUND, "Post-cycle ID " + std::to_string(nPostCycleID) + " specified but no IO cycle mapping available");
384+
if (!m_pIOCycleMapping->ioCycleExists((uint32_t)nPostCycleID))
385+
throw ELibMCDriver_RaylaseInterfaceException(LIBMCDRIVER_RAYLASE_ERROR_IOCYCLENOTFOUND, "Post-cycle ID " + std::to_string(nPostCycleID) + " not found");
386+
auto pPostCycle = m_pIOCycleMapping->getIOCycle((uint32_t)nPostCycleID);
387+
executeIOCycle(pPostCycle);
388+
}
389+
348390
}
349391

350392
}
@@ -430,3 +472,67 @@ LibMCDriver_Raylase::ePartSuppressionMode CRaylaseCardList::getPartSuppressionMo
430472
}
431473

432474

475+
void CRaylaseCardList::executeIOCycle(PRaylaseIOCycleImpl pIOCycle)
476+
{
477+
if (pIOCycle.get() == nullptr)
478+
return;
479+
480+
const auto& entries = pIOCycle->getEntries();
481+
for (const auto& entry : entries) {
482+
switch (entry.m_EntryType) {
483+
case eIOCycleEntryType::SignalOut:
484+
{
485+
// Convert LibMCDriver_Raylase::eIOPort to eRLIOPort
486+
eRLIOPort rlPort = eRLIOPort::ioPortA;
487+
switch (entry.m_IOPort) {
488+
case eIOPort::PortA: rlPort = eRLIOPort::ioPortA; break;
489+
case eIOPort::PortB: rlPort = eRLIOPort::ioPortB; break;
490+
case eIOPort::PortC: rlPort = eRLIOPort::ioPortC; break;
491+
case eIOPort::PortD: rlPort = eRLIOPort::ioPortD; break;
492+
case eIOPort::PortE: rlPort = eRLIOPort::ioPortE; break;
493+
default:
494+
throw ELibMCDriver_RaylaseInterfaceException(LIBMCDRIVER_RAYLASE_ERROR_INVALIDIOPORT);
495+
}
496+
497+
// Set the pin high using the pin mask
498+
uint32_t nPinMask = (1u << entry.m_nIOPin);
499+
m_pSDK->checkError(m_pSDK->rlListAppendGpioValue(m_ListHandle, rlPort, eRLPinAction::paSet, nPinMask), "rlListAppendGpioValue");
500+
break;
501+
}
502+
503+
case eIOCycleEntryType::WaitForSignal:
504+
{
505+
// Convert LibMCDriver_Raylase::eIOPort to eRLIOPort
506+
eRLIOPort rlPort = eRLIOPort::ioPortA;
507+
switch (entry.m_IOPort) {
508+
case eIOPort::PortA: rlPort = eRLIOPort::ioPortA; break;
509+
case eIOPort::PortB: rlPort = eRLIOPort::ioPortB; break;
510+
case eIOPort::PortC: rlPort = eRLIOPort::ioPortC; break;
511+
case eIOPort::PortD: rlPort = eRLIOPort::ioPortD; break;
512+
case eIOPort::PortE: rlPort = eRLIOPort::ioPortE; break;
513+
default:
514+
throw ELibMCDriver_RaylaseInterfaceException(LIBMCDRIVER_RAYLASE_ERROR_INVALIDIOPORT);
515+
}
516+
517+
// Wait for input signal on the specified pin
518+
uint32_t nPinMask = (1u << entry.m_nIOPin);
519+
int32_t nTimeoutInMicroseconds = (int32_t)entry.m_nTimeoutOrDelayInMicroseconds;
520+
m_pSDK->checkError(m_pSDK->rlListAppendWaitForInput(m_ListHandle, nPinMask, rlPort, true, false, nPinMask, nTimeoutInMicroseconds), "rlListAppendWaitForInput");
521+
break;
522+
}
523+
524+
case eIOCycleEntryType::Delay:
525+
{
526+
// Delay is specified in microseconds, SDK expects seconds
527+
double dDelayInSeconds = (double)entry.m_nTimeoutOrDelayInMicroseconds / 1000000.0;
528+
m_pSDK->checkError(m_pSDK->rlListAppendSleep(m_ListHandle, dDelayInSeconds), "rlListAppendSleep");
529+
break;
530+
}
531+
532+
default:
533+
break;
534+
}
535+
}
536+
}
537+
538+

Drivers/RayLase/Implementation/libmcdriver_raylase_raylasecardlist.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Abstract: This is the class declaration of CRaylaseCard
3838
#include "libmcdriver_raylase_interfaces.hpp"
3939
#include "libmcdriver_raylase_sdk.hpp"
4040
#include "libmcdriver_raylase_nlightdriverimpl.hpp"
41+
#include "libmcdriver_raylase_raylaseiocyclemapping.hpp"
4142

4243
#include <map>
4344

@@ -91,10 +92,13 @@ class CRaylaseCardList
9192

9293
std::map<std::string, ePartSuppressionMode> m_PartSuppressions;
9394
PNLightDriverImpl m_pNLightBoardImpl;
95+
PRaylaseCardIOCycleMapping m_pIOCycleMapping;
96+
97+
void executeIOCycle(PRaylaseIOCycleImpl pIOCycle);
9498

9599
public:
96100

97-
CRaylaseCardList(PRaylaseSDK pSDK, rlHandle cardHandle, double dMaxLaserPowerInWatts, PRaylaseCoordinateTransform pCoordinateTransform, const std::map<std::string, ePartSuppressionMode> & partSuppressions, PNLightDriverImpl pNLightBoardImpl);
101+
CRaylaseCardList(PRaylaseSDK pSDK, rlHandle cardHandle, double dMaxLaserPowerInWatts, PRaylaseCoordinateTransform pCoordinateTransform, const std::map<std::string, ePartSuppressionMode> & partSuppressions, PNLightDriverImpl pNLightBoardImpl, PRaylaseCardIOCycleMapping pIOCycleMapping);
98102

99103
virtual ~CRaylaseCardList();
100104

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*++
2+
3+
Copyright (C) 2020 Autodesk Inc.
4+
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
* Neither the name of the Autodesk Inc. nor the
15+
names of its contributors may be used to endorse or promote products
16+
derived from this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL AUTODESK INC. BE LIABLE FOR ANY
22+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
30+
Abstract: This is the implementation of CRaylaseCardIOCycleMapping
31+
32+
*/
33+
34+
#include "libmcdriver_raylase_raylaseiocyclemapping.hpp"
35+
#include "libmcdriver_raylase_interfaceexception.hpp"
36+
37+
using namespace LibMCDriver_Raylase::Impl;
38+
39+
CRaylaseCardIOCycleMapping::CRaylaseCardIOCycleMapping()
40+
{
41+
}
42+
43+
CRaylaseCardIOCycleMapping::~CRaylaseCardIOCycleMapping()
44+
{
45+
}
46+
47+
PRaylaseIOCycleImpl CRaylaseCardIOCycleMapping::createIOCycle(uint32_t nCycleID)
48+
{
49+
if (nCycleID == 0)
50+
throw ELibMCDriver_RaylaseInterfaceException(LIBMCDRIVER_RAYLASE_ERROR_INVALIDIOCYCLEID);
51+
52+
auto iIter = m_IOCycles.find(nCycleID);
53+
if (iIter != m_IOCycles.end())
54+
throw ELibMCDriver_RaylaseInterfaceException(LIBMCDRIVER_RAYLASE_ERROR_IOCYCLEALREADYEXISTS);
55+
56+
auto pIOCycle = std::make_shared<CRaylaseIOCycleImpl>(nCycleID);
57+
m_IOCycles.insert(std::make_pair(nCycleID, pIOCycle));
58+
59+
return pIOCycle;
60+
}
61+
62+
bool CRaylaseCardIOCycleMapping::ioCycleExists(uint32_t nCycleID) const
63+
{
64+
auto iIter = m_IOCycles.find(nCycleID);
65+
return (iIter != m_IOCycles.end());
66+
}
67+
68+
PRaylaseIOCycleImpl CRaylaseCardIOCycleMapping::getIOCycle(uint32_t nCycleID) const
69+
{
70+
auto iIter = m_IOCycles.find(nCycleID);
71+
if (iIter == m_IOCycles.end())
72+
throw ELibMCDriver_RaylaseInterfaceException(LIBMCDRIVER_RAYLASE_ERROR_IOCYCLENOTFOUND);
73+
74+
return iIter->second;
75+
}
76+
77+
void CRaylaseCardIOCycleMapping::removeIOCycle(uint32_t nCycleID)
78+
{
79+
m_IOCycles.erase(nCycleID);
80+
}
81+
82+
void CRaylaseCardIOCycleMapping::clearAllIOCycles()
83+
{
84+
m_IOCycles.clear();
85+
}
86+
87+
size_t CRaylaseCardIOCycleMapping::getIOCycleCount() const
88+
{
89+
return m_IOCycles.size();
90+
}

0 commit comments

Comments
 (0)