Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Programming Languages
C, C++ and C#
Code efficiency
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="LightPawa, post: 5173076, member: 94830"] Hello everyone, I come with a piece of code that got me into a "brawl" in the office: It's a module designed to accelerate and decelerate a motor from a PLC within a certain range of RPS. The normal speed is generated in a second module that doesn't matter here. My boss created the code and then shared with me: [B]While...[/B] //Logic protections... //Acceleration iterations... //Deceleration iterations... //Limits: [B]IF output_speed > MaxSpeedAllowed THEN [I]output_speed := MaxSpeedAllowed;[/I] END_IF; IF output_speed < MinSpeedAllowed THEN [I]output_speed := MinSpeedAllowed;[/I] END_IF; endWhile;[/B] I told him that he could improve it a lot by setting the high and low limits of speed as conditionals and then running the acceleration or declaration depending on the conditions, because this way there would be many less iterations per cycle and we would be changing the output speed only once per cycle, which is the ideal case: [B]While...[/B] //Logic protections... //Limits: [B]IF currentSpeed + speedFactor > MaxSpeedAllowed THEN currentSpeed := MaxSpeedAllowed;[/B] [B]ELSE_IF currentSpeed - SpeedFactor < MinSpeedAllowed THEN currentSpeed := MinSpeedAllowed; ELSE [/B]//Acceleration iterations... //Deceleration iterations... [B]endWhile;[/B] He got annoyed and told me to "stop asking stupid questions". I would like to have your opinion because I am getting tired of this guy and I just want to make him swallow his ego. [/QUOTE]
Verification
Post reply
Forums
Programming Languages
C, C++ and C#
Code efficiency
Top