Code Contributions to the software

thereza
Posts: 138
Joined: Fri Feb 13, 2015 11:49 pm

Re: Code Contributions to the software

Post by thereza »

As the code presentation is of personal taste, I obviously leave it in a better shape, given my taste :)

The thing that's annoying with the version of vs that i use is when you use autocomplete for something like

.videoProessing

and it fill in .videoCapture because you hit tab too soon, you have to erase the entire method to get it provide autocomplete again. would be nice if it provided it for you hit tab with a partial name, even if you didn't just type it in from the beginning. is this improved in the latest versions?

I've done a major overhaul of the code base so far. perhaps unnecesssary, but having like 10,000 lines of code in the main form handler made it hard for me to follow sometimes. so i broke it up into a number classes. i also replaced the homogoneyestimation code with some stuff I wrote (based on least squares fitting to get the rotation angle and then it's simple to find the offset -- not fully tested, but i expect it to). also most of the state is stored in datagridview objects as strings. this required a lot of parsing and valiation of variables which i didn't like. i've reimplemented everything using BindingList<objects> bound to the datagrids so that you can edit an object or the table and be assured that the data is always valid and consistent. i also used this approach to enable for an arbitrary number of measurement filter sets - so you can create one specific to each type of component in the tape if you want. the placement jobs are much easier now as you just have component objects that populate the components table and you put them into another object to group them to populate the job table. you then just pass a list of selected components to be placed.

i've modified the tinyg firmware (bitch to do given how it was written) to read from the ADC (\SS2 pin) when you read the 'adc' configuration parameter. untested but that approach should work. I've removed support for spi2 in the process (identical to spi1 but used \ss2 instead of \ss1). I will use this to interface with the pressure sensor that I've installed to detect if a pickup was successful or not.

I've changed the UI so that the cameras are always on so you can see what's gong on - i notice sometimes i have to adjust the thersholds on the filters - not sure why - but it's easy to spot that when you see how the computations are being made. It's also in a separate window than the main one. I've consolidated the calibration functions into a new page, and broke out three classes

VideoCapture -> VideoProcessing
and a static class VideoDetection


the code is still too rough to release but it's coming together ok. Once it's operational again, I will start adding additional functions like using the upward camera to determine how off center the pickup of a component was - and to correct for it when it places it. This includes passives like 0402s. I posted this but have not had time to follow up

http://stackoverflow.com/questions/3065 ... of-objects

-r
JuKu
Site Admin
Posts: 1114
Joined: Thu Feb 14, 2013 3:06 pm
Location: Tampere, Finland
Contact:

Re: Code Contributions to the software

Post by JuKu »

As the comments are mostly towards thereza's version, I'm addressing this to you (you==thereza). Still, this is for everyone to comment:

I'm now looking at your version, and I agree: It is much better shape than mine, enough so that I'm thinking of adding my new stuff to that, not the other way around. I'm tempted to call that as v2, and the current version v1.

There are lots of pros. It is obviously written by much more proficient software professional than I am. (I consider myself just as a designer that can do software as well.):

- maintaining v2 would be much easier
- much cleaner
- easier to add features
- a really great contributor working on it, at least now
- better user interface

Not many cons:

- Data files (tapes) not compatible with v1. Fixable by a converter routine, or maybe people wouldn't mind that much redoing the tape definitions?
- Not quite there yet. On the other hand, nor was mine at all areas...
- I don't get it at all areas, your software thinking is better than mine. I guess I could learn it, if at some point I need to maintain it without thereza.
- I don't like the formatting, but I can live with it, with a condition*

Rest are details:
- Some behavior that you specifically wrote in is not to my liking, but no big deals and mater of opinion anyway.
- The estimation routine seems to ignore scaling, and that is a mistake, imo. The board manufacture's mm's are not always the same as the machine's mm's, especially when the board is big. the difference may not be big, but close is not good enough for SMD.
- Few bugs. Read: only a few, likely less that I have now, certainly less than we would have if continuing my route, but there are a few.

*: About formatting: Your formatting would not be my first choice, but one code style in a project is better than many. It would be nice if there would be a tool or other way to reformat everything to some standard before committing back, letting everyone code in their familiar style. I didn't find one right away, but that doesn't mean such tool isn't out there. I did found the next best option: https://visualstudiogallery.msdn.micros ... 567e543c58. This allows storing VS formatting options per project, so everyone can have a settings file that loads formatting settings they have used 20 years and love, and only use LitePlacer formatting when working on it. So, would you be so kind to install that extension and commit the settings file so I can use your settings? With some file manipulation, that extension would even allow going back and forth with styles, if someone really can't stand a certain style.

Anyway, I really appreciate and I'm very thankful for your contribution. Big, big thank you for this.
mawa
Posts: 139
Joined: Wed Jun 10, 2015 1:23 pm
Location: Near Hamburg, Germany

Re: Code Contributions to the software

Post by mawa »

thereza wrote:As the code presentation is of personal taste, I obviously leave it in a better shape, given my taste :)
-r
If we think of this code as open source individual "taste" is IMO not advised.

therezas reformatting can make it very difficult to diff the files to see what really important things have changed.

There are coding standards for C# .NET out on the web since many years. And I do not think bracing is the main topic in these standards.

In my business, as I stated earlier, I write C# code for living. We use more than a dozen of open source libraries and components and all of them comply to the given "standard".

Heres are a couple of links to some of many web sites that deal with that issue:

Lance Hunts C# Coding Standard for .NET

http://se.inf.ethz.ch/old/teaching/ss20 ... ndards.pdf

Philips Healthcare - C# Coding Standard:

http://www.tiobe.com/content/paperinfo/gemrcsharpcs.pdf

Microsoft has it too: search for C# Coding Conventions (C# Programming Guide)

Aviva has a down-loadable pdf:

https://csharpguidelines.codeplex.com/


Looking at Juhas source code there are some issues that could be improved:

what it the sense for the _m postfix?

please use public & private everywhere

Don't use Pascal Case for private fields.

use string.Format for string concatenation:

instead of

Code: Select all

 DisplayText("Version: " + version.ToString() + ", build date: " + buildDateTime.ToString());
use:

Code: Select all

 DisplayText(string.Format("Version: {0}, build date: {1}", version.ToString(), buildDateTime));

don't use _ in method names: instead of Update_xpos() use UpdateXPos()

Try to use Verb-Object naming:

difficult to understand:

Code: Select all

public void XY(double X, double Y)
easy to understand:

Code: Select all

public void MoveToXY(double X, double Y)
or even:

Code: Select all

public void MoveTo(double X, double Y)

Try to use a single property for boolean type objects instead of individual methods.

For example instead of VacuumOn(), VacuumOff() define a bool property Vacuum and use Vacuum = true, Vacuum = false; Then the setter prevents redundant code.

Instead of Camera.IsRunning() define a bool property IsRunning with a getter and then you can just write UpCamera.IsRunning.

Just a couple of suggestions.
best regards
Manfred
thereza
Posts: 138
Joined: Fri Feb 13, 2015 11:49 pm

Re: Code Contributions to the software

Post by thereza »

i can write my standards down if that helps you. or why don't you make your own version the way you like it and not not use the code i wrote.
JuKu
Site Admin
Posts: 1114
Joined: Thu Feb 14, 2013 3:06 pm
Location: Tampere, Finland
Contact:

Re: Code Contributions to the software

Post by JuKu »

Your comments are noted. As said, I consider myself as a designer who knows how to code. In other words, I'm not really a programmer, I'm just pretending. I do value the opinions and feedback from professionals.

Using exeptions vs. catching errors when they occur is a philosophical and unsolved (unsolvable?) discussion, let's not start that here. I'm catching errors when and where they occur, and return a bool to indicate success/failure. The _m suffix means a function has already has given a message to the user. So, if a _m function returns false, the caller will also return false and I know the user has already been notified, there is no need to raise another dialog. This way, the true error is noted as soon it happens and the error condition travels up without raising more error messages.
JuKu
Site Admin
Posts: 1114
Joined: Thu Feb 14, 2013 3:06 pm
Location: Tampere, Finland
Contact:

Re: Code Contributions to the software

Post by JuKu »

thereza wrote:i can write my standards down if that helps you. or why don't you make your own version the way you like it and not not use the code i wrote.
I'm fine with any coding style. For me, it is not much more important than font and style in other writing. When reading, I adapt fast. The thing I'm somewhat against is to have different style from one sentence or chapter/routine to another. That does make software and prose annoying and harder to read. And since VS automatically completes structures using a set style, I suggested the tool that allows using your style in your code and still keep the style I've already used on other stuff.

After all, if a different style of braces makes something significantly harder to read, the code wasn't that great to begin with. (Your code is inherently more clear than mine, btw.)
mawa
Posts: 139
Joined: Wed Jun 10, 2015 1:23 pm
Location: Near Hamburg, Germany

Re: Code Contributions to the software

Post by mawa »

thereza wrote:i can write my standards down if that helps you. or why don't you make your own version the way you like it and not not use the code i wrote.
Sorry, thereza, that is NOT the sense of open software code and team programming!

Without sticking to a proven design standard many great open source applications would not have come to their current level.

We should concentrate on refining the LitePlacer solution with easy to merge code modifications and additions.
best regards
Manfred
thereza
Posts: 138
Joined: Fri Feb 13, 2015 11:49 pm

Re: Code Contributions to the software

Post by thereza »

o·pen-source
adjective COMPUTING
denoting software for which the original source code is made freely available and may be redistributed and modified.


open source means i can do whatever i want with it. not that i have to conform to any standards, especially if i disagree with said standards. if i was forced to conform, then i wouldn't do it at all and you would be stuck in the same place - not using my code.

also, a standard is just a set of rules. i code by my unpublished standard which i feel is superior to the standards that you've pointed to. i strongly feel that code must maintain an aesthetic appeal where form and function are combined. most published standards are designed to conform with the least common denominator which means that no effort is spent on the aesthetic of the code. I don't code for mediocrity.

my final point is i could give a flying f* what you think. if you paid me money for my time, then that would be different. but you don't. you're an unkown person behind a computer trying to dictate how i spend my (not) free time and effort and energy. I didn't agree to anything when I decided to enhance the software. I chose to do it because i wanted to. what would make you think i would care what you thought?

and just to be clear, about 80% of the code has now been reworked so your argument of being able to do diffs is meaningless. trying to back-port my code will be futile given the breadth of changes. i'm sure JuKa doesn't agree with some of my choices (i.e. moving away from passing and populating references as it lacks the aesthetic appeal I want) but he can choose to continue using his code the way he likes to -- one of the nice things about open source.
thereza
Posts: 138
Joined: Fri Feb 13, 2015 11:49 pm

Re: Code Contributions to the software

Post by thereza »

JuKu wrote: After all, if a different style of braces makes something significantly harder to read, the code wasn't that great to begin with. (Your code is inherently more clear than mine, btw.)
Thanks. I'm trying to be consistent with the coding style. I think the biggest change is adding the class 'PartLocation' which I've been extending to act as a glue between everything and that's made things a lot cleaner/easier.

One thing that's been bugging me (mostly because of the number of lines it uses) is the code to map the machine parameters to all the form textfields you have. it's just not aesthetic and bulky. I read on how to do data-bindings of form variables to variables - so it can be done in a cleaner way - but it will take more time than I want to spend cleaning it up. If done on a per-variable basis, it would also be bulky so it needs to be done programatically using reflection to apply the mapping in an automated fashion.

The only other issue I have is that with your code, the cameras would always shut down and restart. With one of my cameras, if it doesn't start up, I have to quit and restart 3 times, and it always works on the 3rd time. what advice do you have on stopping/starting the cameras so it works more consistently.
thereza
Posts: 138
Joined: Fri Feb 13, 2015 11:49 pm

Re: Code Contributions to the software

Post by thereza »

JuKa,

one other question - the metal thing that is supposed to keep the needle pushed back doesn't do anything for me. adding rotational slack compensation seems to work fine though. is my metal thing not springy enough? what are your thoughts on the rotational slack compensation?
Post Reply