PWM control with mathematical function

Status
Not open for further replies.

tnay

New Member
Hi guys,

I have a big question here, which i think, theoritical this can be achieve, but i am not sure how to do it. Can we send out PWM frequency as a mathematical function? Meaning that the frequency of PWM change constantly from 0 deg to 180 deg, following a predefine function.

Basically, my project is to control a 3-dofs robotic arms, where three servos is responsible for the shoulder (2 servos) and elbow (1 servo). When i specify the path of the end effector (gripper), all three servo will work simultaneously to follow the path, at predefine speed. In short, the servos will rotate with a mathematical expression, can this be done with PIC? how would i do it? say a simple function, y = asin (x), where y is the rate of change for the servo (deg) which correspond to the frequency of servo, while x is the speed of the path is x-direction.
 
All the servo understands is that a specific pulse width sets it to a specific place - it's up to your programming to move it where you want. You could certainly use a mathematical formula if you wanted - and convert the output values to the corresponding pulse widths.
 
If you are using something like a highly controlled arm, it might more effective to just replace the PCB inside the servo altogether so you can "externalize" the servo's internal feedback loop not to mention adding things like serial interfaces so you can set-and-forget the servos motion parameters like speed and position.

www.openservo.com

If the servo's feedback loop remains internal, the actual speed it travels at is pretty much at the mercy of the load it's handling.

The alternative is to add route the potentiometer outside the case and have it being monitored by both the servo and your control electronics so you can directly monitor the actual speed of the servo and compensate by decreasing or increasing the PWM.
 
Last edited:
Yes, that kind of positioning can be done with a PIC. I don't know how to go about implementing it, but it would be possible, albiet not at a very high refresh rate, and the X/Y/Z positioning wouldn't be linear. You'd need at least 16 bit PWM per channel to do any kind of acurate positioning. What kind of servos are you using? Hobby servos? You can feed the output of the positioning pot into the micro controller to 'externalize' the loop and let the micro controller itself close it. None of this is easy, or for someone without a decent amount of knowledge with trig.
 
Sceadwian said:
You'd need at least 16 bit PWM per channel to do any kind of acurate positioning. What kind of servos are you using? Hobby servos?.

Pretty pointless using 16 bits with standard RC servos - they don't have anywhere near that resolution.
 
16 bits full scale for the servo pulse width yeah, but if the PWM frequency is 100hz you're only going to get about 11-12 bits out of the full 16 bit duty cycle that is going to result in a valid servo pulse. The other bits are lost on shorter and longer than servo length pulses. 10bits is what digital RC systems use so 12 bits would be a good number to give you a saftey margin of 2-3 times the maximum required precision.
 
You think a standard radio control servo has resolution to 1024 steps?, I seriously doubt it!.
 
I thought they did...just not the accuracy to make use of the resolution.
 
Standard hobby servo's are analog devices, their resolution is essentially infinite, the dead band in the feedback loop and the geartrain slop are the only thing that limit precision. You don't typically actually need that much but I've heard posts on RC forums that especially pattern flyers can tell the difference between 8 and 10 bit PCM systems. The resolution of the signal you send it is going to be most noticeble when the servo is under heavy load because the force exerted by the servo is directly proportionate to the difference in the actual servo position and the error signal. 10 bits over 8 is going to give you a LOT more fine control over the torque applied to a heavily loaded flight surface.
 
Hi guys, thanks for the reply. Actually the 3 dofs robotic arms is for my 4-legged robot. Each of the legs consist 3 servos, so i need to control 12 servos at every instant to make it walk. So each leg actually resemble a 3-dof robotic arm. I plan to control the arm (or leg) by adjusting the X/Y/Z direction and the servo will move according to achieve that. The governing equations are complicated, which make me worry about its responsiveness.

I have order samples of 16F877 and 16F458 as I have a book about C programming which used these chips. I have also place order for 12 hobby servos, hitec HS-322HD. These servos have very low torque rating, and the working envelope of the legs is constraint my it. This mean at some point during the motion, it will sustain maximum loading. I would definitely prefer higher bits if it gives better control.

I understand that servo position is proportional to pulse width, and it will go to the position as fast as possible. Then how do i control the speed without replacing the PCB inside the servo? I am interested in OpenServo, but i need to check with my institute if we have the programmer. Any suggestion or advice?
 
As long as you are using the servo's drive circuitry, whether or not you externalize the servo's internalfeedback loop, you will need to sit down and empirically figure out the servo's response parameters. THis should have been covered in your controls systems class.

The ENTIRE servo in this case is the plant (even though inside the servo the circuit is the controller and the motor is the plant), since you have no access to the inside of the servo (you can, but then you can't be lazy). YOur external circuitry is the controller in this case and accounts for all this.

It's like making a robotic arm to throw a ball (controlling the servo)- you have no control over how fast the ball will fall due to gravity (how the servo electronics drive the motor). But you can make control circuitry to account for this. As far as you are concerned, the electronics inside the servo are "basic physical laws" that cannot be altered- and your controller will have to deal with them.

Even if you replaced the servo circuitry to interface directly with the motor, you still have no control over the mechanics of the motor (like it's speed, acceleration, and torque at that instant). Your controller would have to deal with all these uncontrollable parameters again. One thing that can make it easier is if your application is very slow compared to the plant's (overall servo's) response time, then you can assume the response time is instaneous for your purposes. Sure, the overall servo motor is slower responding than the motor itself, but does your robot leg really move so fast that it's comparable to the response time of the servo? If it doesn't, you don't need to worry about all this (or you can slow down your leg motions so this holds true).
 
Last edited:
There are plenty of examples of servo powered walking robots on the net, normal servo's work fine, and are often only controlled by a BASIC Stamp!, but using a servo driver boad (essentially a PIC that receives serial information and generates the pulses for all the servos).
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…