Message 1 of 3
slideValue is to slow

Not applicable
04-06-2020
04:30 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Posting again, first was considered spam, don't know why.
I'm developing a software to control motion rigs for simulators.
There, we calculate the actuators positions.
The idea is to send those positions to Fusion360 and preview the result in the model.
Many use Fusion to design their rig, and that was a way to preview the result.
So I made a C DLL to get the values from shared memory, and update the joints.
Problem is that each time I update the joints, it takes around 3 seconds to update it in Fusion360.
Is there a way to make it faster?
The software:
Message box shows elapsed time to set 6 sliders...
The current code to test it:
#include <Core/CoreAll.h>
#include <Fusion/FusionAll.h>
#include <CAM/CAMAll.h>
#include <Fusion/Components/RevoluteJointMotion.h>
#include <Fusion/Components/SliderJointMotion.h>
#include <Fusion/Components/Component.h>
#include <windows.h> // for mmf
#include <string>
#include <iostream>
#include <chrono>
using namespace adsk::core;
using namespace adsk::fusion;
using namespace adsk::cam;
Ptr<Application> app;
Ptr<UserInterface> ui;
HANDLE hMMF; // Memory file
LPVOID data; // Mapped view
const DWORD BUF_SIZE = 6; // Size of the info we are sending for now just bytes
extern "C" XI_EXPORT bool run(const char* context)
{
app = Application::get();
if (!app)
return false;
ui = app->userInterface();
if (!ui)
return false;
// Get data from the shared memory
hMMF = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, L"TESTEMMF");
data = MapViewOfFile(hMMF, FILE_MAP_ALL_ACCESS, 0, 0, BUF_SIZE);
Ptr<Product> product = app->activeProduct();
if (!product)
return false;
Ptr<Design> design = product;
if (!design)
return false;
// Get the root component of the active design
Ptr<Component> rootComp = design->rootComponent();
if (!rootComp)
return false;
Ptr<Joints> joints = rootComp->joints();
if (!joints)
return false;
// Get joints by name
Ptr<SliderJointMotion> axis1a = joints->itemByName("Axis1a")->jointMotion();
if (!axis1a)
return false;
Ptr<SliderJointMotion> axis2a = joints->itemByName("Axis2a")->jointMotion();
if (!axis1a)
return false;
Ptr<SliderJointMotion> axis3a = joints->itemByName("Axis3a")->jointMotion();
if (!axis1a)
return false;
Ptr<SliderJointMotion> axis4a = joints->itemByName("Axis4a")->jointMotion();
if (!axis1a)
return false;
Ptr<SliderJointMotion> axis5a = joints->itemByName("Axis5a")->jointMotion();
if (!axis1a)
return false;
Ptr<SliderJointMotion> axis6a = joints->itemByName("Axis6a")->jointMotion();
if (!axis1a)
return false;
char text[200];
double mult = 127.0/250.0;
while (true)
{
// -250 to 250 in the joints 250->127
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
double k = (((byte*)data)[0] - 127) * mult;
axis1a->slideValue(k);
k = (((byte*)data)[1] - 127) * mult;
axis2a->slideValue(k);
k = (((byte*)data)[2] - 127) * mult;
axis3a->slideValue(k);
k = (((byte*)data)[3] - 127) * mult;
axis4a->slideValue(k);
k = (((byte*)data)[4] - 127) * mult;
axis5a->slideValue(k);
k = (((byte*)data)[5] - 127) * mult;
axis6a->slideValue(k);
std::chrono::steady_clock::time_point middle = std::chrono::steady_clock::now();
sprintf(text, "Elapsed: %dµs", std::chrono::duration_cast<std::chrono::microseconds>(middle - begin).count());
if (ui->messageBox(text, "Test", adsk::core::MessageBoxButtonTypes::OKCancelButtonType, adsk::core::MessageBoxIconTypes::QuestionIconType) == adsk::core::DialogResults::DialogCancel) return true;
adsk::doEvents();
}
return true;
}
#ifdef XI_WIN
BOOL APIENTRY DllMain(HMODULE hmodule, DWORD reason, LPVOID reserved)
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#endif // XI_WIN