NXT Development Tutorial Part 2: Sensor/ Motor Collaboration NTHU CS Freshman Camp Shu-Ting Wang.

Slides:



Advertisements
Similar presentations
PID Control for Embedded Systems
Advertisements

Nattee Niparnan. Towards Autonomous Robot A robot that can think how to perform the task.
Proportional, Integral, Derivative Line Following October 5, 2013.
Add and Use a Sensor & Autonomous For FIRST Robotics
Graphical RobotC NXT (EV3) Robot Workshop 2015 Instructor: Dr. Fred Brauchler Assistant: Chris Parker 2/7/2015Lawrence Technological University1.
Using the NXT Light Sensor. 2 Connect One Light Sensor – 1 From My Files use Left / Right NXT buttons and get to View menu and push Orange button. From.
The Proportional-Integral-Derivative Controller
Chapter 10 – The Design of Feedback Control Systems PID Compensation Networks.
ECE 4951 Lecture 5: PID Control of Processes. PID Control A closed loop (feedback) control system, generally with Single Input-Single Output (SISO) A.
Using LeJOS LMICSE Workshop June , 2005 Alma College.
Navigation, Path finding, and Maze Encoding MICROMOUSE ALGORITHMS.
PID Control & ACS550 and ACH550
1 ©2006 INSciTE Lab Two Task: Make the program from Lab One (Move forward 5 rotations and turn right 90 degrees) into a MyBlock.
Chapter 7 PID Control.
Java for Robots How to program an NXT robot with a Java Brain Bert G. Wachsmuth Seton Hall University.
LEGO NXT Robot Programming Introduction to Programming a Lego NXT robot in Java.
Introduction to LEGO NXT 6 hour course. Introductions You Your Expectations.
Automatic Control Mike Robinson. You can measure the distance from the RC car to some target. What could your program do to keep the car as close to the.
Why do robots need to move?
T HE F INCH R OBOT AND THE W HILE L OOP Pepper. T HE R OBOT Developed by Carnegie Mellon students to teach CS Supports many compilers, including Java.
Application of Math and Science Principles Creating a robot that moves a specified distance straight ahead and Creating a robot that turns a specified.
Agenda Path smoothing PID Graph slam.
Maze Challenge Maze Challenge activity > TeachEngineering.org
Encoding Robotic Sensor States for Q-Learning using the Self-Organizing Map Gabriel J. Ferrer Department of Computer Science Hendrix College.
Sound, Touch Sensor, and Motors. Wheeled Vehicles Using the Pilot class: –Constructor Pilot(float wheelDiameter, float trackWidth,Motor leftMotor, Motor.
David GiandomenicoFeedback Control for your FIRST Robot’s DrivetrainDec 2010 WRRF Workshops #1 David Giandomenico Team mentor for Lynbrook Robotics – Team.
Light, Sound, and Ultrasonic Sensor. Doc leJOS API – leJOS Tutorial –
CS 478: Microcontroller Systems University of Wisconsin-Eau Claire Dan Ernst Feedback Control.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
NXT Development Tutorial Part 3: Robot Arm NTHU CS Freshman Camp Shu-Ting Wang.
PID. The proportional term produces an output value that is proportional to the current error value. Kp, called the proportional gain constant.
PID CONTROLLERS By Harshal Inamdar.
CSCI1600: Embedded and Real Time Software Lecture 12: Modeling V: Control Systems and Feedback Steven Reiss, Fall 2015.
Testing Chapter 23 IB103 Week 12 (part 3). Verify that a complex (any) program works correctly, that the program meets specifications The chapter reviews.
ENTC 395 Lecture 7a. Today 4 PID control –Overview –Definitions –Open loop response 4 Example –SIMULINK implementation.
Chapter - Continuous Control
ECE 192: NATCAR Team (Triton X) Sponsored by IEEE ( Vincent Bantigue, Joseph Formanes,
Control Loops Tune a Fish. Control Loops Tuning of a control loop involves selecting loop parameters to ensure stable control under all operating conditions.
ECE 192: NATCAR Team (Triton X) Sponsored by IEEE ( Vincent Bantigue, Joseph Formanes,
Obstacle Detection. In the previous program the robot moves forward and then checks for something in the way. As we observed it only checks for things.
Casne.ncl.ac.uk Taking care of the CrumbleBot Please do NOT stress the robot's motors 1.Do NOT push the robot 2.Do NOT hold the.
PID Control Joe Ross Team 330.
Introduction to Robots and the Mind - Programming with Sensors - Bert Wachsmuth & Michael Vigorito Seton Hall University.
Forward Until Near Stop when near a wall.
BIRLA VISHWAKARMA MAHAVIDHYALAYA ELECTRONICS & TELECOMUNICATION DEPARTMENT o – ANKUR BUSA o – KHUSHBOO DESAI UNDER THE GUIDENCE.
3-July-2002cse142-D2-Methods © 2002 University of Washington1 Methods CSE 142, Summer 2002 Computer Programming 1
EEN-E1040 Measurement and Control of Energy Systems Control I: Control, processes, PID controllers and PID tuning Nov 3rd 2016 If not marked otherwise,
PID Control for Embedded Systems
PID Control Systems (Proportional, Integral, Derivative)
Process Control & Instrumentation MAPUA INSTITUTE OF TECHNOLOGY
Intelligent Traction Control Smart Robot
PID Controllers Jordan smallwood.
IT Basic Wednesday 14 April 2010
Control Loops Nick Schatz FRC 3184.
CSCI1600: Embedded and Real Time Software
Balanduino Supervisor: Dr. Raed Al-Qadi Prepared by: Nadeen Kalboneh Nardeen Mabrouk.
Using Encoders to go Straight
6: Processor-based Control Systems
The Finch Robot and the While Loop
Basic Design of PID Controller
Cole Perrault Spring 2015 ET 493 Wesley Deneke
Better Line Following with PID
Robotics and EVT - line follower -
Robotics Programming Using Shaft Encoders
Dynamical Systems Basics
Advanced LabVIEW
© A+ Computer Science -
Lego MINDSTORMS EV3.
LEGO MINDSTORMS NXT PROGRAMMING
Presentation transcript:

NXT Development Tutorial Part 2: Sensor/ Motor Collaboration NTHU CS Freshman Camp Shu-Ting Wang

Download Links code.zip code.zip _Day2.pptx _Day2.pptx

Outline A Car class Ultrasonic tracker – Naive Threshold – Method based Threshold – Proportional Control Light sensor based line follower – Naïve line follower – PID controlled line follower

Outline A Car class Ultrasonic tracker – Naive Threshold – Method based Threshold – Proportional Control Light sensor based line follower – Naïve line follower – PID controlled line follower

Recall: Dog Features: – Weight – Height – Age – Is Healthy – Favorite Sports Behaviors: – Run – Bark – Bite – Eat – Sleep

Recall: Class Dog in Java public class Dog { …...Features …... public Dog(int Weight, float height, int Age) { …….How to create a dog based on these information } public void Bark(){ …….How to bark as a dog……. } public void Eat(){ …….How to eat……. }

Recall: How an Object Pops Out? Use a specific term: new We new a dog out based on our definition in class dog Dog mydog= new Dog(5,1.8,3); mydog.Eat(); Mydog.Bark();

Lab 1: Write a Car Class (1/2) public class Car { // Commands for the motors private final static int forward = 1, backward = 2, stop = 3; private static MotorPort leftMotor = MotorPort.C; private static MotorPort rightMotor= MotorPort.B; private Car(){ } }

Lab 1: Write a Car Class (2/2) We need three methods: – public static void stop() – public static void forward() – public static void backward()

Outline A Car class Ultrasonic tracker – Naive Threshold – Method based Threshold – Proportional Control Light sensor based line follower – Naïve line follower – PID controlled line follower

While() while(condition){ ….something… } Keep doing something until the condition is not true For example, keep walking until you see Delta building while (I don’t see Delta building){ dog.walk(); }

If() if(condition){ ….something A… } else ….something B… } Do something if the condition is true For example if (I am hungry){ I go to find something to eat } else{ play LOL }

Recall: Ultrasonic Sensor Get the distance from your hand public static void main(String[] args) throws Exception { UltrasonicSensor Ultrasonic = new UltrasonicSensor(SensorPort.S1); while(!Button.ESCAPE.isDown()) { LCD.clear(3,0,0); LCD.drawInt(Ultrasonic.getDistance(),3,0,0); }

Lab 2: Naïve Threshold Tracker Implement a control loop which based on the measured distance controls the movements of the car If the measured distance to obstacles/wall are over 40, the car continued straight ahead. If not, the car turning to the left Modify the run() method in Tracker.java

Lab3: isCrashed() ? Your car got stuck in chair legs during the rotation ? Made an isCrashed method whose task is to check whether the car is stuck based on repeated distance measurements similar to each other.

Proportional Control (1/2) The power to the car motors is determined by the measured error Error in this case is the difference between the measured distance to the object and the desired distance to the object: error = distance - desiredDistance;

Proportional Control (2/2) The power is proportional to the measured error by multiplying the error with a constant (gain). power = (int) (gain * error);

Lab 4 The power is always in between two extremes which are the minimum (set to 60) and maximum ( set to 100) speed Modify the run() method in Tracker.java If error>0, we move forward Otherwise, we move backward

public void run(){ while ( running ) { distance = us.getDistance(); if ( distance != 255){ error = distance -threshold; power = (int)(Pgain * error); if ( error > 0 ) { …………… } else { ……………. } Delay.msDelay(200); }

Outline A Car class Ultrasonic tracker – Naive Threshold – Method based Threshold – Proportional Control Light sensor based line follower – Naïve line follower – PID controlled line follower

Lab 5: Straight Line Follower Fix a bug that determines the light sensor input is white or black How to control the two motors?

Overview of PID Controller The Setpoint (SP) is the value that we want the process to be If the SP and the Process Variable PV are the same – then the controller is a very happy little box

Usage Scenario We want the AC in our classroom to achieve a steady temperature of as close to 22°C as possible What should we do?

Another Example How you drive a car on windy freeway ? Basically, you are a blackbox controller

The Blackbox: PID Controller

PID? Proportional: multiplies the Error by the Gain (Kp) Integral: the sum of instantaneous errors over time Derivative: a mathematical term meaning rate-of-change. It predicts future errors

Effects of increasing a parameter independently ParameterRise timeOvershootSettling time Steady-state error Stability DecreaseIncrease Small change DecreaseDegrade DecreaseIncrease EliminateDegrade Minor change Decrease No effect in theory Improve if small

Principle ? React faster: Kd Move steadily: Ki Try different parameters to make your car run faster and more steadily on the given track

How to Tune the Parameters …… PIDController pid = new PIDController (threshold, 10); pid.setPIDParam(PIDController.PID_KP, 12.0f); pid.setPIDParam(PIDController.PID_KI, 0.009f); pid.setPIDParam(PIDController.PID_KD, 300.0f); ……

PID Controller in Java (1/3) public int doPID(int processVariable){ int outputMV; this.PV = processVariable; error = setpoint - processVariable; if(Math.abs(error)<=deadband){ error=0; } if (!disableIntegral) { integral += Ki * error * dt; }

PID Controller in Java (2/3) if (integralLimited){ if (integral>integralHighLimit){ integral = integralHighLimit; } if (integral<integralLowLimit) { integral = integralLowLimit; } derivative = ((float)(error - previous_error))/dt; outputMV = (int)(Kp*error + integral + Kd*derivative);

PID Controller in Java (3/3) if (outputMV>highLimit){ outputMV=highLimit; } if (outputMV<lowLimit){ outputMV=lowLimit; } previous_error = error; outputMV=rampOut(outputMV);

Lab 6: public static void PIDControl(PIDController pid){ pid.setPIDParam(PIDController.PID_KP, 12.0f); pid.setPIDParam(PIDController.PID_KI, 0.009f); pid.setPIDParam(PIDController.PID_KD, 300.0f); pid.setPIDParam(PIDController.PID_LIMITHIGH, 200.0f); pid.setPIDParam(PIDController.PID_LIMITLOW, f); pid.setPIDParam(PIDController.PID_I_LIMITHIGH, 0.0f); pid.setPIDParam(PIDController.PID_I_LIMITLOW, 0.0f); pid.setPIDParam(PIDController.PID_DEADBAND, 1); } Insert this function inti BlakcWhiteSensor.java We want to see how these parameters work with PID controller

Reference leJOS official tutorial leJOS API documentation