Course
Robotics: Kinematics and Mathematical Foundations
Curso sobre introdução de aspectos matemáticos e cinemáticos aplicados a robótica
Modules (8)
-
Matlab Tutorial
Hi, this tutorial is designed to introduce students to math lab online and is used in solving programming assignments for this course. The goal of this assignment is to help in visualizing the key concepts starting this course. Let's get started. The first window we observe is the problem description, where details regarding the assignments and it's requirements are mentioned. This section often contains links to download files for your desktop MathLab. We recommend using the desktop version frequently when building your solutions, as it helps to inspect your variables and debug your code. For function problems, there are two code boxes. The first code box is where you implement the functions for the assignment and it will often contain some code to get you started. The second box is for testing, this box will consist of some code to test your function but can be modified to test for different scenarios. The Run Function button, runs the code and the code to call your function box and displays any output there. The Submit button, tests your function and returns your result. Let's see how this works. In this example, we're going to create a rotation matrix about the z-axis for a given angle and gradient, which is given by the equation in the problem description. So our task is to create a matrix according to the formula shown. Now that I think my function is done, let's use the run function button to test if my function works as expected. Always test the function before pressing Submit to make sure there aren't any syntactical errors. Great, our function runs and we see the rotated vector. Remember we can modify this code to test the function multiple times. Now that we think our function is correct, let's press Submit. Oops, looks like we made a mistake. Notice the two levels of feedback. The feedback in red is directly from the grading code. The feedback in black is the additional set of hints provided regarding possible errors. So in this case, I have the error because of the negative sign. So let me go ahead and update the code and try again. Great, now we have all green checks, implying that we have successfully passed the problem. Don't worry if you get stuck. Code rarely works the first time and problems in this course are quite challenging. So pat yourselves on the back when you get them right. When you want to get help in the forums, include three things in your posts. The assessment descriptions that failed, or that you have questions on. The red error message returned, as this can vary from the type of error. Description of your approach or pseudocode outlining your approach. Please do not post your actual code in the forums even if it is not working. Thank you.
-
Adding Files to the Search Path Robotics Fundamentals
Transcription As we write code or use files provided by others, we’ll want to organize them into separate folders. But what happens when we try to use these files? For example, let’s save this script in our folder “MyProject.” Let’s try calling our script from the command prompt. Hmmm… An error message? When we call a function or script, MATLAB first searches for this file in the current folder, before checking an ordered list of folders called the MATLAB Search Path. Notice in the Current Folder Browser that our folder name appears in a lighter shade, indicating that the folder is not on the Search Path. To ensure our file is found, we have two choices. The first option is to change our Current Folder to the project folder where the script is stored. The script name now appears in the Current Folder Browser in black letters, indicating that it will be found. Alternatively, if we frequently find ourselves using files from a specific folder, we can add that folder to the Search Path so that those files will be found regardless of the Current Folder. To view and change the Search Path we use the PATHTOOL command. Let’s add the folder “MyProject.” Notice that this folder is now first on our MATLAB Search Path. To keep this setting for our current MATLAB session only, we click CLOSE. To permanently add this folder for future sessions we choose SAVE. And that’s it! By adding folders to the search path, we can organize our code files the way we want, and still use them when we want.
-
Writing Functions Robotics Fundamentals
Transcription MATLAB includes thousands of ready-to-use functions that perform a variety of common tasks. But what if we need a custom function for our application? We can write our own MATLAB function. Let's see how. A MATLAB function consists of two parts: the declaration, and the body. The declaration begins with the keyword, FUNCTION, followed by how we will use, or call, the function. This means we provide the output variables, the function name, and the input variables. In the function body, we provide the set of commands to be executed each time the function is called. We use other MATLAB functions in combination with the inputs to create the output variables. Finally, we mark the end of the function with the keyword, END. That covers the syntax, but how do we use a custom function? Let's see how by doing an example. Suppose we need to sum the first n terms of a geometric series, which is given by this formula. The function only has a single output variable, s, which corresponds to the sum. The brackets are required when there are multiple outputs, but since we only have one output we can remove them. Function names follow the same conventions as the naming of MATLAB variables and should not overlap with existing function names. Let's call ours geoSum. To complete the declaration, we'll provide the list of input variables needed to compute a geometric sum: the common ratio, r, and the number of terms to sum, n. Next, we include the instructions for computing s in terms of r and n inside the function body. It's also good practice to provide comments below the function declaration for our future reference, or to communicate the intent to others. Now let's put this function to use. We can do this two different ways. If the function will be used in a single code file, we move the definition to the bottom of the script, and then call geoSum in the code above. When we run the script, our function is used to calculate the geometric sum. But what happens if we need our function in other code files or at the command prompt? Uh oh, red text usually isn't good. This error occurred because geoSum is currently a local function, meaning we can only use it in the script where it's defined. In this case, we need to create a separate code file that contains only the function definition. So let's delete the code above. Lastly, we save our file in the Current Folder, making sure that file name matches the function name. Now when we call geoSum at the command prompt, the two input values are passed to the function, the function body is executed, and the value of the output variable is returned. And just like that, there's one more function we can call. Hello, geoSum? I'd like the sum for r equals one-half and n equals infinity please. <sigh> Yes, I'll hold.
-
Troubleshooting Code with the Debugger Microrobotics
Transcription As we start combining many lines of code into scripts or functions, there are more opportunities to introduce mistakes. Sometimes our code will result in an error message, or it may produce an output that is different than we expect. Oops! Such errors are often called bugs. We can locate mistakes and fix errors using the debugger in MATLAB. Let's see how using this example. This code is meant to calculate the total account balance in interest earned on a vector of deposits and interest rates for each year. However, when we run the code we receive an error message. Hmm. There was a problem in line 7 of the code related to multiplication as referenced in the error message. To help determine the cause of the error, let's run the code again, but this time pause the execution of the code at the line where the error occurs. We do this using a breakpoint. With the code file open in the MATLAB editor, let's create a break point by left clicking on the dash next to line 7. A red circle is displayed on the line number indicating that we have set a breakpoint. Now when we run the file the command prompt changes to show us that we are in debug mode, and new buttons are available in the MATLAB editor toolstrip. We also see the current values of variables in the workspace. Notice that the loop variable, i, is one, and variable interest is zero because the code was stopped before line 7 was executed. We have two options for continuing code execution. We could use the "Continue" button to resume execution until another breakpoint is reached, an error occurs, or the code runs to completion. Or we can use the "Step" button to execute only the current line of code which is indicated by the green arrow. Since we don't know where the error is, let's use the step button to execute line 7 and advance the code one line. The variable interest is updated and we see it is a vector of six elements! We meant for interest to be a scalar value, so it looks like we might have found our error. In debug mode, we can type commands to test possible corrections. Here, what we meant to do was use the loop variable, i , to select a value from the vector rates. Since we found the error, let's press the "Quit Debugging" button, then update and save the code file. It's important to quit debugging because we can't save our changes in debug mode. Notice the breakpoint wasn't removed, and execution will pause here next time the code is run. To run the code without stopping, we removed the breakpoint by left clicking on it. Now let's run the code and... oops, another error? Do you see where the error is? If not try using the debug tools to find and fix the mistake. Set a breakpoint and "Step" or "Continue" through the code until you find the error. Pay attention to the dimensions of variables as the code iterates through the FOR loop.
-
Symbolic Calculations Robotics Fundamentals
Transcription Up to now, we've been doing numeric calculations which are required in many real-world applications. Take the simple example of finding the solutions to a quadratic equation. We can quickly find the solutions numerically when we have the coefficients. However, sometimes we get imaginary roots. How can we determine when the solutions are real? If we look at the symbolic solution, we see that the expression inside the square root must be positive to have real roots. Let's see how we get to this solution using MATLAB and the Symbolic Math Toolbox. The first step is to define symbolic variables using the syms command. Symbolic variables differ from the numeric variables we've used so far because we don't have to assign value to them. We simply declare their existence and we can use them in calculations. Like here, we enter the generic quadratic equation, and assign the expression to the variable 'y'. Notice that 'y' automatically becomes a symbolic variable even though we didn't declare it as one. Now, to find the symbolic solution, we use the SOLVE function while setting 'y' equal to 0, and specifying 'x' as the variable to solve for. And bingo! The SOLVE function returns a variable with the two solutions that match the quadratic formula. But wait a second. There's something different about this last command. Because a single equal sign is the assignment operator, we used two equal signs to create a symbolic equation. Now what if we need to apply our solution to a specific example? In other words, we have to replace the symbolic variables 'a', 'b', and 'c' with fixed values. No problem. The SUBS function replaces symbolic variables with numbers or other symbolic expressions. Here's how it works. We need three inputs: the expression we wish to evaluate, the symbolic variables to replace, and the values to substitute in for the symbolic variables. The result is kept as an exact symbolic solution, rather than a numeric approximation. Perhaps you've noticed, our solution is not fully simplified. Let's fix that using the SIMPLIFY function. There we go, an exact solution to our quadratic equation. In many cases, we still need a numeric representation of our symbolic results. Again, no problem. We use the variable precision arithmetic, or VPA, function to view the exact solution as a number. The 2nd input to the VPA function specifies the number of digits to include in the output, and the output is still a symbolic variable. We have now worked through the essentials of solving an equation symbolically, and you can use these techniques to solve a wide variety of problems. Before we close, here are a few examples from other applications that often arise, like finding integrals, doing series expansions, and plotting equations of one or more variables. Now put away the pen and paper, and try solving a few problems in MATLAB yourself.
-
MATLAB and Simulink in Industry
MATLAB is a high level programming language that is easy to use for rapid prototyping of algorithms. It was designed to work efficiently with matrices and linear algebra operations, which makes MATLAB a great tool for the types of math and image processing techniques needed for robotics. However, it is widely used in many industries making it a valuable skill to have. Even Google is looking for people who know MATLAB. Simulink is a graphical programming environment well suited for controls and time-based simulations. Simulink enables engineering groups to model specific components, and then combine individual models to simulate an entire system. MATLAB and Simulink both support code generation. With a push of a button, MATLAB code and Simulink models are ready for deployment to hardware, reducing the time from design and simulation to prototype and production. Though we're only using a subset of these tools in the MicroMasters, by using MATLAB you'll gain valuable skills for current or future employers. If you're interested in learning more, look at these user stories describing how MATLAB and Simulink were used to accelerate the pace of science and engineering. Humanoid robot completes complex tasks like catching a ball. MIT uses MATLAB and Simulink to make the ATLAS robot drive a car. Delphi uses MATLAB for radar systems for autonomous vehicles.
-
Vector Algebra-Video 1.1
Transcription Hello and welcome to this unit on robotics fundamentals. Before we begin, I wanted to give you an idea of what the basic theme of this module will be about. Our goal here is to provide you with the mathematical tools that we're gonna need to talk about where things are in space. Now, this sounds like a relatively simple task and it is. But there are few subtleties that we're gonna need to get right. In order to get our thinking clear and so that we'll also gonna be able to write code to guide various robots. To motivate this problem imagine that you're trying to program a humanoid robot like this one. To pick up a cup. You may start by developing a system to locate the cup with respect to the camera system, which is embedded in the head of the robot. Now, you may also be interested in figuring out where that cup is with respect to the gripper that you're going to be using to actually manipulate the object. Both of these perspectives are important, and we need to be able to relate them in our thinking and in the code that we will ultimately write. Now, one of the basic tools that we're going to using to talk about where things are goes all the way back to Descartes. He proposed this idea of a Cartesian coordinate frame of reference. Here, we're depicting this in the plane. The basic idea is pretty simple. We start with a partition plane of reference depicted here by these two axis, x and y at an implicit origin right here. Once we've established this coordinate frame of reference, we can talk about the location of points in the plane, by associating them with tuples. Denoting their coordinates with respect to this frame of reference. Note that we could also use this kind of representation to talk about vectors, corresponding to directions in the plane, or displacements. Here for instance we can think of a displacement vector. Which is represented by this tuple. Indicating a displacement of one unit along the x axis. And three units along the y axis. Let's call these tuples of numbers stacked up vertically vectors, here we're showing an example of vector v associated with this tuple here, 2, 1. We will say that v is an element of R2 to denote the fact that it's composed of two real numbers as opposed to say two complex numbers. We'll have more to say about vectors in this form in subsequent modules. Given this representation it is natural to imagine simple algebraic operations like multiplication by a scalar or addition. It the first example we can imagine a vector. 1, 2, being multiplied by a scalar, in this case five. The operation proceeds by simply multiplying each of the elements in that vector in turn by the scale of five. In this case the result would be a new tubal 5, 10. Where the first entry is simply 5 times 1 and the second is 5 times 2. Another operation that we can imagine is addition. Here we have two vectors, 3, 7 and minus 5, 2 and the sum of those two vectors corresponds to this third result. -2, 9, where here again, the first element, -2, is the sum of 3 and -5, and the second element is the sum of 7 and 2. Basically, we're simply adding corresponding elements in the vector together. Now, we can actually place a kind of geometric interpretation on these algebraic operations. Here for instance, if we think of each of these tuples as corresponding to a vector in space, scalar multiplication corresponds to scaling of vector by that amount. So here, we can imagine starting with initial vector v and scaling it by a factor a which corresponds to scalar multiplication, I'm getting a new vector a times v. Similarly, we can imagine two vectors v and w represented by tuples in the plane consisting of two numbers. And think of their algebraic sum as corresponding to a new vector which represents the result of adding these two vectors head to tail. Note, that there is nothing special About the number 2 here other than the fact that elements of R2 correspond very naturally to points in the Cartesian...
-
Vector Algebra-Video 1.2
Transcription In the last module, we started talking about vectors. And we described some very basic algebraic operations we could perform on vectors. Namely, multiplication by scalar and addition. In this module, we're going to introduce a third basic operation that can be performed on vectors. The name of this operation is the inner product and we can define it as follows. The inner product takes two vectors, in this case, we'll consider vectors v and w to be an R2. The result of the inner product is a scalar value which is computed by multiplying corresponding elements into the vector together and then adding the result. In this case, the vector v is represented by a topple of two numbers v1 and v2. And w is represented by this topple, w1 and w2. The inner product depicted by this v dotted with w is given by v1 times w1 + v2 times w2. Here we see two examples worked out. In the first, we're taking the dot product of 1, 2, and 3, 4. The result of this is 1 x 3 + 2 x 4, resulting in 11. And in this example, we're taking the dot product of 3- 5 and 2, 1. The result of this Is the scalar value, 1. More generally, we can apply this in a product operation to vectors in Rn. We simply multiply corresponding elements of the two vectors together, and add the products together to form the final result. Here we're showing an example, operating on vectors in R3. So 1, 2, 5, dotted with 3, 4, -1, results in 1 x 3 + 2 x 4 + 5 x (-1) and the result of this operation is the scalar value 6. If we take the inner product of a vector with itself, we end up with a positive number, which corresponds to the sum of the squares of the entries. Here, for example, we're taking the inner product of a vector v, which lives in R2, with itself and the result is simply x squared + y squared. Now, we can interpret this quantity as the square of the length of the vector, as shown below. This quantity, which refers to as the norm of the vector is depicted with this symbol. Expressing this idea algebraically, we can write that the norm of the vector squared is = to the duct product of the vector v, with itself. Or, equivalently, that the norm of the vector is = to the square root of the inner product of the vector with itself. This slide depicts graphically, what the previous slide was expressing algebraically. Here, we can think of the vector v in terms of its coordinates along the x and the y axis. And we note that the norm of the vector corresponds to the length of this side of the triangle. And that this length is going to correspond to the square root of x squared plus y squared cuz the Pythagoras's theorem.