Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8485309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:36:25+00:00 2026-06-10T20:36:25+00:00

I am working on a motion control system, and will have at least 5

  • 0

I am working on a motion control system, and will have at least 5 motors, each with parameters such as “gearbox ratio”, “ticks per rev” “Kp”, “Ki”, “Kd”, etc. that will be referenced upon construction of instances of the motors.

My question to StackOverflow is how should I organize these numbers? I know this is likely a preferential thing, but being new to coding I figure I could get some good opinions from you.

The three approaches I immediately see are as follows:

  1. Write in the call to the constructor, either via variables or numbers– PROS: limited coding, could be implemented in a way that it’s easy to change, but possibly harder than #define’s

  2. Use #define’s to accomplish similar to above — PROS: least coding, easy to change (assuming you want to look at the source code)

  3. Load a file (possibly named “motorparameters.txt”) and load the parameters into an array and populate from that array. If I really wanted to I could add a GUI approach to changing this file rather than manual. — PROS:easiest to change without diving into source code.

These parameters could change over time, and while there are other coders at the company, I would like to leave it in a way that’s easy to configure. Do any of you see a particular benefit of #define vs. variables? I have a “constants.h” file already that I could easily add the #defines to, or I could add variables near the call to the constructor.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:36:26+00:00Added an answer on June 10, 2026 at 8:36 pm

    Sounds to me like the thing to do is:

    • Write a flexible motor class, that can handle any values (within reason), even though there are only 5 different sets of values you currently care about.

    • Define a component that returns the “right” values for the 5 motors in your system (or that constructs the 5 motors for your system using the “right values”)

    • Initially implement that component to use some hard-coded values out of a header file

    • Retain the option to replace that component in future with an implementation of the same API, but that reads values out of a resource file, text file, XML file, GUI interaction with the user, off the internet, by making queries to the hardware to find out what motors it thinks it has, whatever.

    I say this on the basis that you minimize expected effort by putting in a point of customizability where you suspect you’ll want one (to prevent a lot of work when you change it later), but implement using the simplest thing that satisfies your current certain requirements.

    Some people might say that it’s not actually worth doing the typing (a) to define the component, better just to construct 5 motors in main() (b) to use constants from a header file, better just to type numeric literals in main(). The (b) people are widely despised as peddlers of “magic constants” (which doesn’t mean they’re necessarily wrong about relative total programming time by implementer and future maintainers, they just probably are) and the (a) people divide opinion. I tend to figure that defining this kind of thing takes a few minutes, so I don’t really care whether it’s worth it or not. Loading the values out of a file involves specifying a file format that I might regret as soon as I encounter a real reason to customize, so personally I can’t be bothered with that until the requirement arises.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jQuery slider in working motion with previous and next buttons. The
I am working on a system that will analyze video frames from multiple cameras.
We are working with some new Cutting Tools that can have it's hardware parameters
Working with Reporting Services 2008 r2. So here's my issue: We have 5 reports
Working on game where plates will be falling from top to bottom. Some plates
Alright, now I am working on a small derp-ish game based on Brownian motion,
I have this inside my viewController: - (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event { if (event.type ==
I'm hacking a security system DVR so I can add motion capture and other
I am working on a program that is a projectile motion simulation with a
So, I'm working on a project for a motion-graphics class, wherein they teach us

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.