void function that returns an equation? or anything?

So for my next code for school we are required to use a function to set rpm of a servo using an equation . We were specifically instructed to use void as the function specifier yet we want it to return something. My professors explanation was that we are asking it to return an equation not a value. This makes no sense to me. As I understand it the void tells the function not to return anything?

Any thoughts?

golightlyj: This makes no sense to me.

You are not alone.

As I understand it the void tells the function not to return anything?

Correct.

Any thoughts?

There are two other ways to get data out of a function. Maybe the professor wants you to explore those.

(At moments like these I am very grateful to have had Dr. Whitehead as my professor for Structured Programming.)

There are two other ways to get data out of a function.

This raises more questions than it answers. Any chance you could tell me where I might do some reading on the matter?

UPDATE So I've been reading. Am I to understand that I can just use the function to save a value to memory without technically returning data? If so, what advantage does this have vs just returning data?

Am I to understand that I can just use the function to save a value to memory without technically returning data?

That would be my take, using a global variable and sticking the answer into that. But I have no idea what this means:

we are asking it to return an equation not a value.

I think the only advantage of assigning the answer to a variable over a return, is that you can do as many calcs as you like and as many assignments to variables in a function, but it may only return one.

As to this:

set rpm of a servo

..... the purists will frown. A servo doesn't have rpm, it goes to a certain position. If the servo is modded so that it rotates, and the pulse you send it is now the speed, is it still a servo? At least one member here uses the phrase "continuous rotation ex-servo".

That raises another question: for one of those (ex-) servos, there is as far as I know, no specific correlation between the pulse width and the rotation speed. I suspect the pulse vs speed will depend on the mechanics of the servo, and may even vary across instances of the same model. So how do you know what pulse width to send it for a required rpm?

From a practical perspective these two are the nearly same... https://www.google.com/search?q=c%2B%2B%20pass%20by%20reference https://www.google.com/search?q=c%2B%2B%20pass%20by%20pointer

Probably not what the professor had in mind but certainly worth mentioning... https://www.google.com/search?q=c%2B%2B+global+data

. We were specifically instructed to use void as the function specifier yet we want it to return something.

As stated above, use references.

void something( int &whatYouNeedToReturn) { 
    whatYouNeedToReturn = 999;
}

int theReturn;
something(theReturn);

// theReturn now equals 999

My professors explanation was that we are asking it to return an equation not a value

Sounds like he wants you to return a function pointer.

As I understand it the void tells the function not to return anything?

The "void" tells the function not to return a value via the function name. There are other ways of getting values out of a function.

..... the purists will frown. A servo doesn't have rpm, it goes to a certain position. If the servo is modded so that it rotates, and the pulse you send it is now the speed, is it still a servo? At least one member here uses the phrase "continuous rotation ex-servo".

That raises another question: for one of those (ex-) servos, there is as far as I know, no specific correlation between the pulse width and the rotation speed. I suspect the pulse vs speed will depend on the mechanics of the servo, and may even vary across instances of the same model. So how do you know what pulse width to send it for a required rpm?

To begin, my take on the definition of a servo is: a motor that uses an signal to control speed. The servo that only goes to a certain position and back is a specialized type of servo?

As for the RPM, we took several measurements of the RPM at different pulse width values, put them into excel and derived an equation that allows us to input RPM and the program changes that into the appropriate pulse width value based on our equation.

As for pointers, we have not gotten that far yet. I think that will be this weeks topic.

Thanks for the help guys! I will check out those websites Coding Badly

As for the RPM, we took several measurements of the RPM at different pulse width values, put them into excel and derived an equation that allows us to input RPM and the program changes that into the appropriate pulse width value based on our equation.

That makes it quite sensible to have a function SetRPM that takes RPM as a parameter and instructs a servo accordingly. It would be reasonable that such a function return nothing, as your professor suggested. What do you want to return?

In reality, SetRPM would probably take another parameter specifying which servo to operate on too.

The servo that only goes to a certain position and back is a specialized type of servo?

No that is "A" servo; the other kind is a converted "ex" servo.

But be that as it may, if you have a rpm vs pulse width thingy, that's cool. I'd be interested to see the curve. I've never used an "ex" servo, but always assumed the curve was kind of linear. How will you know, though, that it actually got to the right speed? You took measurements under certain load conditions, and under heavier conditions it will take longer to get to speed, and indeed may never get there.

To wildbill

That makes it quite sensible to have a function SetRPM that takes RPM as a parameter and instructs a servo accordingly. It would be reasonable that such a function return nothing, as your professor suggested. What do you want to return?

I think I might be starting to grasp this. So, I'm not trying to return a value, I am just trying to change a parameter?

In reality, SetRPM would probably take another parameter specifying which servo to operate on too.

Yes, 2 independent servos

To JimboZA

if you have a rpm vs pulse width thingy, that's cool. I'd be interested to see the curve. I've never used an "ex" servo, but always assumed the curve was kind of linear.How will you know, though, that it actually got to the right speed? You took measurements under certain load conditions, and under heavier conditions it will take longer to get to speed, and indeed may never get there.

The line is linear. For whatever reason I can't seem to paste the graph. As for load conditions and whatnot, this is a beginner level class, we are just programming parallax robots for now. Our semester project is to design and build our own that has to follow a line on the floor.

You need to work on your tags 8)... the opening on has no / at either end.... easiest to select the text and hit the quote icon above the :*

You might fins this page about functions handy: http://arduino.cc/en/Reference/FunctionDeclaration

I have read that reference already jimboZA. The problem reading does not mean understanding all of what is has to say.