My method has always been as follows:
1) Define the scope and/or complexity of the project. In other words, I need to program ten conveyors, five solenoids, one HMI, and twenty pushbuttons/pilot lights.
2) Make some kind of educated guess as to what each will take. For example, I can write the logic for ten conveyors in twenty hours.
3) The most important step: Track your time accurately. Be fair to yourself. If you get stuck on a strange problem that will not happen again, for example you are unfamiliar with how to use a certain instruction, don't count that against you for this step.
4) Compare your estimate to actual.
5) Make adjustments as required.
Over a longer period of time, you will get darn good at estimating your programming time.
However, when I was a consultant, I found my total time to break down as follows:
30% Electrical design - generate CAD drawings of schematics and layouts
30% PLC and HMI programming
40% Start-up and troubleshooting - This was usually due to a mechanical machine delay issue. For example, if a double acting solenoid is wired with the A and B coils swapped, I can move a wire on a terminal strip quick. If the pipefitter has to swap hard-piped hydraulic tubes, we're talking two hours.
I always had enough time to make my software changes while the mechanical people made their fixes... In fact, I used to leave myself a little something to do to kill time while the machine problems were resolved, such as fault logic implementation.