VB programming SMC: setting motor acceleration

Hello:

Could you please provide a code example to set the motor acceleration in visual basic when using the smc.dll as an import? The tiny code example SmcExample1Vb only shows setting the speed, but without setting the acceleration it can cause damage to the motor. I was able to set the acceleration, but I haven’t been able to set the speed update period and so it’s ineffectual with a default update period of 1ms.

Code adapted from Pololu:

Public Function setRpmValue(ByVal mySpeed As Double) As Double
rpmVal = Math.Round(mySpeed)
Try
Using device As Smc = connectToDevice(serialNumVal) ’ Connect device as Smc
device.setMotorLimit(SmcMotorLimit.MaxAcceleration, 100) ’ Seems to be working
’ device.setSmcSettings(SmcSettings.SpeedUpdatePeriod… Not working
device.resume() ’ Clear errors as possible.
device.setSpeed(rpmVal) ’ Set the speed
End Using
Catch oEx As Exception
Throw New Exception(oEx.Message)
End Try
Return rpmVal
End Function

Thank you very much in advance for any assistance.

Hello.

I recommend using the Simple Motor Control Center to set the Speed Update Period ahead of time. It is stored in flash memory of the controller so you don’t want to be changing it frequently. Is there some reason you need to set the Speed Update Period from your VB program?

–David

That may be ok. I have two different functions to run the pumps, fast acceleration and slow acceleration. During startup, I want to ramp the motor speed very slowly. Once the system is stable and in “monitor” mode, then I want to make fast adjustments to the motor speed to reflect changes in the system’s pressure.

If I set the timer to something long, in order to allow the slow acceleration, this will limit fast acceleration program too. But maybe I can find a setting that works for both.

How can I set this globally then?

Why do you recommend not setting the update period in the program? I can avoid a 0 setting. I would prefer to set it in the program.

Marion

Sorry, you already answered one of those questions, that it’s in the flash memory setting.

I’m worried about it getting reset by an operator too. I would really prefer to set it in the program. If you tell me the limit of how frequently I can set it, I can comply with that via the timers.

Help!

I do need to be able to set the update speed in the program just once. Any operator could override and change the simple motor controller settings.

Thanks,

Marion

The flash memory on the SMC’s microcontroller is only rated for 10,000 erase/write cycles so after you’ve changed the parameter 10,000 times things might start to go wrong. There is no limit on the frequency as far as I know, but writing the settings does take around 26 ms.

Calling the “setSmcSettings” method should be all that you need to do. If you show me your code for calling that, without ellipses, I can help you figure out why it’s not working. It will probably take more than one line because you have to construct an SmcSettings object. Be sure to include the exact text of any compiler errors or warnings in your post.

–David

Hi David:

I tried to create a code example but I was too clueless. I’m still learning VB and it’s my first object oriented programming language. Could you please give me some instructions of how to do that, or a starting point or some kind of example? Even if it’s in some other language, I could probably adapt it. Documentation of all of the available programming constructs in the pololu Smc.dll would help a lot also.

Thanks,
Marion

Hello.

The source code of Smc.dll is available in the Pololu USB SDK and there are plenty of XML documentation comments in it. The auto-complete in Visual Studio should also help you out a lot.

The C# code would be something like this:

SmcSettings s = new SmcSettings();
s.forwardLimits.maxAcceleration = 10;
s.reverseLimits.maxAcceleration = 10;
/* set any other settings you care about, or else they will get reset to their defaults */
device.setSmcSettings(s);

I think that code will be pretty much the same in Visual Basic .NET except for the first line.

–David