Skip to content

Commit 79c7328

Browse files
author
Michał Pełka
committed
plots
1 parent e3af5c8 commit 79c7328

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,29 @@ Simple DC Motor Servo using Arduino
33

44
## Motivation
55

6-
Very, very, very large RC Servo
6+
Building very, very, very large RC Servo
77

88
## Input signal
99
Standard PPM signal (like classic RC Servo)
10+
- D1 Output of servo tester or RC reciever
1011

1112
## Output
1213
Driving signal for H-Bridge
14+
D9 - PWM output
15+
D6 - direction Left
16+
D7 - direction Right
1317

1418
## Feedback
1519
Rotary Potentiometr
20+
A1 - signal from rotary potentiometer
1621

1722
## Regulation
18-
P-controller with saturation
23+
ch1_interrupt is called when state of reciever input is changed. Than pulse width is measured. That value is mapped to input value of P controller. That P controller works output mapped to PWM generator and two direction output. Those outputs are controlling motor H-Bridge IC (like VNH 5019)
24+
25+
## Plots
26+
Arduino sends over port controll setpoint and measurment. Thus it can be plotted.
27+
28+
# Issues
29+
If you experience contant movement, please check if feedback (rotary encoder is connected in right direction).
30+
31+

plots/sin.png

144 KB
Loading

plots/step.png

78.5 KB
Loading

plots/triangle.png

128 KB
Loading

servo.ino

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
#define button 4
55
#define CH1 3
66
#define RANGE 10000
7-
const byte ledPin = 13;
8-
volatile byte state = LOW;
9-
int rotDirection = 0;
10-
int pressed = false;
117
void setup() {
128
pinMode(enA, OUTPUT);
139
pinMode(in1, OUTPUT);
@@ -18,7 +14,7 @@
1814
// Set initial rotation direction
1915
digitalWrite(in1, LOW);
2016
digitalWrite(in2, HIGH);
21-
attachInterrupt(digitalPinToInterrupt(CH1), blink, CHANGE);
17+
attachInterrupt(digitalPinToInterrupt(CH1), ch1_interrupt, CHANGE);
2218

2319
Serial.begin(9600);
2420
}
@@ -31,7 +27,7 @@
3127
volatile int oldCh;
3228
volatile int microsStart=0;
3329
volatile int readout =0;
34-
void blink() {
30+
void ch1_interrupt() {
3531
volatile int ch = digitalRead(CH1);
3632
if (ch==1 && oldCh==0)
3733
{
@@ -44,18 +40,17 @@
4440

4541
}
4642
oldCh = ch;
47-
state = !state;
4843
}
4944

5045

5146

5247
void loop() {
5348

54-
int setPoint = map(readout, 1200, 1700, -RANGE, RANGE);
49+
int setPoint = map(readout, 1000, 1700, -RANGE, RANGE);
5550
//Serial.println(setPoint);
5651

57-
int potValue = analogRead(A0); // Read potentiometer value
58-
int input = map(potValue, 100, 900, -RANGE , RANGE);
52+
int potValue = analogRead(A1); // Read potentiometer value
53+
int input = map(potValue, 200, 750, -RANGE , RANGE);
5954
//Serial.println(input);
6055

6156
int error = input - setPoint;

0 commit comments

Comments
 (0)