Written by Anthony McNicoll

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 1-1 The Web Wizards Guide to PHP by David A. Lash.
Advertisements

Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
Jason Howard. Agenda I. How to download robotc II. What is tele-op used for? III. How to build a basic tele-op program IV. Getting the robot to drive.
Lab7: Introduction to Arduino
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Creating a Console Application with Visual Studio
Chapter 1: Python Basics CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
A First Program Using C#
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
CSE 305 Theory of Database Tutorial on Connecting with Sybase from Java program and Developing GUI Jalal Mahmud, TA, CSE 305.
YourClassPage.com TM Inservice Quickstart Guide Getting YOUR classpage up and running!
Introduction to Programming Workshop 1 PHYS1101 Discovery Skills in Physics Dr. Nigel Dipper Room 125d
Geo CE-XM ch 4 Edited 10/14/05 1 The XM is the newest of the rovers, and unlike other units, it comes with software installed on the unit as well as using.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
CPSC1301 Computer Science 1 Overview of Dr. Java.
Active-HDL Interfaces Debugging C Code Course 10.
Variables and Functions. Open your Encoder program Let’s begin by opening the “Labyrinth Auto Straight” code. Save this file as Labyrinth with variables.
Configuring IQmol for Windows machines, use version!
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
I Power Higher Computing Software Development Development Languages and Environments.
Slide 1 Project 1 Task 2 T&N3311 PJ1 Information & Communications Technology HD in Telecommunications and Networking Task 2 Briefing The Design of a Computer.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
Java Programming, Second Edition Appendix A Working with Java SDK 1.4.
CSC 1010 Programming for All Lecture 2 Introduction to Python Some material based on material from Marty Stepp, Instructor, University of Washington.
Creating a Java Application and Applet
Building a Web Page. Create A New Folder  Right click on the desktop and select New / Folder  Name the folder playpen.
NOTEPAD++ Lab 1 1 Hanin Abdulrahman. Downloading Hanin Abdulrahman 2  Click here to downlaod Notepad++.here  For Mac users, try Textmate or Textwrangler.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Excel Tutorial 8 Developing an Excel Application
Fundamentals of Programming I Overview of Programming
C++ First Steps.
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Development Environment
Getting started with the Arxterra software and 3DoT Firmware
Introduction to GIS PythonScript CGIS-NURIntroduction to ArcGIS II.
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2017
Topics Introduction to Functions Defining and Calling a Void Function
WORKSHOP 19 HATCHBACK III
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Completing the Problem-Solving Process
Tutorial: How to Creat a Website.
Using a set-up file to read ASCII data into SPSS
Introduction to Programming
Variables, Expressions, and IO
Functions CIS 40 – Introduction to Programming in Python
Introduction to C Topics Compilation Using the gcc Compiler
Using Procedures and Exception Handling
Microsoft Office Illustrated
CS 2340: Programming in VB Instructor: Dr. Qi Yang Office: 213 Ullrich
Debugging with Eclipse
Escape sequences: Practice using the escape sequences on the code below to see what happens. Try this next code to help you understand the last two sequences.
8 6 MySQL Special Topics A Guide to MySQL.
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Stata Basic Course Lab 2.
Scripts In Matlab.
Review of Previous Lesson
Input and Output Python3 Beginner #3.
Mu Editor – New User Cheat Sheet – CircuitPython Mode
Mu Editor – New User Cheat Sheet – CircuitPython Mode
Debugging with Eclipse
Microsoft Excel 2007 – Level 2
Workshop for Programming And Systems Management Teachers
Programming for Business Computing Introduction
Presentation transcript:

Written by Anthony McNicoll (am859@cornell.edu) PyLoader Tutorial How to use Python to write tests for and interface with freeLoader machines Updated 8/12/14 Written by Anthony McNicoll (am859@cornell.edu)

freeLoader Background Applies + measures compressive and tensile loads Motor is Dynamixel MX-64, communicates over serial Load cell + interface from Loadstar, also over serial Highly configurable

Python Background Legible, easy to learn, well-documented, open source Python 2.xx simply installs using one .exe file Edit with text editor, run by double-click or command Object oriented: Files may contain scripts that just run Files may also define functions Files may also define classes: Classes represent objects They have attributes (values of interest) They have methods (functions operating on that class) Functions and classes can be imported into other files Careful: Code blocks are defined using tabs, not braces

What It Looks Like Block comments with “””, single line with # Variables are declared implicitly, like MATLAB Definitions, ifs, loops defined with colon and indented (4 spaces) code Only data types of interest are string, int (round numbers) and float (decimal numbers)

Code Structure Overview

Using the Freeloader Class Use import statement: Create a Freeloader object and connect: Use any of the methods defined for a Freeloader: from freeloader import Freeloader, FreeloaderError machine = Freeloader() # machine could be any name machine.autoconnect() # will find motor, cell for you machine.start_motor(30, down = True) # Go down at 30 mm/min machine.stop_motor() # Stop the motor machine.get_raw_encoder() # Get pos. as 0-4096 machine.get_linear_position() # Get pos. as mm machine.reset_linear_position() # Set pos. as mm to 0 machine.read_raw_cell() # Get string from load cell machine.read_cell() # Get load as float machine.disconnect() # Close serial ports

Writing a Test using BasicTest, Part I Things to understand: A BasicTest is a class containing useful methods, like collect_until(), that make test writing easy To take advantage of these, you must write a new class which inherits from a BasicTest. From there, you must override (re-define) whatever you need for your test. At minimum, the run_test() routine must be defined. Start by copying source code from the closest existing test As of this writing, a tension test is available Give your new class an appropriate name: class NewCompTest(BasicTest): # Compression test

Writing a Test using BasicTest, Part II If collecting more than load and position, you will need to override (re-define) the default collect_data method. For instance, imagine reading an analog pressure sensor: To access the test’s Freeloader, use self.fl You can use any Python code you want here. For example, you can connect to an Arduino and collect data from it as well.

Writing a Test using BasicTest, Part III Define the run_test() routine. First, define columns and initialize the data set: If needed, collect data from user: Define test procedure using commands on next slide. Call self.fl.disconnect() to safely stop things. Build a header string if needed (see tensiontest.py) Call self.write_file(header) to write data to a file. self.set_columns([‘time’,’position’,’load’,’pressure’]) self.initialize_data() max_dist = float(raw_input(“Move no further than: “))

BasicTest Method Quick Reference point = self.collect_data() # get a fresh data point lload = self.get_last_value(‘load’) # Get last value of ? fpres = self.get_first_value(‘pressure’) # Get first value of ? lpoint = self.get_last_point() # Get last point as list fpoint = self.get_first_point() # Get first point as list all_load = self.get_all_values(‘load’) # Get list of recorded ? self.data # 2D list of all data self.Initialize_data() # Call at test start self.run_test() # Never call self.collect_until(‘distance’,’lessthan’,20) # Collect until condition self.collect_for(2.3) # Collect for time self.wait_until(‘load’,’greaterthan’,25) # Wait until condition self.wait_for(5) # Wait for time self.collect_until_keyboard() # Collect until key press self.wait_for_keyboard() # Wait for keyboard self.write_file(“Time,Position,Load,Pressure”) # Write data file Look at the HTML pages in the Documentation folder for complete descriptions of every method and available arguments.

Quickstart Python Tips Python 3 is “newer” but not as well supported as Python 2.XX, so stick with that. I used Python 2.7. Download and install that, as well as pySerial, which are both exe’s. You can just use Sublime Text to edit code if you have it, or Notepad++. Python programs can run by simply double-clicking the source file. Google something like “Notepad++ Python Tabs Spaces” and make sure your editor uses spaces for tabs For debugging, it’s useful to open a command prompt, cd to the directory your code is in, and run a command like “python basictest.py”. If there is a syntax error or exception, it will stay on the screen so you can investigate it. In Sublime, you can also hit Ctrl+B.