advanced labview - frc labview tutorials

52
Advanced LabVIEW frclabviewtutorials.com/workshop 1

Upload: others

Post on 03-Jul-2022

129 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Advanced LabViEW - FRC LabVIEW Tutorials

Advanced LabVIEW

frclabviewtutorials.com/workshop

1

Page 2: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

• On the robo-RIO

2

Page 3: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

Use Arduino to read sensors and stream data over connection to

robo-RIO

DIO/AIO

Using Serial bus

Connecting DIO or AIO lines to and from an Arduino and the RoboRIO can provide a simple interface – useful for a small finite set of states to communicate (i.e., Breakaway LED status in Recycle Rush – 2 DO for type and 1 AO for height).

Serial bus is a tad harder to code, but allows for infinite states to be communicated (while only consuming one of the serial ports on the RIO).

3

Page 4: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

DIO/AIO

Code on Arduino to read/write pins

Code on RoboRIO to read/write pins

Code on destination to interpret result

4

Page 5: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

Using Serial Bus

Code on Arduino to open and transmit to port

Code on RoboRIO to receive from port and interpret

Code on RoboRIO to handle a loss of connection

5

Page 6: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

Using Serial Bus

Code on Arduino to open and transmit to port - setup

#include <math.h>// largely from https://www.instructables.com/id/Simple-Arduino-and-HC-SR04-Example/#define trigPin 13#define echoPin 12

int order_of_mag;long duration; float distance;String message = "";

6

Page 7: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

Using Serial Bus

Code on Arduino to open and transmit to port - init

void setup() {

Serial.begin(9600); // must match baud rate on roboRIO open too. pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT);order_of_mag = 0;while(!Serial); // wait for it to be connected

}

7

Page 8: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

Using Serial Bus

Code on Arduino to open and transmit to port – read sensor

void loop() {// write a 10 microsecond high pulse to the trigger - make sure it was low for at least 2 beforedigitalWrite(trigPin, LOW);delayMicroseconds(2);digitalWrite(trigPin, HIGH);delayMicroseconds(10);digitalWrite(trigPin, LOW);

// measure time echoPin is HIGH in microSduration = pulseIn(echoPin, HIGH);

8

Page 9: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

Using Serial Bus

Code on Arduino to open and transmit to port – scale to cm

// average time to send and receivedistance = (duration/2);// convert time to cm// s * ( 343 m/s) = s * 343 m// distance / 1000 * 353 = d m// distance * .0353 = d cmdistance = distance * .0353;

9

Page 10: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

Using Serial Bus

Code on Arduino to open and transmit to port – send

// begin transmissionSerial.print('^’);// transmit distanceSerial.print(distance);// end transmissionSerial.println('$’);

// hold up 10 mS - don't need to overflow the buffer.delay(250);

10

Page 11: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

Using Serial Bus

Code on roboRIO to open port

Make sure baud rate matches – select port

11

Page 12: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

Using Serial Bus

Code on roboRIO to receive when available

Make sure baud rate matches – select port

12

Page 13: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

Using Serial Bus

Code on roboRIO to receive when available

Make sure baud rate matches – select port

13

Page 14: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

Using Serial Bus

Code on roboRIO to receive when available

Make sure baud rate matches – select port

14

Page 15: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

Using Serial Bus

Code on roboRIO to receive when available

Make sure baud rate matches – select port

15

Page 16: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

Using Serial Bus

Code on roboRIO to receive when available

Make sure baud rate matches – select port

16

Page 17: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

Using Serial Bus

Code on roboRIO to receive when available

Make sure baud rate matches – select port

17

Page 18: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

Using Serial Bus

Code on roboRIO to receive when available

Make sure baud rate matches – select port

18

Page 19: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

Using Serial Bus

Code on roboRIO to receive when available

Make sure baud rate matches – select port

19

Page 20: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

Using Serial Bus

Code on roboRIO to receive when available

Make sure baud rate matches – select port

20

Page 21: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

Using Serial Bus

Code on roboRIO to handle loss of connection

Make sure baud rate matches – select port

21

Page 22: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

• Demo

22

Page 23: Advanced LabViEW - FRC LabVIEW Tutorials

Using an Arduino for sensor input

• On the robo-RIO

• On the Dashboard

23

Page 24: Advanced LabViEW - FRC LabVIEW Tutorials

Using and Arduino with the Dashboard

• Driver station i/o

– Potentiometer for extra input (autonomous selection, shooter speed,

etc.)

– Buttons/switches for additional control

– LEDs for indication

– Etc.

24

Page 25: Advanced LabViEW - FRC LabVIEW Tutorials

Using and Arduino with the Dashboard

• Customize the dashboard to read/write to Arduino

– Implement own serial interface (like with previous example on

RoboRIO) or

– Use LINX library

(https://www.labviewmakerhub.com/doku.php?id=libraries:linx:start)

25

Page 26: Advanced LabViEW - FRC LabVIEW Tutorials

Using and Arduino with the Dashboard

• Use LINX library

– Open connection

– Read/write to I/O

– Close connection

26

Page 27: Advanced LabViEW - FRC LabVIEW Tutorials

Using and Arduino with the Dashboard

• Use LINX library

– Open connection

– Read/write to I/O

– Close connection

Works in built exe with/without pressing stop. Need to press stop in dev (will leave the port reserved).

27

Page 28: Advanced LabViEW - FRC LabVIEW Tutorials

Using and Arduino with the Dashboard

• Demo

28

Page 29: Advanced LabViEW - FRC LabVIEW Tutorials

PID

• Proportional

https://docs.google.com/viewer?a=v&pid=sites&srcid=aGFyZGluZy5lZHV8dGVhbS0zOTM3fGd4OjUyNzdiNzRkNjkxNjA3MGMhttps://www.youtube.com/watch?v=JEpWlTl95Twhttps://www.youtube.com/watch?v=UR0hOmjaHp0http://robotics.stackexchange.com/questions/167/what-are-good-strategies-for-tuning-pid-loops

29

Page 30: Advanced LabViEW - FRC LabVIEW Tutorials

PID

• Proportional

– Constant multiplied by error (offset)

– The larger this is, the faster the robot approaches the setpoint (smaller

rise time)

30

Page 31: Advanced LabViEW - FRC LabVIEW Tutorials

PID

• Proportional

– Constant multiplied by error (offset)

– The larger this is, the faster the robot approaches the setpoint (smaller

rise time)

• Integral

– Constant multiplied by integral of all previous error values

– The larger this is, the less overshoot and settling time (less bounce)

31

Page 32: Advanced LabViEW - FRC LabVIEW Tutorials

PID

• Proportional

– Constant multiplied by error (offset)

– The larger this is, the faster the robot approaches the setpoint (smaller

rise time)

• Integral

– Constant multiplied by integral of all previous error values

– The larger this is, the less overshoot and settling time (less bounce)

• Differential

– Used to eliminate steady state error (reducing offset after movement)

32

Page 33: Advanced LabViEW - FRC LabVIEW Tutorials

PID

• Proportional

– Constant multiplied by error (offset)

– The larger this is, the faster the robot approaches the setpoint (smaller

rise time)

• Integral

– Constant multiplied by integral of all previous error values

– The larger this is, the less overshoot and settling time (less bounce)

• Differential

– Used to eliminate steady state error (reducing offset after movement)

33

Page 34: Advanced LabViEW - FRC LabVIEW Tutorials

PID

• Tuning

34

Page 35: Advanced LabViEW - FRC LabVIEW Tutorials

PID

• Tuning

– Several methods available

• Ziegler–Nichols*

• Tyreus Luyben

• Cohen–Coon

• Åström-Hägglund

• Manual Tuning*

http://faculty.mercer.edu/jenkins_he/documents/TuningforPIDControllers.pdf#page=6https://www.youtube.com/watch?v=JEpWlTl95Twhttps://www.youtube.com/watch?v=UR0hOmjaHp0http://robotics.stackexchange.com/questions/167/what-are-good-strategies-for-tuning-pid-loopsZiegler-Nichols: http://robotsforroboticists.com/pid-control/Manual (page 16): https://docs.google.com/viewer?a=v&pid=sites&srcid=aGFyZGluZy5lZHV8dGVhbS0zOTM3fGd4OjUyNzdiNzRkNjkxNjA3MGMhttp://www.ni.com/white-paper/3782/en/

35

Page 36: Advanced LabViEW - FRC LabVIEW Tutorials

PID

• Tuning

– Manuel

• Raise CP Until robot oscillates about setpoint

• Raise CD Until Robot stops bouncing

• Raise CI (and change the setpoint) until robot turns and hits the target point

– Ziegler-Nichols

• Raise CP Until robot oscillates (Value of CP becomes Ku)

• Measure the period of this oscillation (Time to complete 1 cycle becomes TU)

36

Page 37: Advanced LabViEW - FRC LabVIEW Tutorials

PID

• Tuning

– Manuel

• Raise CP Until robot oscillates about setpoint

• Raise CD Until Robot stops bouncing

• Raise CI (and change the setpoint) until robot turns and hits the target point

– Ziegler-Nichols

• Raise CP Until robot oscillates (Value of CP becomes Ku)

• Measure the period of this oscillation (Time to complete 1 cycle becomes TU)

37

Page 38: Advanced LabViEW - FRC LabVIEW Tutorials

PID

• Tuning

– Manuel

• Raise CP Until robot oscillates about setpoint

• Raise CD Until Robot stops bouncing

• Raise CI (and change the setpoint) until robot turns and hits the target point

– Ziegler-Nichols

• Raise CP Until robot oscillates (Value of CP becomes Ku)

• Measure the period of this oscillation (Time to complete 1 cycle becomes TU)

38

Page 39: Advanced LabViEW - FRC LabVIEW Tutorials

PID

• Demo

39

Page 40: Advanced LabViEW - FRC LabVIEW Tutorials

Functional Global Variable

40

Page 41: Advanced LabViEW - FRC LabVIEW Tutorials

Functional Global Variable

• Quick Intro

– https://frclabviewtutorials.com/fgv/

demo

41

Page 42: Advanced LabViEW - FRC LabVIEW Tutorials

FGV

Functional Global Variable Code

42

Page 43: Advanced LabViEW - FRC LabVIEW Tutorials

Implementing An FGV

43

Page 44: Advanced LabViEW - FRC LabVIEW Tutorials

Architectures

• State Machine

46

Page 45: Advanced LabViEW - FRC LabVIEW Tutorials

Architectures

• State Machine

47

Page 46: Advanced LabViEW - FRC LabVIEW Tutorials

Architectures

• State Machine

48

Page 47: Advanced LabViEW - FRC LabVIEW Tutorials

Architectures

• State Machine

• Producer-Consumer

– Parallel loops

• First creating data or instructions

• Other handling

49

Page 48: Advanced LabViEW - FRC LabVIEW Tutorials

Architectures

• State Machine

• Producer-Consumer

– Parallel loops

– Use either queue or fgv

50

Page 49: Advanced LabViEW - FRC LabVIEW Tutorials

Producer Consumer Demo

Queue and FGV

51

Page 50: Advanced LabViEW - FRC LabVIEW Tutorials

Encoders

• Wiring (see notes for links)

• Rotational Encoders

– Fly wheel speed

– Drive distance

• Linear Encoders

– Linear actuator feedback

• Etc.

https://www.chiefdelphi.com/forums/showthread.php?t=133263https://www.andymark.com/encoder-p/am-3314.htmhttps://www.andymark.com/product-p/am-2992.htm

52

Page 51: Advanced LabViEW - FRC LabVIEW Tutorials

Encoders – Fly Wheel monitor demo

53

Page 52: Advanced LabViEW - FRC LabVIEW Tutorials

Questions

61