Pololu Robotics & Electronics
Menu
My account Comments or questions? About Pololu Contact Ordering information Distributors

Controlling a solenoid with the jrk


#1

I am attempting to use a jrk 21v3 to control a solenoid. Everything works fine in the Configuration Utility with the following parameters:

Input mode: Serial
Serial Interface: USB Dual Port
Feedback mode: (None)

To engage the solenoid, I set the target in the “Manually set target” panel to 4095 (or 0). To disengage, I simply stop the motor.

I am having trouble replicating this behavior in C code however. I am running a linear actuator with a second jrk with no problems. I set the target using the compact protocol, and the linear actuator behaves appropriately.

With the solenoid, when I set the target, nothing moves. I have tried both setting the target in high and low resolution to no avail. Here is the code I am using to attempt to drive the solenoid:


 
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
 
#ifdef _WIN32
#define O_NOCTTY 0
#else
#include <termios.h>
#endif

int jrkSetTarget(int fd)
{
  unsigned short target = 0xA58;
  unsigned char command[] = {0xE1, target};
  if (write(fd, command, sizeof(command)) == -1)
  {
    perror("error writing");
    return -1;
  }
  return 0;
}
 
int main()
{

  const char * device = "/dev/cu.usbmodem00195891"; // Mac OS X
  int fd = open(device, O_RDWR | O_NOCTTY);
  if (fd == -1)
  {
    perror(device);
    return 1;
  }
 
#ifndef _WIN32
  struct termios options;
  tcgetattr(fd, &options);
  options.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
  options.c_oflag &= ~(ONLCR | OCRNL);
  tcsetattr(fd, TCSANOW, &options);
#endif
 
  jrkSetTarget(fd);


  return 0;
}

#2

It looks like you are sending an invalid target. The command you are using in your code (Set Target Low Resolution Forward) accepts a “magnitude” value that is used to calculate the target position. As mentioned under the “Set Target Low Resolution” heading of the “Motor Control Commands” section in the jrk controller’s user’s guide, the calculation when feedback mode is set to “None” is as follows:

Target = 2048 + (600/127)×magnitude

For example, to set the target to full-speed forward (2648 when the feedback mode is set to “None”) the magnitude value should be 127 (or 0x7Fin hex). Could you try changing your “target” variable to 0x7F and see if that helps?

Brandon


#3

Hi Brandon,

Sorry about that – yes, I originally had this set as 0x7F, but had changed it during my troubleshooting.

I ended up getting the solenoid to work appropriately by setting a target (in high resolution) to the max value, and then checking/clearing the error status with command protocol 0xB3. For some reason it seems errors needed to be cleared after setting the target.