Robotics: Kinematics and Mathematical Foundations Public

Robotics: Kinematics and Mathematical Foundations

Thiago Carlos
Course by Thiago Carlos, updated more than 1 year ago Contributors

Description

Curso sobre introdução de aspectos matemáticos e cinemáticos aplicados a robótica

Module Information

No tags specified
No tags specified

Context

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.
Show less
No tags specified

Context

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.
Show less
No tags specified

Context

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.
Show less
No tags specified

Context

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.
Show less
No tags specified
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.
Show less
Show full summary Hide full summary