software and hardware correspondances

Hi,

  • My first application with Arduino is a servomotor driven by a UNO card. One of the analog inputs is driven by a potentiometer. Then the voltages corresponding to the resistor values will be used to modify the angular positions of the output shaft Let's say R1 correspond to alfa 1 and R2 correspond to alfa 2.

  • The software ( found in the literature) uses the following instructions ( loop section )

val = analogRead(analogpin) ;
val = map(val,120,50010,60) ; // R1 > alfa1 =10°, R2 > alfa2 = 60°
myservo.write (val) ;
delay (100);

This is clear, I understand the logic but it seems to me that the code is not dependant of the characteristics of the servomotor ( as hardware) such duration of pulses for a given angle, frequency, reference angle etc . Are they standard values all included then in the library servo.h ?

Thanks in advance

The values are not really standard for normal servos. If you want specific angles you will have to tune the values for your servos. E.g. for write(0) to write(180) some servos only move about 90-100 degrees and almost none will move a full 180 degrees.

It's generally better to use writeMicroseconds() which gives you finer control of the servo positioning and doesn't fool you into thinking write(angle) actually means what it sounds like.

Steve

Try this instead:

val = map(val,0,1023,10,60) ;

Hi,

Thanks to both of you, but my question is not may be crystal clear :

  • Starting from the fact that the potentiometer value will varie from R1 to R2 ( and not from 0 to Rx ), it should idealy correspond to min/max values of alfa such alfa1/alfa2 (output) . The total angular variation expected shall be ~100°.
    So I understand that I need first to select the proper servomotor covering this range and mechanicaly set the servo such that alfa1 is close to the position zero of it ( to be sure that alfa2 will be inside the servo range).
    If now if I use « writeMicrosecond( ) » I need to get the data pulse duration( angle) from the manufacturer or perform the measurements (calibration).

  • Now concerning the map instruction, knowing that potentiometer min/max values are R1/R2, the gain of the system shall be (alfa2-alfa1) / (R2-R1)
    If I use « val = map(val,0,1023,10,60) ; » I do not see how R1 will be associated to"0" and R2 to "1023" value or the gain will be lower ?

Note : I don't have yet the sermotor to make tests and try to have a good understanding of the instructions first...

The range 0 to 1023 assumes you are using the full range of the potentiometer. If you plan to restrict the potentiometer movement to part of its range you will need to find out what is the lowest and highest values for that range and substitute those for 0 and 1023.

Just write a short program with like this

void loop() {
  potVal = analogRead(potPin);
  Serial.print(potVal);
  delay(300);
}

so you can see what values you get for different positions of the potentiometer.

...R

Your basic understanding seems correct. If you have tested the potentiometer voltage divider and it only produce values from the analogread() between R1 and R2 (rather than the full 0-5V which reads as 0 and 1023) and you want the servo to move between Alpha1 and Alpha2 (where these are pulse lengths that send the servo to the desired positions) then map(val, R1, R2, Alpha1,Alpha2) should work.

But you won't find the exact values of Alpha1 and Alpha2 from the servo specification. Hobby servos are not specified in that detail nor are they that accurate. You calibrate by testing.

Steve

Hi,

Thanks again

Following your explanations, my today understanding is :

The UNO card and associated instructions ( map/write) delivers a max pulse duration de 2 ms corresponding to the 1023 digital value.

The servomotor units are designed for a max pulse duration 2ms for let'say 100° maximum angular range ( the standardisation being at that level .)

I can then define by test ( using Robin program ) the corresponding R2 / R1 values.
I think they have to be as close as possible of min and max potentiometer values to take benefit of the full range (0-1023 ) and then have in final a good chance to get a better accuracy.
By the way I hope to get « not too bad » performances because I intend to use a servo « mammoth 38055 » given for industrial applications.

So finally , the instruction map ( val, R1, R2, Alpha1,Alpha2) » takes then into account in some way the hardware characteristics as far as the 2ms max pulse duration delivered by the UNO card corresponds to the max angular range of the servo unit.

You need to separate your understanding into two parts.

On the one hand there are values detected by analogRead() when you adjust the potentiometer

On the other hand there are pulses with varying widths that must be sent to the servo to make it it move to a particular angle.

A potentiometer normally varies the voltage on its centre pin between 0v and 5v (assuming you are using a 5v Arduino). When the voltage is 0v analogRead() will return 0 and when the voltage is 5v it will return 1023.

The standard way in which Servos work is that they require a pulse every 20 millisecs and the width of the pulse should vary from 1 millisec to 2 millisecs (1000 microsecs to 2000 microsecs). This repeating signal is generated by the Servo library and you can use either Servo.write(degrees) or Servo.writeMicroseconds(pulseWidth) - whichever is more suitable for your project.

The purpose of the map() function is to act as a bridge between the range of the potentiometer (0-1023) and the range you want for your servo (perhaps 20 to 160 degrees).

...R

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

Hi,

Robin : I agree , I shall separate input and output data, map () doing the link between them. I was a bit puzzeld considering this instruction The transfert function of the card could be ( for me ) clearer by defining the output as the duration of a pulse ( and not an angle ), followed by the Servo.writeMicroseconds(pulseWidth) instruction.

I don't have yet started any tests waiting for the servo, but it seems to me that I shall start anyway a calibration allowing to define min and max pulse duration .I suspect considering the available and minimum existing documentation that, for instance, the max angle to don't correspond to 2ms . I intend to gradually increase the pulse duration value ( starting around 1,9 ms and stop when a different noise will occur. Is it a way to skin the cat ?

Tom : is it what you expected ?

Thanks anyway of your support.

Hi,
OHHH this for a throttle positioning system on a car...

You will need to be very careful because of safety requirements, is this for a road going registered car?
There may be certain design rules that you may need to follow.

Positon R1 = 10deg of 310deg = (10/310) x 1023 = 33 from the AtoD.

Positon R2 = 60deg of 310deg = (60/310) x 1023 = 198 from the AtoD.

If the pot is outside R1 and R2 what do you want the servo to do?
Stay at the max or min value of R1 or R2?

Until you get your servo and fit it to get your output angles, we can only suggest a method.
But please check in on the legalities of what you are doing if car is registered for the road.

Tom... :slight_smile:

Image from Reply #9 so we don't have to download it. See this Image Guide

...R

TomGeorge:
OHHH this for a throttle positioning system on a car...

I would go a lot farther than @TomGeorge. IMHO it is madness to be considering modifying the control system of a car when you are not already an expert. People can be killed or crippled.

You can't control speed by connecting a powerful servo to a gas-pedal - what will you do when the servo/Arduino goes wrong?

You need to discuss this with your Automobile insurer before you do any more work on it.

...R

Hi Tom,

Don't worry for legacy, it is just an adaptation of an existing system,to better fit the hand under the control of a well known company specialised in that business.

Now :
a/ looking the orignal code ( of the original system) it shows an input ( map( val,0,1023 ,...) with a ( R2-R1) / Rpot of only 25%. , why ?

b/ Indepandantly of the servo and concerning the output,If, I specify map( val,12,632, -10° /,212°), what will be the duration pulses delivered by the card ? In short, what is the "UNO" relation between input/output values and limits if any ?

This way of specifying an angle instead of a duration pulse is definetly misleading for me ( but may be I am the only one ! ) is there any other way to proceed ?

Don't worry for legacy, it is just an adaptation of an existing system,to better fit the hand under the control of a well known company specialised in that business.

From someone who confuses legacy with legality I would worry indeed. The Processor data sheet that is in the Arduino specifically says it is not to be used for automotive applications.

Hi,

Grumpy_Mike : thanks for these counterproductive comments : « From someone who confuses legacy with legality I would worry indeed »
You don't have to worry too much because my english is not as good as it was ten years ago or more and I am awfully sorry for the confusion..
I don't understand now what you say about processor data sheet /automotive application : it seems to me that there are several examples of this nature in Arduino literature and others.

Robin : you have been of a great help to me until now and I hope that it will continue.

  • However, Let me explain a few things.

a/ I already asked support for that system in a bit more risky way ( see « Use of particular wireless link with an analog sensor » ) and I decided to stop working on that solution for questions of lack of reliability. At that time no comments on your side exepted Tom. I gave him the same arguments.

b/ The company in France installing all devices is certified by the authorities and works since 30 years in this field of activities. They supervise what I do and are interested because that could help a few other persons. You have to understand that a standard product is not in terms of safety, confort etc. the one which is the more appropriate because each handicap is different.

c/ Insurance :my insurance company is already aware of the basic modifications. They just care about the modification of the driver's licence. The certified company tall me based on their experience to proceed as is : once the modifications will satisfy my requirements and after their have reviewed the modifications, I will go back to the relevant administration to proceed to the updating of the driver's licence.

A few years ago, there was in France a need to define by law the various categories of handicap and attached to them a type of system to be used and supposed to be adapted. This bright idea of a high school young guy working for the Security Administration has been rapidly abandonned,

So Robin please before using such hard judgment like « it is madness to be considering modifying etc. etc. » try to have a better knowledge of that specific subject. Sometimes there is a big gap between core values and principles and real life / common sens.

  • I try only to modify the section in relation with the hand because after one hour of driving it starts hurting the hand and becomes potentially dangerous ( depends on the persons ). I try too, to increase the rotation angle for the thumb because two millimeters instead of one at that level means a step of 5 km/h instead of 10 ; Consequently I have to adapt the « gain » of the system in one way or the other and need to understand the way the UNO card and associated software work.

conclusion : I regret to have communicated this scheme creating so much confusion ( kindly requested by Tom !) and even if I still don't understand why it is so important to you ( and others) to tell me what I shall do, I am only interested by a technical answer to a technical question that I repeat :

1/ looking the original code ( of the original system) it shows an input ( map( val,0,1023 ,...) with a (R2-R1)/Rpot of only 25%. , why ?
2/ Independantly of the servo and concerning the output,If, I specify map( val,12,632, -10° /,212°), what will be the duration pulses delivered by the card ? In short, what is the "UNO" relation between input/output values and limits if any ?
This way of specifying an angle instead of a pulse duration is definetly misleading for me ( but may be I am the only one ! ) is there any other way to proceed ?

3/ last but not least : If the UNO card/software is not considered sufficiently reliable, is it envisageable to use a second one as redondancy ?

Samanu:
b/ The company in France installing all devices is certified by the authorities and works since 30 years in this field of activities. They supervise what I do

I had not been aware that your work is being supervised by a certified body. That makes all the difference.

However I still would not connect a servo to the gas-pedal. I assume by gas-pedal you mean the standard foot-operated pedal.

...R

If the UNO card/software is not considered sufficiently reliable, is it envisageable to use a second one as redondancy ?

Yes, it certainly is possible.
You will have to do a risk analysis. What can happen in the worst case if the arduino fails (SW and HW)? Design your system in such a way that the worst case scenario is manageable. If that means including a second arduino, then do it.

Generally speaking:
The problem with automotive applications is vibration resistance and big temperature range. This is not only about the arduino itself, it is about how you mount it, how it is cooled, the power supply etc. Read up about the allowed temperature range of the atmega processor, the power dissipation of the 5V regulator etc.
Then plan how to manage this heat dissipation.

Do a stress test under worst case conditions with your final prototype. Calculations are all good and fine, but the real proof is the real world.

A word of caution about non-genuine arduinos (clones):
Some of them have unpredictable quirks. Bad soldering joints, inferior 5V regulators, problems with serial communication. I use clones, but I choose wisely where the risk is acceptable, and where not.

The genuine arduino uno is a well manufactured and reliable PCB, as long as you don't exceed the specified operating parameters (current, voltage, temperature) of the arduino and the processor.
Consider voltage spikes from the 12V car power.

The contacts of the pin sockets are not designed for 100s of plugging/unplugging operations. Don't use your prototype uno board for the final product.

I know risk analysis and safe HW/SW design means a lot of work. There's no easy shortcut.

In the end, it doesn't matter what people in this forum consider safe or not.
You are the one who is writing the software and designing and building the additional hardware.
It is your responsibility to comply to the safety regulations of your employer and your law.

Summing up, only you can answer the question if the uno card and the software is safe for your application. If you are unsure, ask the safety/compliance officer of your employer/client. You are responsible.

I hope this helps
Thomas

Hi again,

  • OK but each time somebody ask for an advice related to Arduino usage, does he have to tell everything related to his problem ( context and so on ) ? It seems to me that your responsability is and should be limited to the technical aspects ( if the problem is at that level ).

  • You don't like the solution developed by a specialized and well known company, why not, but what are the major drawbacks, as far it is an industrial product ? What would you recommand instead of a servo ?

  • Now is there any chance for me to get an answer to my questions ?

Have a good day anyway...

Robin2:
I still would not connect a servo to the gas-pedal. I assume by gas-pedal you mean the standard foot-operated pedal.

...R

Well, Samanu somehow has to control the gas via a microprocessor... this is the whole point of the project.
How else than by some servo motor? If the car has cruise control, you could maybe utilize the existing gas servo.

Of course I understand your cautioning. The whole system has to be well designed.

Samanu,
Are you actually modifying an existing certified system, or are you designing from scratch? If you are designing from scratch, then the arduino board is probably your smallest problem.

Generally speaking, such support systems/modified cars for handicapped people have been around for a long time. So certainly it's possible.

Cruise control does nothing else.

If I were a handicapped person and have the money, I would buy a car with distance radar and adaptive cruise control. The car will do all the acceleration for you.

Thomas