樹莓派 0W 狂想曲︰ 木牛流馬《控制》

想那洛水小神龜自由自在

洛書

Turtle

L3

L2

images

子虛先生說︰昔時洛水有神龜,總於晨昏之時,彩雲滿天之際,游於洛水之波光霞影之中。興起就神足直行,左旋右轉飛舞迴旋,那時波濤不起漣漪不見,河面只隨神龜尾之上下,或粗或細或長或短或直或曲契刻成圖文。一日大禹治水偶經洛水恰遇神龜,神龜感念大禹昔日洩洪疏河之恩,特演平日最得意水畫之作,所以歷史才傳說『大禹得洛書』。

雖然作者以為子虛先生所說乃是烏有之言,然而他卻把『小海龜』繪圖法的精神描寫的活靈活現。小海龜頭的朝向決定它『前進』的方向,『【向前】【數值】 』表示向前走多少單位距離的指令,比方 forward 10,是說向前走十個單位。除了直行之外小海龜還可以『轉向』,這個轉向是依據當前之前進的方向『左轉』或是『右轉』,用『【旋轉】【角度】』表示,比方 rotate 90 是說右轉九十度, 而 rotate -90 是講左轉九十度。小海龜在網頁上的『位置』是由網頁上的 (X,Y) 座標來決定的,它的設定是『左上』(0,0)和『右下』 (600,600) 。小海龜當下的『狀態』state 是由『現在』的『位置』與『朝向角度』所一起決定的,這也就是『存上堆疊』push 與『堆疊取回』pop 存上取回指令裡所說的狀態。小海龜可以給定一個『開始』的『位置』與『朝向』,初進網頁時它在 (50,300),小海龜的頭朝右,它的角度是 0。

─── 摘自《科赫傳說!!

 

自主自動,經絡暢通心到行至,早不知何謂『控制』的也。這個『 GoPiGo 』畢竟是人造之物聽人使喚,前進、後退、左旋、右轉不得不有個『運動機制』

Servomotor

A servomotor is a rotary actuator or linear actuator that allows for precise control of angular or linear position, velocity and acceleration.[1] It consists of a suitable motor coupled to a sensor for position feedback. It also requires a relatively sophisticated controller, often a dedicated module designed specifically for use with servomotors.

Servomotors are not a specific class of motor although the term servomotor is often used to refer to a motor suitable for use in a closed-loop control system.

Servomotors are used in applications such as robotics, CNC machinery or automated manufacturing.

Industrial servomotor
The grey/green cylinder is the brush-type DC motor. The black section at the bottom contains the planetary reduction gear, and the black object on top of the motor is the optical rotary encoder for position feedback. This is the steering actuator of a large robot vehicle.

Mechanism

A servomotor is a closed-loop servomechanism that uses position feedback to control its motion and final position. The input to its control is a signal (either analogue or digital) representing the position commanded for the output shaft.

The motor is paired with some type of encoder to provide position and speed feedback. In the simplest case, only the position is measured. The measured position of the output is compared to the command position, the external input to the controller. If the output position differs from that required, an error signal is generated which then causes the motor to rotate in either direction, as needed to bring the output shaft to the appropriate position. As the positions approach, the error signal reduces to zero and the motor stops.

The very simplest servomotors use position-only sensing via a potentiometer and bang-bang control of their motor; the motor always rotates at full speed (or is stopped). This type of servomotor is not widely used in industrial motion control, but it forms the basis of the simple and cheap servos used for radio-controlled models.

More sophisticated servomotors use optical rotary encoders to measure the speed of the output shaft[2] and a variable-speed drive to control the motor speed.[3] Both of these enhancements, usually in combination with a PID control algorithm, allow the servomotor to be brought to its commanded position more quickly and more precisely, with less overshooting.[4]

 

追求更好的『控制穩定性』

PID controller

A proportional–integral–derivative controller (PID controller) is a control loop feedback mechanism (controller) commonly used in industrial control systems. A PID controller continuously calculates an error value e ( t ) {\displaystyle e(t)} e(t) as the difference between a desired setpoint and a measured process variable and applies a correction based on proportional, integral, and derivative terms (sometimes denoted P, I, and D respectively) which give their name to the controller type.

A block diagram of a PID controller in a feedback loop. r(t) is the desired process value or “set point”, and y(t) is the measured process value.

Fundamental operation

A PID controller continuously calculates an error value e(t) as the difference between a desired setpoint and a measured process variable and applies a correction based on proportional, integral, and derivative terms. The controller attempts to minimize the error over time by adjustment of a control variable  u(t), such as the position of a control valve, a damper, or the power supplied to a heating element, to a new value determined by a weighted sum:

{\displaystyle u(t)=K_{\text{p}}e(t)+K_{\text{i}}\int _{0}^{t}e(\tau )\,d\tau +K_{\text{d}}{\frac {de(t)}{dt}},}

where  {\displaystyle K_{\text{p}}} {\displaystyle K_{\text{i}}}, and  {\displaystyle K_{\text{d}}}, all non-negative, denote the coefficients for the proportional, integral, and derivative terms, respectively (sometimes denoted P, I, and D). In this model:

  • P accounts for present values of the error. For example, if the error is large and positive, the control output will also be large and positive.
  • I accounts for past values of the error. For example, if the current output is not sufficiently strong, the integral of the error will accumulate over time, and the controller will respond by applying a stronger action.
  • D accounts for possible future trends of the error, based on its current rate of change.[1]

As a PID controller relies only on the measured process variable, not on knowledge of the underlying process, it is broadly applicable.[2] By tuning the three parameters of the model, a PID controller can deal with specific process requirements. The response of the controller can be described in terms of its responsiveness to an error, the degree to which the system overshoots a setpoint, and the degree of any system oscillation. The use of the PID algorithm does not guarantee optimal control of the system or even its stability.

Some applications may require using only one or two terms to provide the appropriate system control. This is achieved by setting the other parameters to zero. A PID controller is called a PI, PD, P or I controller in the absence of the respective control actions. PI controllers are fairly common, since derivative action is sensitive to measurement noise, whereas the absence of an integral term may prevent the system from reaching its target value.

For discrete-time systems, the term PSD (proportional-summation-difference) is often used.[3]

 

因是可知小汽車『設計構想』哩☆

4.  Attach Encoders

The encoders for the GoPiGo are cut in black and look like a little wheel.  They fit on the inside of the motors, and poke through the GoPiGo acrylic chassis.  They provide feedback on speed direction traveled to the motors. Most of the time the motors will work fine without them, but they can be used to control and refine the action of the motors.

Note: Some have found that these can fall off easily.  You can secure them with a small piece of tinfoil, paper or blue ticky tacky.

If these keep falling off, just remove them for now, as they are not necessary.

Encoders ready to be attached.

Encoders ready to be attached.

Raspberry pi robot chassis

Encoders properly attached.

 

#ifndef SoftwareServo_h
#define SoftwareServo_h

#include <Arduino.h>
#include <inttypes.h>

class SoftwareServo
{
  private:
    uint8_t pin;
    uint8_t angle;       // in degrees
    uint16_t pulse0;     // pulse width in TCNT0 counts
    uint8_t min16;       // minimum pulse, 16uS units  (default is 34)
    uint8_t max16;       // maximum pulse, 16uS units, 0-4ms range (default is 150)
    class SoftwareServo *next;
    static SoftwareServo* first;
  public:
    SoftwareServo();
    uint8_t attach(int);     // attach to a pin, sets pinMode, returns 0 on failure, won't
                             // position the servo until a subsequent write() happens
    void detach();
    void write(int);         // specify the angle in degrees, 0 to 180
    uint8_t read();
    uint8_t attached();
    void setMinimumPulse(uint16_t);  // pulse length for 0 degrees in microseconds, 540uS default
    void setMaximumPulse(uint16_t);  // pulse length for 180 degrees in microseconds, 2400uS default
    static void refresh();    // must be called at least every 50ms or so to keep servo alive
                              // you can call more often, it won't happen more than once every 20ms
};

#endif