Mechatronics Laboratory Assignment 3 Introduction to I/O with the F28335 Motor Control Processor

Similar documents
GE423 Laboratory Assignment 6 Robot Sensors and Wall-Following

Mechatronics Laboratory Assignment 5 Motor Control and Straight-Line Robot Driving

Mechatronics Engineering and Automation Faculty of Engineering, Ain Shams University MCT-151, Spring 2015 Lab-4: Electric Actuators

ME 461 Laboratory #5 Characterization and Control of PMDC Motors

Lab 1: Steady State Error and Step Response MAE 433, Spring 2012

Exercise 3: Sound volume robot

EE 314 Spring 2003 Microprocessor Systems

GE 320: Introduction to Control Systems

Project Proposal. Underwater Fish 02/16/2007 Nathan Smith,

Iowa State University Electrical and Computer Engineering. E E 452. Electric Machines and Power Electronic Drives

Motomatic Servo Control

ME 461 Laboratory #2 Timers and Pulse-Width Modulation

ECE 477 Digital Systems Senior Design Project Rev 8/09. Homework 5: Theory of Operation and Hardware Design Narrative

EEL5666C IMDL Spring 2006 Student: Andrew Joseph. *Alarm-o-bot*

Understanding the Arduino to LabVIEW Interface

EE 308 Lab Spring 2009

Training Schedule. Robotic System Design using Arduino Platform

2.017 DESIGN OF ELECTROMECHANICAL ROBOTIC SYSTEMS Fall 2009 Lab 4: Motor Control. October 5, 2009 Dr. Harrison H. Chin

Debugging a Boundary-Scan I 2 C Script Test with the BusPro - I and I2C Exerciser Software: A Case Study

Introduction. Theory of Operation

UNIVERSITY OF VICTORIA FACULTY OF ENGINEERING. SENG 466 Software for Embedded and Mechatronic Systems. Project 1 Report. May 25, 2006.

DASL 120 Introduction to Microcontrollers

EE 308 Spring S12 SUBSYSTEMS: PULSE WIDTH MODULATION, A/D CONVERTER, AND SYNCHRONOUS SERIAN INTERFACE

Brian Hanna Meteor IP 2007 Microcontroller

Sten-Bot Robot Kit Stensat Group LLC, Copyright 2013

Brushed DC Motor Microcontroller PWM Speed Control with Optical Encoder and H-Bridge

3.3V regulator. JA H-bridge. Doc: page 1 of 7

DC motor control using arduino

PIC Functionality. General I/O Dedicated Interrupt Change State Interrupt Input Capture Output Compare PWM ADC RS232

DSP BASED SYSTEM FOR SYNCHRONOUS GENERATOR EXCITATION CONTROLL

University of Michigan EECS 311: Electronic Circuits Fall 2009 LAB 2 NON IDEAL OPAMPS

ESE 350 Microcontroller Laboratory Lab 5: Sensor-Actuator Lab

Linear Motion Servo Plants: IP01 or IP02. Linear Experiment #0: Integration with WinCon. IP01 and IP02. Student Handout

Lab Exercise 6: Digital/Analog conversion

CSE 3215 Embedded Systems Laboratory Lab 5 Digital Control System

Figure 1: Motor model

AN ARDUINO CONTROLLED CHAOTIC PENDULUM FOR A REMOTE PHYSICS LABORATORY

EE-110 Introduction to Engineering & Laboratory Experience Saeid Rahimi, Ph.D. Labs Introduction to Arduino

University of North Carolina-Charlotte Department of Electrical and Computer Engineering ECGR 3157 Electrical Engineering Design II Fall 2013

Sensors and Sensing Motors, Encoders and Motor Control

CHAPTER-5 DESIGN OF DIRECT TORQUE CONTROLLED INDUCTION MOTOR DRIVE

Massachusetts Institute of Technology. Lab 2: Characterization of Lab System Components

Experiment 4.B. Position Control. ECEN 2270 Electronics Design Laboratory 1

Project Final Report: Directional Remote Control

UNIT 2: DC MOTOR POSITION CONTROL

Arduino Control of Tetrix Prizm Robotics. Motors and Servos Introduction to Robotics and Engineering Marist School

Development of a MATLAB Data Acquisition and Control Toolbox for BASIC Stamp Microcontrollers

Analog I/O. ECE 153B Sensor & Peripheral Interface Design Winter 2016

Design of stepper motor position control system based on DSP. Guan Fang Liu a, Hua Wei Li b

HAW-Arduino. Sensors and Arduino F. Schubert HAW - Arduino 1

Index Terms IR communication; MSP430; TFDU4101; Pre setter

Total Hours Registration through Website or for further details please visit (Refer Upcoming Events Section)

LM4: The timer unit of the MC9S12DP256B/C

Built-in soft-start feature. Up-Slope and Down-Slope. Power-Up safe start feature. Motor will only start if pulse of 1.5ms is detected.

Hydraulic Actuator Control Using an Multi-Purpose Electronic Interface Card

32-bit ARM Cortex-M0, Cortex-M3 and Cortex-M4F microcontrollers

Electronics Design Laboratory Lecture #9. ECEN 2270 Electronics Design Laboratory

DESIGN OF AN EMBEDDED BATTERY MANAGEMENT SYSTEM WITH PASSIVE BALANCING

ENGR 1110: Introduction to Engineering Lab 7 Pulse Width Modulation (PWM)

Lecture 2 Exercise 1a. Lecture 2 Exercise 1b

SonoLab Echo-I User Manual

Aerial Photographic System Using an Unmanned Aerial Vehicle

Activity 4: Due before the lab during the week of Feb

B RoboClaw 2 Channel 30A Motor Controller Data Sheet

1. Controlling the DC Motors

J. La Favre Using Arduino with Raspberry Pi February 7, 2018

Page 1/10 Digilent Analog Discovery (DAD) Tutorial 6-Aug-15. Figure 2: DAD pin configuration

Sensors and Sensing Motors, Encoders and Motor Control

Part (A) Using the Potentiometer and the ADC* Part (B) LEDs and Stepper Motors with Interrupts* Part (D) Breadboard PIC Running a Stepper Motor

Generating DTMF Tones Using Z8 Encore! MCU

University of Pittsburgh

RX23T inverter ref. kit

Attribution Thank you to Arduino and SparkFun for open source access to reference materials.

Figure 1. Digilent DC Motor

ECE2049: Embedded Systems in Engineering Design Lab Exercise #4 C Term 2018

ME 461 Laboratory #3 Analog-to-Digital Conversion

FABO ACADEMY X ELECTRONIC DESIGN

Speed Measurement Method for Digital Control System

International Journal of Advanced Research in Electrical, Electronics and Instrumentation Engineering. (An ISO 3297: 2007 Certified Organization)

ME 333 Assignment 7 and 8 PI Control of LED/Phototransistor Pair. Overview

Electric Bike BLDC Hub Motor Control Using the Z8FMC1600 MCU

Project Proposal. Low-Cost Motor Speed Controller for Bradley ECE Department Robots L.C.M.S.C. By Ben Lorentzen

Study of M.A.R.S. (Multifunctional Aero-drone for Remote Surveillance)

ME 3200 Mechatronics I Laboratory Lab 8: Angular Position and Velocity Sensors

PSoC Academy: How to Create a PSoC BLE Android App Lesson 9: BLE Robot Schematic 1

Brushed DC Motor PWM Speed Control with the NI myrio, Optical Encoder, and H-Bridge

Brushless DC motor drive board evaluation

Motor Control using NXP s LPC2900

Modeling, Simulation and Implementation of Speed Control of DC Motor Using PIC 16F877A

Lab 2: Introduction to Real Time Workshop

A Model Based Digital PI Current Loop Control Design for AMB Actuator Coils Lei Zhu 1, a and Larry Hawkins 2, b

L E C T U R E R, E L E C T R I C A L A N D M I C R O E L E C T R O N I C E N G I N E E R I N G

CHAPTER 4 HARDWARE DEVELOPMENT OF STATCOM

Introducing the Quadrotor Flying Robot

Development of Control Algorithm for Ring Laser Gyroscope

TMS320F241 DSP Boards for Power-electronics Applications

ECE 511: FINAL PROJECT REPORT GROUP 7 MSP430 TANK

High-speed and High-precision Motion Controller

In this activity, you will program the BASIC Stamp to control the rotation of each of the Parallax pre-modified servos on the Boe-Bot.

AC : PERSONAL LAB HARDWARE: A SINE WAVE GENERATOR, LOGIC PULSE SIGNAL, AND PROGRAMMABLE SYNCHRONOUS SERIAL INTERFACE FOR ENHANCING EDUCATION

Transcription:

Mechatronics Laboratory Assignment 3 Introduction to I/O with the F28335 Motor Control Processor Recommended Due Date: By your lab time the week of February 12 th Possible Points: If checked off before your lab time the week of Feb. 19 th 10 points If checked off after your lab time the week of Feb. 19 th and before your lab time the week of Feb. 26 th 7 points If work not finished before your lab time the week of Feb. 26 th 0 points Goals for this Lab Assignment: 1. Work with wheel angles measured by the motor s Optical Encoders and write to both PWM and DAC output channels. 2. Estimate Velocity from Optical Encoder Position Feedback. 3. Identify the friction in the robot s drive system. DSP/BIOS Objects Used: PRD, SWI Library Functions Used: Global variables Enc1_rad, Enc2_rad, Enc3_rad and Enc4_rad. Funcutions void writedac7564(float dac1,float dac2), void PWM_out(enum epwm ep, float u), void init_pwm(enum epwm ep) Prelab: Read the first few pages of the TMS320F28335datasheet http://coecsl.ece.illinois.edu/ge423/datasheets/f28335ref_guides/f28335datasheet.pdf to familiarize yourself with the robot s motor control processor. Laboratory Exercise Up to this point, lecture and lab have been focused on the MSP430G2553 microcontroller used in your homework assignments and the dual core OMAPL138 processor on your robot vehicle. In this lab and also lab assignments 4 and 5 we are going to switch gears a bit and focus on another processor on the robot s circuit board that takes care of the motor control and acquisition of many of the robot s sensors. This chip is named the TMS320F28335. Texas Instruments categorizes this processor as a microcontroller but just for marketing reasons. It is actually one of TI s first DSP series. Looking at its datasheet http://coecsl.ece.illinois.edu/ge423/datasheets/f28335ref_guides/f28335datasheet.pdf and Figure 1 below it is much more powerful than a standard microcontroller. The TMS320F28335 is clocked at 150MHz, has 67Kb of internal RAM, 512Kb of program flash and a large number of peripherals. The peripherals we are most interested in for our robot vehicle are the ADC (Analog to Digital) inputs, Optical Encoder inputs, PWM outputs and SPI and I2C serial ports. In addition to the on-chip peripherals of the TMS320F28335, external chips and sensors have been added to the robot s circuit board to interface with the TMS320F28335 giving it even more capabilities. See Table 1 for a list of inputs, outputs and sensors the TMS320F28335 provides for the robot. GE423, Mechatronic Systems Lab 3, Page 1 of 8

Figure 1: Pictorial of the Many Capabilities of the TMS320F28335 Processor GE423, Mechatronic Systems Lab 3, Page 2 of 8

On Chip Peripherals Off Chip Peripherals Sensors/Actuators Interfaced by these Peripherals 1. 12 PWM Outputs 1. 4 Optical Encoder Inputs 1. +/- 400 deg/s Rate Gyro 2. 16 ADC Inputs 2. 2 DAC Outputs 2. Ultrasonic Distance Sensors 3. 2 Optical Encoder Inputs 3. IR Distance Sensors 4. SPI serial port 4. Compass 5. I2C serial port 5. 6 Optical Encoder Sensors 6. UART serial port 6. 6 RC Servos 7. McBSP serial port 7. 2 DC Motors 8. Text LCD Screen 9. 4 Toggle Switches 10. 2 LEDs Table 1: TMS320F28335 Capabilities used by Mechatronics Robot Vehicle. In this lab we are not going to focus on learning a new aspect of the DSP/BIOS real-time operating system, instead we are going to focus on using the Optical Encoder inputs, DAC (Digital to Analog Converter) outputs and PWM (Pulse Width Modulation) outputs. In Lab 4 we will take a more detailed look at the source code given by the F28335 project creator and also study the circuit board design of the robot s processor board. So you are not completely in the dark about the source code given, a brief description is in order. To read four of the possible six optical encoder sensors that can be connected to the robot s processor board, four LS7366 chips are interfaced to the TMS320F28335 through its SPI serial peripheral. These LS7366 chips are 32 bit counters that count up when the optical encoder is turned in the positive direction and count down when turned in the opposite direction. So the TMS320F28335 uses its SPI serial port to read this 32 bit count from each of the LS7366 chips. The TMS320F28335 has a peripheral for generating PWM signals so no addition circuits are needed for PWM outs. In the case of the DAC outputs, the TMS320F28335 does not have a DAC peripheral. So in addition to the LS7366 chips connected to the TMS320F28335 s SPI serial port there is a DAC7564 chip connected to the SPI serial interface giving the TMS320F28335 two channels of 0-2.5V 12bit DAC output. The TMS320F28335 code s purpose is twofold. One is to acquire all the sensor information every 1 millisecond and communicate this information to the OMAPL138 through another serial port called the McBSP serial port. Second is to perform the speed control of the robot s motors also every 1 millisecond. In lab 4 you will be developing code to add the acquisition of the sensors connected to the ADC peripheral of the TMS320F28335. In lab 5 you will develop the motor control algorithm. So in the TMS320F28335 project creator s default code, what happens each 1 millisecond? 1. A PRD object calls its function void start_datacollection(void) every 1 millisecond. Inside this function all that is done is call the function start_spi(). Start_SPI() selects all four of the LS7366 chips and sends a command to them over the SPI to latch the current reading of their connected optical encoder. Start_SPI() does not wait for the 8bits of data to be transmitted. It starts the SPI transfer in the SPI peripheral unit. After Start_SPI() initiates the transfer, the function GE423, Mechatronic Systems Lab 3, Page 3 of 8

ends, leaving the processor free for other tasks while the SPI peripheral handles the SPI transfer. Once the transfer is complete, the SPI s receive interrupt takes care of the next steps in reading the four LS7366 chips. 2. After transmitting the 8 bit command to latch the four LS7366 readings, the SPI serial port generates a Receive interrupt (we are not using the SPI Transmit interrupt with the F28335) indicating that the transfer is complete. On receiving this interrupt the HWI function void SPI_RXint(void) is called. 3. Inside the SPI_RXint interrupt function, the TMS320F28335 selects the first LS7366 chip and sends it a command to return its 32bit count value. 4. On receiving the SPI s next interrupt the SPI_RXint interrupt function knows that the 32bit count reading is sitting in the SPI s FIFO buffer. After reading the data from the first LS7366 chip, the function will select the second LS7366 chip and sends it the command to return its 32bit count value. 5. This reading of the remaining LS7366 chips repeats three more times to acquire the count readings of the remaining 3 LS7366 chips. 6. On the final SPI receive interrupt that indicates the fourth count value has been communicated from the fourth LS7366 chip the SWI SWI_control is posted. The SWI s function is void control(void). 7. Here in this function void control(void) is where you will be putting your own code, but before your code the function updatedata(); needs to be called. updatedata() checks if there is any new sensor readings from the slow sensors like the compass and IR distance sensors and communicates those values to your code in predefined global variables. 8. After updatedata() returns is where you should insert your code. At this point you have all the sensor readings at your access. 9. After your code you should call the function senddata(). This function communicates all the data sampled by the TMS320F28335 to the OMAPL138 s DSP core through the McBSP (Multi Channel Buffered Serial Port) serial port. 10. Then when 1 millisecond occurs again the entire process is repeated. Your robot can only be sitting in two locations: on the floor or on a stand on the bench with all wheels off the bench. Failure to do so may result in robot suicide, i.e. the robot may suddenly drive itself off the bench. If a student catastrophically breaks their robot, both the instructor s and the student s lab work will triple. Both will still have to come to lab, both will have to come after lab hours to use different group s robot to complete the lab, and both will have to come in after hours to repair the robot so it can be used in other lab sections. Exercise 1: Basic Input and Output 1. Create a new project using the Spr2018F28335ProjectCreator.exe executable found in \Spr2018F28335ProjectCreator directory of your repository. 2. As just summarized above the function void control(void) is the function for the SWI object SWI_control. SWI_control is posted every 1ms after the 4 LS7366 Optical Encoder interface chips have been read. You will be placing all the code you develop for this lab inside the control() function and in between the functions GE423, Mechatronic Systems Lab 3, Page 4 of 8

updatedata() and senddata(). At that point in the function control(), the motor s optical encoder sensors have been measured and are located in the variables Enc1_rad, Enc2_rad. There are also two other encoder readings sampled, Enc3_rad and Enc4_rad which are unconnected for Exercise 1. For this short exercise think of the wheels of the robot as input dials that change a numerical output value when rotated. We will send this numerical output value to the DAC and the PWM channels to test that they are working. Add the following functionality to the control() function: a. Normally we will be using PWM4 and PWM5 to drive RC servo motors. For laboratory 3 only we will setup PWM4 and PWM5 to produce the same 20KHz carrier frequency PWM signal the drives the two robot motors. This is done so that you can see the PWM signal on the oscilloscope. So towards the top of your main() function find the source lines init_pwm_as_rcservo(epwm4b); and init_pwm_as_rcservo(epwm5); and change them to init_pwm(epwm4); and init_pwm(epwm5); b. Every 1 ms (which is every time this function is called), send the radian value of encoder channels 1 & 2 to the PWM output channels 4 & 5. Also send a scaled value of the encoder channels 1 & 2 to the two DAC channels. In future labs you can use the DAC as a debug output to monitor the control effort sent over a PWM channel to a DC Motor s amplifier. The range of the PWM command is between -10 and 10. Our DAC can only output a range of 0 to 2.5Volts. Therefore scale the values sent to the DAC with the scale constant that converts the -10 to +10 range to 0 to 2.5. Send these scaled values to DAC channels 1 & 2. Use the function PWM_out() to command a PWM channel. For example PWM_out(EPWM4,5.0) would produce a 75% duty cycle square wave on PWM channel 4 s output. To write to both DAC channels use the function writedac7564(float dac1,float dac2) with the two parameters variables floats with values in the range 0 and 2.5. c. As in previous lab, use an integer variable to keep a count of the number of milliseconds elapsed. Using this count variable, print the elapsed time in milliseconds to the text LCD screen every 100ms. On the TMS320F28335 the function to write to the text LCD screen is LCDPrintfLine(unsigned char line, char *format,...). This function, as with the LCDPrintfLine function on the OMAPL138 processor, works the same as the ANSI C printf function except for the added first parameter that states which LCD line the text is to be printed. Additionally print to the second LCD line the radian measurements from optical encoder 1 and 2. Only print one decimal precision of these floating-point values so you can see the full values on the single 20 character line of the LCD. d. Also every 100ms, toggle on and off one of the LEDs of the TMS320F28335 control card. The LED is connected to pin GPIO34. To control the state of this pin (and whether the LED is on or off) use the bit field structure GpioDataRegs. To simply toggle the bit on and off as the assignment asks, use the toggle command GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1; to clear the IO bit use (FYI) GpioDataRegs.GPBCLEAR.bit.GPIO34 = 1; and to set the IO bit use (FYI) GE423, Mechatronic Systems Lab 3, Page 5 of 8

GpioDataRegs.GPBSET.bit.GPIO34 = 1; 3. If you have not already, connect the JTAG debugger to the TMS320F28335 s JTAG connector which is at the top left corner of the circuit board close to the TMS320F28335 Control Card. 4. Build and run your application to confirm it is working. NOTE that when you download code from CCS through the JTAG to the TMS320F28335 you are flashing your code to the TMS320F28335 s flash memory. This is the reason that it takes longer for the JTAG to download code to this processor. This is exactly the same thing that is happening when you are programing your microcontroller for your homework assignments. This means that after you have downloaded and debugged your code, the code is sitting in the flash ready to be run the next time you turn off and on the robot. 5. Verify your program by scoping the DAC outputs. While moving the wheels on the robot, the DAC voltage should vary between 0 and +2.5 volts. 6. Also verify your program by scoping the PWM outputs. While moving the wheels on the robot, the PWM duty cycle should vary from 0% to 100%. 7. Disconnect CCS from the robot and carefully remove the JTAG from the robot board. Test that indeed your program has been stored in the flash of the TMS320F28335 by turning off and on the robot and see that your program begins running again. 8. Set the robot on the ground and find the conversion factor from motor angle to length of a floor tile (1ft). Do this by lining up the robot s front wheels with the edge of a floor tile, turn off then on the robot to zero the encoder readings, push the robot three or four tiles and record the number of radians the motor s shaft has turned. This is easily done by printing the encoder count to the LCD screen. Record this radians-to-tile ratio as you will need it for calculations later in this lab and in the remainder of the class. 9. Check your ratio with your instructor before proceeding to next exercise. 10. Set the robot back on its stand on the table and reconnect the JTAG to the TMS320F28335 JTAG port. Exercise 2: Basic Feedback Calculations Partners switch places to allow other partner to program. For this lab we will attach a third optical encoder to Enc3_rad s input connector that you will be able to hold in your hand and use like a joystick to dial in an input to the robot. We will also no longer be using PWM outputs 4 and 5 which were just attached to the banana jacks for connecting to the oscilloscope. 11. Continue working with the same code as exercise #1 12. Create two global float variables u1,u2, to be used as the control outputs to PWM channels 1 and 2. Modify your previous code so that every 1ms the third optical encoder, which you can manually turn, is used as the command to drive the robot s two motors with the same value. This way you will have manual control of the robot moving forward and backward at different speeds. Perform the following: a. Set both u1 and u2 equal to Enc3_rad. NOTE, in later labs u1 and u2 will be assigned values calculated by a control algorithm. b. Limit u1 and u2 to a value between 10 and 10. c. Command EPWM1 and EPWM2 to the value of u1 and u2 using the PWM_out() function. GE423, Mechatronic Systems Lab 3, Page 6 of 8

13. Using the backwards difference rule (v = (p_current p_old)/0.001) as a discrete approximation to the derivative, calculate the linear velocity corresponding to each motor in tiles/second from the past and present motor position measurements, p_old and p_current respectively. 14. Print the velocity values of v1 and v2 on the first line, and the reading from encoder 3 on the second line of the LCD screen every 100 ms. You have to limit the accuracy of your floating-point number printed in order for all the information to be displayed completely on the 20 character LCD line. 15. Make sure that the robot is on the bench stand with wheels OFF the ground. Enable the PWM amplifier when running this code so the motors will spin. The amplifier is enabled by flipping up the switch on the robot s front amplifier board. When the motors start spinning check the direction they are spinning. Given a positive input, both of the motors should be spinning so they drive the robot forward. The back end of the robot is the end the battery can be inserted. If both of the motors do not move in the forward direction when sending a positive control effort, change the sign of the control effort for the motor that is spinning in the wrong direction. The best place to add this negative sign is in front of the parameter passed to the appropriate PWM_out() function. Do not change the sign of the control variable, e.g., if you think motor 1 is spinning the wrong way given a positive control input, add the sign change to the parameters of PWM_out()and do not do something like u1 = -u1; The sign change is necessary because the motors under the robot are mounted in opposite directions. When you have both motors spinning in the positive direction given a positive PWM input, check the signs of the two velocity readings. If either of the velocities is not positive you will need to change the sign of the encoder measurement. The easiest way to do this is before you use either the Enc1_rad value or Enc2_rad value, change the variable s sign with the command Enc1_rad = -Enc1_rad;. Of course change this statement using Enc2_rad if it is the variable with the wrong sign. Verify that your velocity (tiles/sec) calculation changes if you put a load on the wheels (by adding resistance to motion with your hand). Exercise 3: Friction Compensation In this final exercise you are going to implement a friction compensation algorithm to reduce the effects of the motor s friction on your system. Your task will be to identify the friction acting on the motor. To accomplish this you will produce a plot of applied motor control effort (or input) (on the y axis) vs. motor velocity (tiles/s) (on the x axis). You will first record 10 or so data points split between positive and negative values. Then by making a plot of your data, you can determine both the viscous and coulomb friction of the motors in both the positive and negative directions. 16. Using the third encoder to change the open loop command to the motors, record the steady state tile/sec velocity of the robot driving on the floor at 10 different control inputs. Be sure your measurements make sense if you read 1 tile per second from the LCD, then the robot should actually be moving approximately 1 tile every second. If the robot is driving too fast to measure the values, you will obviously have to use a smaller magnitude of control input. Be sure to measure both positive and negative velocity values (robot moving forward AND backward). 17. Produce a plot of control input vs. speed in MATLAB to show to your instructor. 18. Using two separate regression fits, one for positive velocities and one for negative velocities, find the two lines that best fit your measured data points in the positive and negative velocity regimes. Ask your instructor for help if you don t know how to quickly do a regression in MATLAB. From the best-fit lines, note the y intercepts. These are GE423, Mechatronic Systems Lab 3, Page 7 of 8

your values for positive and negative coulomb friction. We will label these values Cpos and Cneg (note Cneg will be a negative value). The slopes of the two lines are your values for positive and negative viscous friction. We will label these values Vpos and Vneg. 19. With these identified parameters, add the following friction compensation algorithm to your code (assuming your motor one command variable is called u1 ): if (v1> 0.0) { u1 = u1 + Vpos*v1 + Cpos; } else { u1 = u1 + Vneg*v1 + Cneg; } And perform similar instructions for u2 20. As a starting point use 100% (in future labs we will only use 60-80% of the identified values) of the values identified for Vpos, Vneg, Cpos, and Cneg. Compile your code. 21. Test your friction compensation code by pushing the robot when it is on the floor. Your robot should roll for a long distance if the friction compensation is working well. In your code make sure that only the friction compensation is activated for this section. The easiest way to do this is to assign u1 and u2 to zero each time in your code section instead of assigning u1 and u2 the value of Enc3_rad. You may need to hand tune your friction gains slightly to get the robot to roll for a good distance when you push it. Demonstrate your working code to your instructor. Lab Check Off: 1. Demonstrate your first application that reads optical encoder inputs 1 & 2 and echoes the radian values to PWM channels 3 & 4 and DAC channels 1 & 2. Scope the outputs to demonstrate your code is working. 2. Demonstrate your second application that drives the motor with an open loop PWM output and prints this control effort and both motor s speed to the LCD. 3. Show your instructor the plot of the motor control vs. velocity friction curve, and demonstrate your working friction compensation code by pushing the robot back and forth between partners. GE423, Mechatronic Systems Lab 3, Page 8 of 8