LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

PID control with an H bridge

Solved!
Go to solution

Hi everyone,

 

I have been working on a project with labview for the last few months now and I have reached a point where I am in need of some assistance.

 

Basically, this next part of my project requires me to drive a linear actuator to apply a force to the end of a shaft, with a load cell in between the actuator and shaft, providing me with the actual force applied.

I need to use a PID controller to maintain a constant specified weight onto the end of the shaft, this in itself should be simple but I have an issue with the way the actuator is driven.

 

The actuator is being driven via an H bridge that has 3 seperate inputs to drive the actuator:

 

direction = logic high/low 5v high 0v low

break= logic high/low 5v high 0v low

Speed= Pulse width modulation

 

My plan was to use a basic PID controller to adjust the PWM going into the H-bridge by adjusting its duty cycle between 0.10 (fast) 0.90(slow) and then using basic comparison functions between the set point and process variable to control the logic to direction and break. So for example.....

 

I want it to apply 5kg onto the end of the shaft

my set point is 5 and the variable is 0 so labview applies a logic high to direction (to go forward) and logic low to break (to let it move) and the PWM is adjusted to zero in on the set point.

 

I cannot get this to work however and was wondering if there was a better way to do this?

 

I appreciate that this may seem unclear, so i hope I have explained it well enough!

 

Many thanks

HCook

0 Kudos
Message 1 of 8
(2,497 Views)

Hey

 

Can you describe what is happening if its not working how you expected? Your thought process seems to be sound so my guess is that something in your code isn't doing quite what you think it is. Could you post the code that is driving your h bridge for a look into what's going on?

 

Cheers

Matthew Trott
Applications Engineer
National Instruments UK
www.ni.com/ask
0 Kudos
Message 2 of 8
(2,468 Views)

Hi Matthew,

 

Thanks for getting back to me, I will post a copy of my code in the next couple of days when Im back on the project.

 

Many thanks

 

Harry

0 Kudos
Message 3 of 8
(2,447 Views)

Hi Matthew,

 

Right, I have got the logic comparison bit of the PID working and now have the actuator moving forwards and backwards as I apply and remove weight to the load cell.

 

However I cannot get the actual PID controller to work with the system to adjust the duty cycle of the pulse width modulation. I can see two issues:

 

Firstly, it keeps telling me that the task I have created to output the PWM to the H bridge (WOB speed) is reserved and will not work, I dont know why its telling me this as the task is not referenced anywhere else in my programme. I do however switch the source of the duty cycle between a manual input and the PID controller while the programme is running.

 

The second issue Im having is that the PID controller adjusts the duty cycle to quickly and says that the PWM must complete a full cycle before the duty cycle can be adjusted again, this also happens if I use a dial to adjust the duty cycle instead of a number indicator.

 

I have attached the PID section of my code.

 

Many thanks

 

Harry

0 Kudos
Message 4 of 8
(2,435 Views)

I'm not sure what you're trying to accomplish with this VI, but it can't possibly be working properly.  Have you tried running it with execution highlighting turned on?  If you start the program in PID control mode, the loop that adjusts the PWM won't execute until you push the stop button (due to the wire between the loops) so you'll get no control.  Are you changing the "Weight on Bit" value manually?  I don't see any other way it would change.  Why so many loops?  Why are the front panel controls and indicators unused in favor of local variables?

 

Try rewriting this as a single while loop.  Put appropriate waits inside the loop, don't let it spin as fast as possible (as your non-functional PID does now).

 

Which function is reporting that the task is reserved?  What is the full text of the error message?

0 Kudos
Message 5 of 8
(2,425 Views)

Hello,

 

Thank you for very much for your reply.

 

I really should have explained this better, but I only had a few minutes to post my code. I should also mention that Im teaching myself labview, so Im sure I could do this a lot better.

 

OK, so here is whats happening...

 

This is just a secttion of my code, as Im not allowed to upload the whole programme.

 

This section is meant to control the weight being applied onto the end of a shaft that is defined by the user.

 

By flicking between auto and manual the user can choose between the PID and comparison moving the actuator or themselves manually.

The two express vis that are outputting an analog voltage are to provide the logic to the h bridge.

To give me Proportional control, I have simply used a comparison function to look at the weight on bit i have requested (elsewhere in the programme and hence the local variable) and the actual weight signal from a loadcell being brought into labview from an anolog input. So for example, If i request 2kg then the comparison between the two signals then tells the h bridge to move the actuator to apply more or less wait depending on the signal.

 

I have got this bit working fine.

Now, the speed with which the actuator needs to move, must be continuosly adjusted to provide a precise adjustment to the weight and I wanted to do this by continuosly adjusting the duty cycle of the PWM through the PID. Thank you for pointing out the loop issue, preventing the PID from passing on the adjustment, I had not spotted this!

I will re build the code and condense it down into a smaller number of loops.

 

The WOB speed task, which is outputting the PWM to the h bridge keeps telling me that the specified resource is reserved and will not function after my inital run. Does this have anything to do with the PID not working ?

 

Also, when I run the programme in manual mode, where by I move the actuator manually and adjust the weight based on the load cell signal, I get an error when I adjust the duty cycle. It informs me that the PWM must complete a full cycle before the duty cycle can be adjusted. Now the rate at which im changing the duty cycle manually is no where near the same speed a PID may adjust it and therefore I can see myself having the same problem in auto mode.

 

Thank you for your help!

 

Hcook

0 Kudos
Message 6 of 8
(2,408 Views)
Solution
Accepted by topic author hcook

hcook wrote:

The WOB speed task, which is outputting the PWM to the h bridge keeps telling me that the specified resource is reserved and will not function after my inital run. Does this have anything to do with the PID not working ?


Unlikely to be related to the PID not working.  Which of the DAQmx functions returns the error?  My guess is it's DAQmx Timing, which is probably not needed.  The task should already be configured for Continuous Samples in the project or in Measurement and Automation Explorer.


hcook wrote: 

Also, when I run the programme in manual mode, where by I move the actuator manually and adjust the weight based on the load cell signal, I get an error when I adjust the duty cycle. It informs me that the PWM must complete a full cycle before the duty cycle can be adjusted. Now the rate at which im changing the duty cycle manually is no where near the same speed a PID may adjust it and therefore I can see myself having the same problem in auto mode.


What's your PWM frequency?  Your loop rate should be less than that to ensure that you don't get this error.  Right now you're running the loop at 100hz, so if the PWM is less than that, and you're using a slider (which can generate a lot of new values quickly as you move it) to control the duty cycle, you're likely to see this error.

 

What's the purpose of DAQmx Task Done in that loop?

0 Kudos
Message 7 of 8
(2,392 Views)

Sorted!

 

Thank you very much for your help, you were absolutely right about the frequency and the timing of the pwm loop, it has completely sorted the problems I have been having. This is also the case for the daqmx error which is now no longer occuring.

 

Now ive just got to tune the dam thing 😛

 

Many thanks

 

Hcook

0 Kudos
Message 8 of 8
(2,373 Views)