Servo movement from side to side with PWM Arduino uploaded code - arduino-uno

I'm using Arduino-Uno micro-controller with Adafruit servo shield. To move a quite fast 0.07 sec/60° mini digital servo motor with desired angle, for example from C# application:
myport.WriteLine(val.ToString());
I using PWM library:
pwm.setPWM(1, 0, Serial.parseInt());
Which moves motor to the assigned angle successfully, but I'm trying to figure out, how to move servo motor from one angle to another with full reaching of end points from uploaded code.
So if maximum and minimum of range is:
#define SERVOMIN 160
#define SERVOMAX 500
And servo motor performs from 210 to 450, here is a my attempt:
pwm.setPWM(1, 0, 210);
delay(12);
pwm.setPWM(1, 0, 450);
delay(12);
pwm.setPWM(1, 0, 210);
This way motor does not completes movement or even makes single direction movement without return. What should be a proper way, to make such movement within uploaded code.
Any advice, guide or example would be very helpful

You can't.
Normal servos don't provide any feedback on their position. It's not possible with software alone, unless you add long enough delay to make sure it completes the move even under load.
You either need a different servo or additional sensors.
More on Arduino Stack Exchange: How long does it take for a servo to change rotation?

Related

Keep ESP32 non-RTC GPIO pin state HIGH in deep sleep

I'm using Arduino IDE, and I'm trying to keep a pin's state held (HIGH, in my case).
I have GPIO16, GPIO17, GPIO18 (which I believe are all non-RTC GPIO pins). They're connected to three P-channel MOSFETs, which power an RGB LED. So my three pins need to be held HIGH while sleeping.
When my ESP32 goes into deep sleep, the RGB LED slowly fades up to full white brightness 😅
After searching around, the method posted elsewhere doesn't work as expected. I've tried the below, but no luck.
Arduino IDE:
gpio_hold_en((gpio_num_t) 16);
gpio_hold_en((gpio_num_t) 17);
gpio_hold_en((gpio_num_t) 18);
gpio_deep_sleep_hold_en();
delay(10000);
esp_deep_sleep_start();
Strangely though, now the blue LED (on GPIO 18) doesn't come on, just the other two (16 and 17) snap to full brightness as soon as I call deep sleep.
Does it matter that they're GPIO vs RTC GPIO?
Is it possible to hold them HIGH during deep sleep? I've also tried INPUT_PULLUP but no luck either.
They're SMD soldered on custom PCBs so I'm trying to solve this in software, before I consider swapping for N-Channel MOSFETs or just making new boards entirely.

Pepper right shoulder pitch wont respond in timeline ir inspector

I'm trying to make some reach-grasp trajectories in timeline. They work fine with the virtual robot. On the real Pepper, sometimes they execute fine, then, next try, the right arm doesnt move in the complete trajectory. If I then use the inspector to move the right shoulder pitch, it gets stuck around 50°.
I wonder if there is some stiffness, or force, parameter: it is as if the robot does not have the strength to make the movement.
You may debug the hand movement with a simple command line Python script that we have made for us. See https://nlp.fi.muni.cz/trac/pepper/wiki/SetArmPosition with a link to souce code.
Pepper has barely the strength to lift its arms when stretched.
When it does so, these motors get hot, and the power fed to them is reduced, to the point where the motion cannot be performed.
Prefer more complex motion, that requires less instantaneous strength to perform, for instance by using a bit of the roll motion, and by stretching the arms only at the last moment.

Temperature Regulation Circuit Arduino

I am currently working on a water flow control system using an arduino. The goal is that I can set the temperature of the water stream using the arduino.
I have a Y shaped part of hosing. On the upper left arm of the Y piece I have a constant stream of cold water, around 12°C. On the upper right arm of the Y piece I got a valve with which I can regulate how much hot water I mix in. The hot water is around 50°C. To regulate the hot water intake I am using a servo motor, which cranks the valve to a certain position.
On the lower part of the Y I got a temperature sensor which tells me the mixed temperature of the water.
The algorithm I came up with to mix water to a specific temperature looks like this:
1. Calibrate by calculating the minimum and maximum temp and corresponding servo positions
1.1 set the servo position to the absolute minimum, wait for 10 seconds and get the temperature -> minTemperature, minPos
1.2 set the servo position to the absolute maximum, wait for 10 seconds and get the temperature -> maxTemperature, maxPos
2. Set the mixing temperature to X°C
2.1 (maxTemp-minTemp)/(maxPos-minPos) = p °C/pos
Which means that changing the position by 1 position changes the mix temperature by p °C
2.2 minPos + (x-minTemp) / p = targetPos
3. If abs(measuredTemp-x)>Tolerance than do 2.
Is this approach viable at all, when it comes to real life implementation? How are other heat regulation circuits done?
This will basically work, but there are a couple problems you should fix:
The relationship between servo position and temperature is not going to be linear. At minimum, calibrate at at 4 different positions and fit a cubic polynomial.
Because a valve has a lot of friction, and the positioning algorithms in off-the-shelf servos are not awesome, the position it goes to when you command a move to position 'X' from a lower position is not the same as the position it goes to when you command a move to the same position 'X' from a higher position. You should calibrate different curves for increasing temperature and decreasing temperature, and make sure you command motion that approaches a desired temperature slowly in order to get repeatable results.
Once you get to correct position according to the calibrated curves, if you temperature is off you can move slowly toward it and adjust the calibration. You probably want to assume that the error comes from a difference in the input temperature and adjust accordingly.

how to control servo motor using embedded c using simple code?

i'm working on a school project "automatic railway system"
my project suppose to close the gate when the train coming to the station with a buzzer on with 90 sec count down display on 7-seg. and a led flashing.
after the train leaving the station, the gate opens and the buzzer off and the led off .
i tried to use a dc motor to open and close the gate but it didn't give me the accurate angle that i need to i try to use a servo motor .
so i need it to open the gate at position zero and close it at position 90 .
all the code i found on the internet they using PWM and timers which i didn't take it in my course , so can anyone help me to do this with simple code ,please ?
i'm using Atmega32 running at 16000000 HZ
Its depend on your analog servo (which is controlled by PWM) frequency specification. After you learn about the servo specification, you can set your PWM using build-in features on cvavr compiler, or you can do some research about PWM registers.
Here is some example of PWM setup
//using OC0 (B.3)
DDRB.3 = 1; //set B.3 as output
TCCR0=0b0111 0001;
TCNT0=0; //set to Phase Correct PWM mode, no prescaler, and inverted output
//to assign a value to your PWM
OCR0 = 127 //50% duty cycle since it was 8 bit

No smooth animation for processing sketch, yet normal GPU/CPU load and framerate

I'm working on the visualizations of an interactive installation as seen here: http://vimeo.com/78977964. But I'm running into some issues with the smoothness of the animation. While it tells me it runs on a steady 30 or 60 fps, the actual image is not smooth at all; imagine a 15fps animation with an unsteady clock. Can you guys give me some pointers on where to look in optimizing my sketch?
What I'm doing is receiving relative coordinates (0.-1. on x and y axis) through oscP5. This goes through a data handler to check if there hasn't been input in that area for x amount of time. If all is ok, a new Wave object is created, which will draw an expanding (modulated) circle on its location. As the installation had to be very flexible, all visual parameters are adjustable through a controlP5 GUI.
All of this is running on a computer with i7 3770 3.4Ghz,8 GB RAm and two Radeon HD7700's to drive 4 to 10 Panasonic EX600 XGA projectors over VGA (simply drawing a 3072x1536 window). The CPU and GPU load is reasonable ( http://imgur.com/a/usNVC ) but the performance is not what we want it to be.
We tried a number of solutions including: changing rendering mode; trying a different GPU; different drawing methods; changing process priority; exporting to application; etc. But nothing seemed to make a noticeable improvement. So now I'm guessing its either just processing/java not being able to run smoothly over multiple monitors or something is causing this in my code...
How I draw the waves within the wave class (this is called from the main draw loop for every wave object)
public void draw(){
this.diameter = map(this.frequency, lowLimitFrequency, highLimitFrequency, speedLowFreq, speedHighFreq) * (millis()-date)/5f;
strokeWeight(map(this.frequency, lowLimitFrequency, highLimitFrequency, lineThicknessLowFreq, lineThicknessHighFreq)*map(this.diameter, 0, this.maxDiameter, 1., 0.1)*50);
stroke(255,255,255, constrain((int)map(this.diameter, 0, this.maxDiameter, 255, 0),0,255));
pushMatrix();
beginShape();
translate(h*this.x*width, v*this.y*height);
//this draws a circle from line segments, and is modified by a sinewave
for (int i = 0;i<segments;i++) {
vertex(
(this.distortion*sin(map(i, 0, segments, 0, this.periods*TWO_PI))+1)* this.diameter*sin(i*TWO_PI/segments),
(this.distortion*sin(map(i, 0, segments, 0, this.periods*TWO_PI))+1)* this.diameter* cos(i*TWO_PI/segments)
);
}
vertex(
(this.distortion*sin(map(0, 0, segments, 0, this.periods*TWO_PI))+1)* this.diameter*sin(0*TWO_PI/segments),
(this.distortion*sin(map(0, 0, segments, 0, this.periods*TWO_PI))+1)* this.diameter* cos(0*TWO_PI/segments)
);
endShape();
popMatrix();
}
I hope I've provided enough information to grasp whats going wrong!
My colleagues and I have had similar issues here running a PowerWall (6x3 monitors) from one PC using an Eyefinity setup. The short version is that, as you've discovered, there are a lot of problems running Processing sketches across multiple cards.
We've tended to work around it by using a different approach - multiple copies of the application, which each span one monitor only, render a subsection and sync themselves up. This is the approach people tend to use when driving large displays from multiple machines, but it seems to sidestep these framerate problems as well.
For Processing, there're a couple of libraries that support this: Dan Shiffman's Most Pixels Ever and the Massive Pixel Environment from the Texas Advanced Computing Center. They've both got reasonable examples that should help you through the setup phase.
One proviso though, we kept encountering crashes from JOGL if we tried this with OpenGL rendering - this was about 6 months ago, so maybe that's fixed now. Your draw loop looks like it'll be OK using Java2D, so hopefully that won't be an issue for you.

Resources