Go to Post Problem with microprocessors: they do exactly what you tell them to do - KenWittlief [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rating: Thread Rating: 75 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #13   Spotlight this post!  
Unread 02-16-2009, 08:59 AM
Kruuzr Kruuzr is offline
Mentor - electrical, software
AKA: Steve Cote
FRC #1922 (Ozram)
Team Role: Engineer
 
Join Date: Feb 2006
Rookie Year: 2006
Location: Henniker, NH
Posts: 33
Kruuzr has a spectacular aura aboutKruuzr has a spectacular aura about
Re: WPILib PID controller object

Quote:
Originally Posted by SlimBoJones View Post
We've done pretty much exactly the same thing as you did here. I think we're running into a small concurrency problem though, and would like to hear from you as well.

As once in a blue moon your camera "spaz" while it is tracking?

Very rarely, but often enough to make it a pain, our camera tracker will move out of position quickly then recover for no apparent reason.

I think it's because of a classic concurrency issue where source is being read and written at the same time.

The PID controller runs in a separate task, and so potentially both SetSource and PIDGet could be called at the same time.

Would any more experienced programmers out there recommend locks? And if so, how would you implement them in the quoted code?
If your code in SetSource consists of just an assignment statement, it's probably not a concurrency issue. Although it's poor style to not protect it with a semaphore, a simple assignment of an int or float is usually what's called an 'atomic' operation, which means that it would not be interrupted in the middle by a task switch. (It happens in one machine language operation) I would look elsewhere for the cause.
If you have more than one line in SetSource (or if you want to get used to how to do multithreaded programming) you need to protect the function with a semaphore. The 'C programming guide for FRC.pdf' page 78 discusses how to do this. It's not hard, just a matter of adding a line at the beginning and end of your function.

Steve C
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
void* pointer to object in C++ byteit101 C/C++ 6 01-14-2009 05:15 PM
UI Board Object Specs 3DWolf Control System 2 12-10-2008 04:13 PM
Demo: Simple robot arm with a PID controller mtomczak Programming 1 01-17-2008 02:17 AM
rangefinding/object detection sciguy125 Electrical 14 01-13-2008 08:36 PM
Object Enablers SherryG Inventor 1 04-07-2006 10:01 AM


All times are GMT -5. The time now is 09:24 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi