epics-motor / motorThorLabs

EPICS motor drivers for Thorlabs controllers
2 stars 1 forks source link

Support for Thorlabs Kinesis Piezo Controllers #10

Open ps3017 opened 5 months ago

ps3017 commented 5 months ago

Hi,

if I understand correctly only DC and Stepper motor controllers are currently supported with Kinesis in the motorThorlabs module. I'm working on an application where I need to integrate a Kinesis Piezo motor controller (KIM101) with motorRecord.

Would you be willing to also add an EPICS motor driver support for Thorlabs Kinesis Piezo motor controllers? If yes, could you give me an approximate time frame how long it would take to add this to the motorThorlabs module?

I appreciate any help you can provide.

Best regards, Petra Smid

kmpeters commented 5 months ago

EPICS motor driver development is usually driven by those who have the hardware and need it to work. As far as I know the organizations I support don't have any Kinesis piezo motor controllers and consequently I won't be allowed to develop a driver for the KIM101 in the foreseeable future.

@keenanlang, the author of the existing Kinesis support, might be able to comment on how much effort it would take to adapt the existing support for the KIM101.

keenanlang commented 4 months ago

@ps3017

The way the Kinesis C++ libraries are written, each different class of motors have their own functions to call, so each needs to be their own controller in the code. We wrote the DC and Stepper controllers because those were the models that we have. We don't have any KIM101 motors to test things out, but you should be able to set up support for them yourself. The layout of the kinesis support is written in a way to make it relatively easy to add support for the other categories of KCube motors.

You can copy-paste the contents of drvKinesisStepper.cpp or drvKinesisDC.cpp into a new file, replacing all of the "Stepper/DC" naming conventions with your own (Piezo, Inertial, etc). At the top of the file, there is an include line, you would replace that with the one for the KIM101

#include "Thorlabs.MotionControl.KCube.DCServo.h"

include "Thorlabs.MotionControl.KCube.InertialMotor.h"

Then do a find/replace to change the function call prefixes in the file to the KIM_ prefix that the KIM101 uses

CC_Close(this->serial) KIM_Close(this->serial)

In drvKinesis.h, you will then need to add the class template, this is again a copy/paste/replace operation using the naming convention you chose before.

class epicsShareClass KinesisDCMotorAxis : public KinesisAxis class epicsShareClass KinesisPiezoMotorAxis : public KinesisAxis

and add in the option to the Enum in that file

enum
{
    KINESIS_DC_MOTOR,
    KINESIS_STEP_MOTOR,
    KINESIS_PIEZO_MOTOR,
};

In drvKinesis.cpp, you'll need to tell it to recognize that option in the constructor

if      (type == KINESIS_DC_MOTOR)    { new KinesisDCMotorAxis(this, 0, serial); }
else if (type == KINESIS_STEP_MOTOR)  { new KinesisStepMotorAxis(this, 0, serial); }
else if (type == KINESIS_PIEZO_MOTOR) { new KinesisPiezoMotorAxis(this, 0, serial); }

Then bind that option to a string, so users can designate the type in the startup script

if (motor_type == "dc" || motor_type == "DC")
{ 
    new KinesisController(asyn_port, serial, KINESIS_DC_MOTOR, movingPollPeriod, idlePollPeriod);
}
else if (motor_type == "stepper" || motor_type == "Stepper" ||
         motor_type == "step" || motor_type == "Step")
{
    new KinesisController(asyn_port, serial, KINESIS_STEP_MOTOR, movingPollPeriod, idlePollPeriod);
}
else if (motor_type == "piezo" || motor_type == "Piezo")
{
    new KinesisController(asyn_port, serial, KINESIS_PIEZO_MOTOR, movingPollPeriod, idlePollPeriod);
}

Then, finally, you just need to tell the Makefile to include your new files and the proper vendor DLL

Thorlabs.MotionControl.KCube.IntertialMotor_DIR += $(THORLABS_DIR)
ThorLabs_DLL_LIBS += Thorlabs.MotionControl.KCube.InertialMotor