delta:build_own_controller:start
Differences
This shows you the differences between two versions of the page.
| delta:build_own_controller:start [2015/11/26 09:05] – [Constants] zeberli | delta:build_own_controller:start [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ======== Delta Roboter Tutorial - Build your own controller ======== | ||
| - | {{ : | ||
| - | ======= Preamble ======= | ||
| - | It took about three days to get to know EEROS and another two days to write this tutorial. If you find mistakes or have suggestion for improvement, | ||
| - | |||
| - | ======= Delta' | ||
| - | |||
| - | The package with the delta robot should include: | ||
| - | |||
| - | | Power Supply | ||
| - | | Lan cable | | | ||
| - | | USB hub with usb cable | {{: | ||
| - | | XBox controller with USB connector | ||
| - | | Mouse with scroll wheel left/right function | {{: | ||
| - | | Special: TTL-232R-3V3 Cable.\\You need this cable, if you don't know the delta' | ||
| - | | Special: Mini USB cable\\You need this cable, if you don't know the delta' | ||
| - | |||
| - | ====== Ready to play? ====== | ||
| - | You get your delta and of course you want to play with it and see what he can do. You can! But do as listed below:\\ | ||
| - | * First of all: **To turn off the delta, press the red stop button for 5 seconds or send a halt command to it and then switch the power off!** Don't plug out the power of your computer before it has shut down either. | ||
| - | * The red stop button stops the delta, theoretically it should restart afterwards. | ||
| - | * Please read the safety instructions, | ||
| - | |||
| - | After that you can start: | ||
| - | - Plug in power and the USB Hub connected with mouse and XBox adapter. Turn the XBox controller on. USB Devices plugged in after the start will not be recognized. | ||
| - | - Switch the power on. | ||
| - | - Wait until the white led's have turned off, during this time the BeagleBoard is starting. | ||
| - | - Press start. **Attention** delta will be moving!! | ||
| - | - You can now steer with the mouse: Move will move, scroll up and down will change the Z-position and pressing the scroll wheel to left or right will turn the magnet. | ||
| - | - Press the blue mode button. From then on the XBox controller now controls the delta. Move with right stick, up and down with the left stick and LT / RT to turn the Magnet. If this mode is skipped, check if the XBox controller has battery. | ||
| - | - Press the blue mode button again. The delta shows automatic moves. If you press the blue button again it starts the mouse mode again. | ||
| - | |||
| - | ====== Preparations ====== | ||
| - | ===== VM ===== | ||
| - | |||
| - | * Install Oracle VM Virtual Box Manager [[https:// | ||
| - | * 64-bit | ||
| - | * 8GB RAM | ||
| - | * Hard disk VDI (VirtualBox Disk Image) dynamic allocated, 50GB ROM | ||
| - | |||
| - | |||
| - | ===== Linux ===== | ||
| - | * Any 64-Bit Linux Version. | ||
| - | * This tutorial works with Linux Mint 17.2 Rafaela 64Bit [[http:// | ||
| - | * Remark for VM beginners: its easier to work if you allow copy/paste from host to target | ||
| - | * Set your computer name to **delta**. You can choose another name, but you have to adapt paths during this tutorial. | ||
| - | * Remember your password! | ||
| - | * Remember the snapshot function of Virtual Box? Make a snapshot after the clean Linux installation. | ||
| - | |||
| - | ===== EEROS ===== | ||
| - | * Download EEROS on your VM [[http:// | ||
| - | * You don't need comedilib or flink for this tutorial. | ||
| - | * Download EEROS to / | ||
| - | * Suggestion: make a snapshot of your VM after a successful download | ||
| - | * To test the EEROS installation, | ||
| - | |||
| - | ===== EEDURO ===== | ||
| - | * Download and install EEDURO on your VM from [[https:// | ||
| - | * As described in README.md, build for Host and Target. **Don' | ||
| - | |||
| - | ===== Putty ===== | ||
| - | * Download and install Putty on your host, not in your VM. [[http:// | ||
| - | |||
| - | ===== Credentials of delta ===== | ||
| - | * Ask your responsible advisor for username, password and IP- Address of the delta. | ||
| - | |||
| - | ======= Connect to delta ======= | ||
| - | Plug in the power supply, the USB hub with mouse and XBox and the lan cable. Then start the delta with the ON button. Wait till the BeagleBoard has booted and the white light has turned off. | ||
| - | The connection procedure depends the knowledge of the IP-Address. If you know it, you're lucky and you can proceed to [[start# | ||
| - | |||
| - | Remark to NTB students: with own laptop, you have to connect with VPN, otherwise it will not work. | ||
| - | |||
| - | ===== Get delta' | ||
| - | ==== With TTL232 and mini USB ==== | ||
| - | Turn off the power and remove all cables. Turn the delta upside down and open the bottom. Remove the BeagleBone Board and connect the mini USB and the TTL232 {{ : | ||
| - | Open your device manager and get the number of the COM, on which TTL232 is plugged in. | ||
| - | Then open Putty and connect with the following settings:\\ | ||
| - | |||
| - | {{: | ||
| - | |||
| - | Press Open. Follow the instructions under [[start# | ||
| - | |||
| - | After that, you want to get the IP-Address of delta. type " | ||
| - | |||
| - | ==== Only with mini USB ==== | ||
| - | Note: there is a way to get the delta' | ||
| - | |||
| - | * Connect the mini USB with the PC. | ||
| - | * Then open Putty and enter the IP address 192.168.7.2 and choose as Connection type SSH (see image). You will get a security warning, click yes. Then follow the instructions under [[delta: | ||
| - | {{: | ||
| - | * Tip to black window the the following instruction. Under the point eth0 you can find the IP-Adresse. | ||
| - | < | ||
| - | **Note:** If you are using Linux running on a VM, there could be some issues to connect the Delta-Roboter with the PC. Try to get remote control with Windows (driver needed) or get the serial connection done over TTL232. | ||
| - | ===== Connect to console====== | ||
| - | ==== From VM ==== | ||
| - | Usually you want to connect the delta with the VM. To do so, open a console and type: < | ||
| - | ==== From Host ==== | ||
| - | Open Putty, set the parameters as shown below and press " | ||
| - | {{: | ||
| - | |||
| - | |||
| - | ===== Login ===== | ||
| - | The first time you do this you will see a security alert in the putty console - press " | ||
| - | Then the following appears on the putty console: < | ||
| - | If you logged in successfully, | ||
| - | < | ||
| - | Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.8.13-bone63 armv7l) | ||
| - | * Documentation: | ||
| - | Last login: Wed Oct 7 11:34:45 2015 from 146.136.53.139 | ||
| - | root@arm: | ||
| - | </ | ||
| - | |||
| - | ====== Test programms ====== | ||
| - | The delta has test programms, which allow you to test several things. They are a perfect entry point. | ||
| - | Open your VM and [[start# | ||
| - | |||
| - | < | ||
| - | $ cd / | ||
| - | </ | ||
| - | List the files in this folder with | ||
| - | < | ||
| - | $ ls | ||
| - | </ | ||
| - | |||
| - | The following will be shown: | ||
| - | < | ||
| - | button | ||
| - | </ | ||
| - | |||
| - | The green color means that the files are executable, see more under [[http:// | ||
| - | To execute these test programms, you have to stop the actual program. Which starts every time you start delta. | ||
| - | |||
| - | - Type:< | ||
| - | - The console will write a lot of text. To stop it, press (Ctrl) + (c) for about 2-3 seconds. | ||
| - | - The programm is stopped if you can < | ||
| - | screen is terminating] | ||
| - | root@arm:/ | ||
| - | on your console. | ||
| - | |||
| - | Now load the button test program. Type: | ||
| - | |||
| - | < | ||
| - | |||
| - | If everything works fine, you can press the buttons and you get a log on the console: | ||
| - | |||
| - | < | ||
| - | button 1: up</ | ||
| - | |||
| - | |||
| - | You can see the source code of the button test programm here: / | ||
| - | |||
| - | You can also try out the other programms too. | ||
| - | |||
| - | Remark: Its not possible anymore to halt delta by pressing the button for 5 seconds. Instead type " | ||
| - | |||
| - | ===== Problems ===== | ||
| - | If your testprogram does not work, check README.md. | ||
| - | |||
| - | ====== Toolchain ====== | ||
| - | Now you want to write you own programm. But first you have to set up the toolchain.\\ | ||
| - | - Start KDevelop. If you still have the last session from [[start# | ||
| - | - Now click: Project, Open / Import Project. | ||
| - | - Navigate to: / | ||
| - | - Name the new Project " | ||
| - | - Change Build Directory to / | ||
| - | - Put the following to the extra arguments input field: | ||
| - | - Build. | ||
| - | - If you open the project view in KDevelop, you can unfold the eeduro-project and open copy2robot.sh. | ||
| - | - Change the setc remote_host " | ||
| - | - Execute the copy2robot script with the console. | ||
| - | - Now you have to go trough the chapter [[start# | ||
| - | |||
| - | Remark: Now is a good time to make another snapshot of your VM. | ||
| - | |||
| - | ===== Problems ====== | ||
| - | Be really careful with the additional includes, check if these files are where you expect them an check for typos. | ||
| - | |||
| - | ====== Your own testprogramm ====== | ||
| - | Now create a new testprogramm. The LED's inside the buttons should glow while they are pressed.\\ | ||
| - | Go to the folder / | ||
| - | |||
| - | Copy the following code into this file and program the missing fragment. | ||
| - | |||
| - | < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | |||
| - | int main(int argc, char *argv[]) | ||
| - | { | ||
| - | eeduro:: | ||
| - | |||
| - | if (!board.open("/ | ||
| - | std::cerr << " | ||
| - | return 1; | ||
| - | } | ||
| - | |||
| - | bool button[3] = { }; | ||
| - | while (true) { | ||
| - | board.run(); | ||
| - | for (int i = 0; i < 3; i++) { | ||
| - | do it yourself! | ||
| - | } | ||
| - | usleep(30000); | ||
| - | } | ||
| - | board.close(); | ||
| - | return 0; | ||
| - | } | ||
| - | </ | ||
| - | Note: if you are not able to write the code in on your own, the source code is in the [[/ | ||
| - | |||
| - | Then open CMakeList which is in the same folder. Add the following code to the end of the file: | ||
| - | |||
| - | < | ||
| - | add_executable(button_led button_led.cpp) | ||
| - | target_link_libraries(button_led eeduro eeros) | ||
| - | </ | ||
| - | |||
| - | Now go to copy2robot.sh and past the following line under the line with voltage: | ||
| - | |||
| - | < | ||
| - | cp build-armhf/ | ||
| - | </ | ||
| - | |||
| - | Execute copy2robot.sh. ([[start# | ||
| - | |||
| - | Now try to run the new test programm, as described [[start# | ||
| - | |||
| - | ======= Hello Structure ======= | ||
| - | |||
| - | Readers with experience in cmake can skip this chapter.\\ \\ | ||
| - | Bigger projects need to be well structured, so you have to organize your code in folders. | ||
| - | Lets create a project with this structure: | ||
| - | |||
| - | {{: | ||
| - | |||
| - | Create a new project in KDevelop, as usual, with Projects, Create New Project, Standard Terminal and enter the name structure_project in the location / | ||
| - | |||
| - | |||
| - | Now navigate to the new folder structure. As you can see, KDevelop has already created CMakeLists.txt(structure), | ||
| - | Create two folders one called " | ||
| - | ControlSystem.cpp and SafetyProperties.cpp. Open the folder " | ||
| - | \\ | ||
| - | |||
| - | Open the CMakeLists.txt(src) and paste the following into it: | ||
| - | < | ||
| - | add_executable(structure main.cpp ControlSystem.cpp SafetyProperties.cpp) | ||
| - | target_link_libraries(structure eeros eeduro) | ||
| - | </ | ||
| - | |||
| - | |||
| - | ControlSystem.cpp and SafetyProperties.cpp in add_executable are just written here that you see how you add them when you need these classes. " | ||
| - | Open the CMakeLists.txt(structure_project) and paste the following into it: | ||
| - | < | ||
| - | cmake_minimum_required(VERSION 2.8) | ||
| - | project(structure) | ||
| - | |||
| - | include_directories(${ADDITIONAL_INCLUDE_DIRS}) | ||
| - | link_directories(${ADDITIONAL_LINK_DIRS}) | ||
| - | |||
| - | set(CMAKE_CXX_FLAGS " | ||
| - | add_subdirectory(src) | ||
| - | </ | ||
| - | |||
| - | With add_subdirectory, | ||
| - | |||
| - | Open the main.cpp and paste the same code as in Hello World into it: | ||
| - | < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | |||
| - | int main() { | ||
| - | using namespace eeros:: | ||
| - | |||
| - | StreamLogWriter w(std:: | ||
| - | Logger< | ||
| - | Logger< | ||
| - | |||
| - | log.info() << " | ||
| - | |||
| - | return 0; | ||
| - | } | ||
| - | </ | ||
| - | Build and try to execute. Don't remember how? See [[http:// | ||
| - | |||
| - | |||
| - | ======= Motor Control ======= | ||
| - | When you create your first controller, you will see the strength of EEROS - it's block schemes. | ||
| - | For that, remove the delta' | ||
| - | {{: | ||
| - | |||
| - | ===== Controller ===== | ||
| - | We want implement a P-Controller to control the velocity of the driving side. In the figure below, you can see a block diagram of the control system.\\ | ||
| - | {{: | ||
| - | Important is, that the speed and position are measured on the motor side. If you want to control the speed/ | ||
| - | In the next figure, you see a scheme of the motors used in the delta. | ||
| - | {{: | ||
| - | |||
| - | We have the following components in the control system: | ||
| - | |||
| - | |Board Speedout Block| |Reads the speed of the four motors of the delta. This is a eeros:: | ||
| - | |Board In Block| |This is where you set the values of the voltage for each motor. Its a 4x1 Matrix again.| | ||
| - | |Constant c|[CONSTANT] |This is the specified value of the rotation speed. In a later step you can exchange this fix value with a trajektorien generator.| | ||
| - | |demux |[DEMUX]|In the booster phase, you want to control one of the motors, the one with the number 1. To do so, you split the incoming board speed up with this demux.| | ||
| - | |mux |[MUX]|The inverse of the demux.| | ||
| - | |gear |[GAIN]|You can control the position/ | ||
| - | |inverseGear |[GAIN]|You still have to set the values for the motor.| | ||
| - | |sum1 |[SUM]|Calculates the variance.| | ||
| - | |kv |[GAIN] |Cruise control system with a proportional controller.| | ||
| - | |inertia |[GAIN]|Mass moment of inertia, motor and system.| | ||
| - | |saturation |[SATURATION]|Limit the upper and lower bounds of the Voltage.| | ||
| - | |motormodel|[MOTORMODEL]|Calculates the needed voltage of the motor from given motor speed and torque. | | ||
| - | \\ | ||
| - | The Delta-Roboter is using a DC-Motor from Faulhaber (1524012SR) with the gear 15/8. He has the following physical Parameters: | ||
| - | |nominal voltage | U< | ||
| - | |ferrule resistor| R< | ||
| - | |motor constant | ||
| - | |moment of inertia |J | 0.65 gcm< | ||
| - | |gear Ratio | i | 76 | ||
| - | |||
| - | |||
| - | ===== Structure ===== | ||
| - | Create a project with the following structure or extend one of your existing projects. You need this structure and these classes: | ||
| - | \\ | ||
| - | |||
| - | {{: | ||
| - | |||
| - | Try to specify the CMakeLists on your own or adapt an existing one. If you fail, the code is in the [[start# | ||
| - | |||
| - | ===== Constants ===== | ||
| - | In the file constants.hpp, | ||
| - | < | ||
| - | // values from: | ||
| - | // | ||
| - | // | ||
| - | // | ||
| - | |||
| - | |||
| - | // Controller parameters | ||
| - | constexpr double dt = 0.001; // [s] | ||
| - | constexpr double dOpt = 0.7; | ||
| - | constexpr double omega0 = 357.0; //[rad/s]; | ||
| - | constexpr double kvValue = 2.0*omega0*dOpt; | ||
| - | |||
| - | // Electrical and mechanical parameters | ||
| - | constexpr double i1524 = 387283.0/ | ||
| - | constexpr double kM1524 = 11.4e-3; // [NM/A]; | ||
| - | constexpr double RA1524 = 19.8; // [Ohm] | ||
| - | constexpr double stallTorqueMotor1524 = 6.76e-3;// [NM] | ||
| - | constexpr double stallTorqueGear1524 = 100e-3;// [NM] | ||
| - | constexpr double maxStallTorque1524 = stallTorqueMotor1524< | ||
| - | constexpr double rotorInertia1524 = 0.65e-7;// [NM] | ||
| - | constexpr double inertiaValue1524 = rotorInertia1524*i1524*i1524; | ||
| - | constexpr double motorModelValue1524 = rotorInertia1524*i1524*i1524; | ||
| - | </ | ||
| - | |||
| - | ===== MotorModel ===== | ||
| - | There is no EEROS block for a MotorModel, so you have to create it on your own. | ||
| - | The function of this block is to calculate the voltage when torque and actual speed are given. The calculation is based on [[http:// | ||
| - | |||
| - | The MotorModel.hpp: | ||
| - | < | ||
| - | #include < | ||
| - | |||
| - | class MotorModel : public eeros:: | ||
| - | public: | ||
| - | MotorModel(const double kM, const double RA); | ||
| - | |||
| - | virtual eeros:: | ||
| - | virtual eeros:: | ||
| - | virtual eeros:: | ||
| - | |||
| - | virtual void run(); | ||
| - | |||
| - | protected: | ||
| - | eeros:: | ||
| - | eeros:: | ||
| - | eeros:: | ||
| - | |||
| - | double kM, RA; | ||
| - | }; | ||
| - | </ | ||
| - | As you can see, you extend the block class here.\\ | ||
| - | |||
| - | And the MotorModel.cpp: | ||
| - | |||
| - | < | ||
| - | #include " | ||
| - | |||
| - | MotorModel:: | ||
| - | |||
| - | Input< | ||
| - | return speed; | ||
| - | } | ||
| - | |||
| - | Input< | ||
| - | return torque; | ||
| - | } | ||
| - | |||
| - | Output< | ||
| - | return voltage; | ||
| - | } | ||
| - | |||
| - | void MotorModel:: | ||
| - | double u, M, w; | ||
| - | M = torque.getSignal().getValue(); | ||
| - | w = speed.getSignal().getValue(); | ||
| - | u = RA * M / kM + w * kM; | ||
| - | voltage.getSignal().setValue(u); | ||
| - | voltage.getSignal().setTimestamp(torque.getSignal().getTimestamp()); | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | ===== SimpleControlSystem ===== | ||
| - | |||
| - | In SimpleControlSystem.hpp you define the instances, methods and the constructor. | ||
| - | The public constructor gets the argument double ts, and there are three public void methods: start(), stop() and initBoard(). | ||
| - | It has these public instances: | ||
| - | < | ||
| - | //Sum with 2 inputs, typename double | ||
| - | eeros:: | ||
| - | eeros:: | ||
| - | eeros:: | ||
| - | eeros:: | ||
| - | eeros:: | ||
| - | eeros:: | ||
| - | MotorModel motormodel; | ||
| - | // typename double | ||
| - | eeros:: | ||
| - | //define 4 outputs (double) and the inpout is a 4x1 Matrix (double) | ||
| - | eeros:: | ||
| - | //define 4 inputs (double) and the output is a 4x1 Matrix (double) | ||
| - | eeros:: | ||
| - | // typename double | ||
| - | eeros:: | ||
| - | // Blocks | ||
| - | eeduro:: | ||
| - | </ | ||
| - | Additionally, | ||
| - | < | ||
| - | eros:: | ||
| - | </ | ||
| - | Can this code fragment be optimized? Did you hear about the namespace declarations? | ||
| - | \\ | ||
| - | |||
| - | In SimpleControlSystem.cpp you exactly specify the blocks from your controller scheme. | ||
| - | Step 1 is to initialize all your blocks | ||
| - | < | ||
| - | ... | ||
| - | //init the blocks | ||
| - | gear(i1524), | ||
| - | saturation(upper-, | ||
| - | do the same with inverseGear, | ||
| - | ... | ||
| - | </ | ||
| - | Step 2 is to define the block properties: | ||
| - | < | ||
| - | ... | ||
| - | // Define blocks properties | ||
| - | sum1.negateInput(1); | ||
| - | c.setValue(0.5); | ||
| - | ... | ||
| - | </ | ||
| - | Step 3 is to define the block connections: | ||
| - | < | ||
| - | ... | ||
| - | demux.getIn().connect(board.getSpeedOut()); | ||
| - | gear.getIn().connect(demux.getOut(0)); | ||
| - | sum1.getIn(1).connect(gear.getOut()); | ||
| - | sum1.getIn(0).connect(c.getOut()); | ||
| - | kv.getIn().connect(sum1.getOut()); | ||
| - | continue here with inertia --> inverseGear --> saturation --> motorModel (2 inputs/1 output) --> mux and finally | ||
| - | board.getIn().connect(mux.getOut()); | ||
| - | ... | ||
| - | </ | ||
| - | |||
| - | Step 4 is to add the blocks to the run method. You do that by adding the blocks to the timeDomain. The order is really important, you can't get values from a block that is not calculated. | ||
| - | < | ||
| - | ... | ||
| - | // Add blocks to run method | ||
| - | timedomain.addBlock(& | ||
| - | timedomain.addBlock(& | ||
| - | ... more here .. | ||
| - | timedomain.addBlock(& | ||
| - | timedomain.addBlock(& | ||
| - | ... | ||
| - | </ | ||
| - | As a last step you have to implement the three methods start() stop() and initBoard(). Cheat here and look how its done in eeduro-project/ | ||
| - | |||
| - | The source code of the SimpleControlSystem.hpp and SimpleControlSystem.cpp are in the [[start# | ||
| - | |||
| - | |||
| - | ===== main.cpp ===== | ||
| - | |||
| - | First of all, you have to make sure, that the Linux command (Ctrl) + (c) can stop your program. To do so, create a boolean " | ||
| - | |||
| - | The second step in the main method is to specify and start the loggers. The easiest way is to cheat and copy it from the delta.cpp file in the eeduro-project/ | ||
| - | |||
| - | Step three is to create an instance of SimpleControlSystem and initialize it. | ||
| - | delta.cpp uses the ControlSystem. Instead of that, main.cpp should use the SimpleControlSystem created before. Call it controlSys. | ||
| - | Initialize the hardware: | ||
| - | < | ||
| - | // | ||
| - | controlSys.initBoard(); | ||
| - | controlSys.start(); | ||
| - | |||
| - | controlSys.board.setReset(false); | ||
| - | controlSys.board.setEnable(true); | ||
| - | </ | ||
| - | Then your program should run as long as you don't press (Ctrl) + (c). | ||
| - | Do this with a while loop | ||
| - | < | ||
| - | while (running) { | ||
| - | //debug log here | ||
| - | sleep(1); | ||
| - | } | ||
| - | </ | ||
| - | The debug output calls are in the [[start# | ||
| - | |||
| - | At the end of your main, you need to close the board. | ||
| - | < | ||
| - | // close hardware | ||
| - | controlSys.board.setReset(true); | ||
| - | controlSys.board.setEnable(false); | ||
| - | |||
| - | controlSys.board.run(); | ||
| - | controlSys.board.close(); | ||
| - | </ | ||
| - | The source code of the main.cpp isin the [[start# | ||
| - | |||
| - | That's it! Now you have realized your own motor controller. | ||
| - | |||
| - | ====== Appendix ====== | ||
| - | ===== Code Appendix ===== | ||
| - | ==== button_led.cpp ==== | ||
| - | < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | |||
| - | int main(int argc, char *argv[]) | ||
| - | { | ||
| - | eeduro:: | ||
| - | |||
| - | if (!board.open("/ | ||
| - | std::cerr << " | ||
| - | return 1; | ||
| - | } | ||
| - | |||
| - | bool button[3] = { }; | ||
| - | while (true) { | ||
| - | board.run(); | ||
| - | for (int i = 0; i < 3; i++) { | ||
| - | if (button[i] != board.button[i]) { | ||
| - | if (board.button[i]) { | ||
| - | board.led[i] = 1; | ||
| - | } else { | ||
| - | board.led[i] = 0; | ||
| - | } | ||
| - | button[i] = board.button[i]; | ||
| - | } | ||
| - | } | ||
| - | usleep(30000); | ||
| - | } | ||
| - | board.close(); | ||
| - | return 0; | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | ==== Motor Controll CMakeFiles ==== | ||
| - | CMakeLists.txt(simpleproject) | ||
| - | < | ||
| - | cmake_minimum_required(VERSION 2.8) | ||
| - | project(simplesystem) | ||
| - | |||
| - | include_directories(${ADDITIONAL_INCLUDE_DIRS}) | ||
| - | link_directories(${ADDITIONAL_LINK_DIRS} " | ||
| - | |||
| - | set(CMAKE_CXX_FLAGS " | ||
| - | |||
| - | include_directories(include) | ||
| - | add_subdirectory(src) | ||
| - | </ | ||
| - | |||
| - | CMakeLists.txt(src) | ||
| - | < | ||
| - | add_library(simplesystem-lib | ||
| - | MotorModel.cpp | ||
| - | SimpleControlSystem.cpp | ||
| - | ) | ||
| - | |||
| - | add_executable(simplesystem main.cpp SimpleControlSystem.cpp MotorModel.cpp) | ||
| - | |||
| - | target_link_libraries(simplesystem eeros eeduro simplesystem-lib) | ||
| - | </ | ||
| - | |||
| - | ==== SimpleControlSystem ==== | ||
| - | SimpleControlSystem.hpp | ||
| - | < | ||
| - | #ifndef MYCONTROLSYSTEM_HPP_ | ||
| - | #define MYCONTROLSYSTEM_HPP_ | ||
| - | |||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | |||
| - | #include " | ||
| - | |||
| - | class SimpleControlSystem { | ||
| - | |||
| - | public: | ||
| - | SimpleControlSystem(double ts); | ||
| - | |||
| - | void start(); | ||
| - | void stop(); | ||
| - | |||
| - | void initBoard(); | ||
| - | |||
| - | //Sum with 2 inputs, typename double | ||
| - | | ||
| - | | ||
| - | eeros:: | ||
| - | eeros:: | ||
| - | | ||
| - | eeros:: | ||
| - | MotorModel motormodel; | ||
| - | // typename double | ||
| - | | ||
| - | | ||
| - | eeros:: | ||
| - | //define 4 inputs (double) and the output is a 4x1 Matrix (double) | ||
| - | eeros:: | ||
| - | // typename double | ||
| - | eeros:: | ||
| - | // Blocks | ||
| - | eeduro:: | ||
| - | |||
| - | protected: | ||
| - | |||
| - | private: | ||
| - | eeros:: | ||
| - | }; | ||
| - | |||
| - | #endif // MYCONTROLSYSTEM_HPP_ | ||
| - | </ | ||
| - | |||
| - | |||
| - | SimpleControlSystem.cpp | ||
| - | < | ||
| - | #include " | ||
| - | #include " | ||
| - | |||
| - | using namespace eeros:: | ||
| - | |||
| - | SimpleControlSystem:: | ||
| - | |||
| - | //init the blocks | ||
| - | gear(i1524), | ||
| - | | ||
| - | | ||
| - | | ||
| - | inertia(0.65*0.0000001*76.0*76.0), | ||
| - | motormodel(11.4*0.001, | ||
| - | | ||
| - | | ||
| - | |||
| - | |||
| - | // Define blocks properties | ||
| - | | ||
| - | c.setValue(0.5); | ||
| - | |||
| - | // Define block connections | ||
| - | demux.getIn().connect(board.getSpeedOut()); | ||
| - | | ||
| - | | ||
| - | sum1.getIn(0).connect(c.getOut()); | ||
| - | kv.getIn().connect(sum1.getOut()); | ||
| - | inertia.getIn().connect(kv.getOut()); | ||
| - | | ||
| - | saturation.getIn().connect(inverseGear.getOut()); | ||
| - | motormodel.getSpeedIn().connect(demux.getOut(0)); | ||
| - | motormodel.getTorqueIn().connect(saturation.getOut()); | ||
| - | mux.getIn(0).connect(motormodel.getOut()); | ||
| - | board.getIn().connect(mux.getOut()); | ||
| - | | ||
| - | // Add blocks to run method | ||
| - | timedomain.addBlock(& | ||
| - | timedomain.addBlock(& | ||
| - | timedomain.addBlock(& | ||
| - | timedomain.addBlock(& | ||
| - | timedomain.addBlock(& | ||
| - | | ||
| - | timedomain.addBlock(& | ||
| - | timedomain.addBlock(& | ||
| - | timedomain.addBlock(& | ||
| - | timedomain.addBlock(& | ||
| - | timedomain.addBlock(& | ||
| - | timedomain.addBlock(& | ||
| - | } | ||
| - | |||
| - | void SimpleControlSystem:: | ||
| - | timedomain.start(); | ||
| - | } | ||
| - | |||
| - | void SimpleControlSystem:: | ||
| - | timedomain.stop(); | ||
| - | } | ||
| - | |||
| - | void SimpleControlSystem:: | ||
| - | if(!board.open("/ | ||
| - | throw -1; | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | ==== Debug Calls main.cpp ==== | ||
| - | < | ||
| - | //read out the position of all motors | ||
| - | eeros:: | ||
| - | std::cout << "enc: " << enc(0) << "; " << enc(1) << "; " << enc(2) << "; " << enc(3) << std::endl; | ||
| - | |||
| - | //get the value of the constant | ||
| - | std::cout << "soll : " << controlSys.c.getOut().getSignal().getValue() << std::endl; | ||
| - | |||
| - | //check the speed out from the board | ||
| - | std::cout << " | ||
| - | << | ||
| - | | ||
| - | .getSignal().getValue()[3] << std::endl; | ||
| - | |||
| - | //check the value of out of the demux | ||
| - | std::cout << "demux out: " << controlSys.demux.getOut(0).getSignal().getValue() << "; " << | ||
| - | | ||
| - | << | ||
| - | controlSys.demux.getOut(3).getSignal().getValue() << std::endl; | ||
| - | |||
| - | // checkt the values from gear | ||
| - | std::cout << "gear in : " << controlSys.gear.getIn().getSignal().getValue() << std::endl; | ||
| - | std::cout << "gear out : " << controlSys.gear.getOut().getSignal().getValue() << std::endl; | ||
| - | |||
| - | // check the calculation inside sum1 block | ||
| - | std::cout << "sum in 0 : " << controlSys.sum1.getIn(0).getSignal().getValue() << std::endl; | ||
| - | std::cout << "sum in 1 : " << controlSys.sum1.getIn(1).getSignal().getValue() << std::endl; | ||
| - | std::cout << "sum out : " << controlSys.sum1.getOut().getSignal().getValue() << std::endl; | ||
| - | |||
| - | //check the calculation inside kv block | ||
| - | std::cout << "kv in : " << controlSys.kv.getIn().getSignal().getValue() << std::endl; | ||
| - | std::cout << "kv out: " << controlSys.kv.getOut().getSignal().getValue() << std::endl; | ||
| - | |||
| - | //check the calculation inside gear block | ||
| - | std::cout << " | ||
| - | std::cout << " | ||
| - | |||
| - | //checkt the values from inverseGear | ||
| - | std::cout << " | ||
| - | std::cout << " | ||
| - | |||
| - | //checkt the values from saturation | ||
| - | std::cout << " | ||
| - | std::cout << " | ||
| - | |||
| - | //check the calculation inside motormodel block | ||
| - | std::cout << " | ||
| - | std::cout << " | ||
| - | std::cout << " | ||
| - | </ | ||
| - | |||
| - | ==== main.cpp ==== | ||
| - | < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | |||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | #include " | ||
| - | |||
| - | #include < | ||
| - | |||
| - | #include < | ||
| - | #include < | ||
| - | #include < | ||
| - | |||
| - | using namespace eeros; | ||
| - | using namespace eeros::hal; | ||
| - | using namespace eeros:: | ||
| - | using namespace eeros:: | ||
| - | using namespace eeros:: | ||
| - | |||
| - | // enable to stop the program with ctrl c | ||
| - | volatile bool running = true; | ||
| - | |||
| - | // handler on press on ctrl c that will set running to false | ||
| - | void signalHandler(int signum) { | ||
| - | running = false; | ||
| - | } | ||
| - | |||
| - | |||
| - | int main() { | ||
| - | //set the interrupt handler | ||
| - | signal(SIGINT, | ||
| - | |||
| - | //start the loggers | ||
| - | StreamLogWriter w(std:: | ||
| - | SysLogWriter s(" | ||
| - | w.show(); | ||
| - | s.show(); | ||
| - | |||
| - | Logger< | ||
| - | Logger< | ||
| - | |||
| - | log.trace() << " | ||
| - | |||
| - | // create control system | ||
| - | //TODO lw 0.001 durch dt ersetzten und testen | ||
| - | SimpleControlSystem controlSys(0.001); | ||
| - | |||
| - | // initialize hardware | ||
| - | controlSys.initBoard(); | ||
| - | controlSys.start(); | ||
| - | |||
| - | controlSys.board.setReset(false); | ||
| - | controlSys.board.setEnable(true); | ||
| - | |||
| - | while (running) { | ||
| - | /* //read out the position of all motors | ||
| - | eeros:: | ||
| - | std::cout << "enc: " << enc(0) << "; " << enc(1) << "; " << enc(2) << "; " << enc(3) << std::endl; | ||
| - | |||
| - | //get the value of the constant | ||
| - | | ||
| - | |||
| - | //check the speed out from the board | ||
| - | | ||
| - | |||
| - | //check the value of out of the demux | ||
| - | | ||
| - | |||
| - | // checkt the values from gear | ||
| - | std::cout << "gear in : " << controlSys.gear.getIn().getSignal().getValue() << std::endl; | ||
| - | std::cout << "gear out : " << controlSys.gear.getOut().getSignal().getValue() << std::endl; | ||
| - | |||
| - | // check the calculation inside sum1 block | ||
| - | std::cout << "sum in 0 : " << controlSys.sum1.getIn(0).getSignal().getValue() << std::endl; | ||
| - | std::cout << "sum in 1 : " << controlSys.sum1.getIn(1).getSignal().getValue() << std::endl; | ||
| - | std::cout << "sum out : " << controlSys.sum1.getOut().getSignal().getValue() << std::endl; | ||
| - | |||
| - | //check the calculation inside kv block | ||
| - | std::cout << "kv in : " << controlSys.kv.getIn().getSignal().getValue() << std::endl; | ||
| - | std::cout << "kv out: " << controlSys.kv.getOut().getSignal().getValue() << std::endl; | ||
| - | |||
| - | //check the calculation inside gear block | ||
| - | std::cout << " | ||
| - | std::cout << " | ||
| - | |||
| - | //checkt the values from inverseGear | ||
| - | std::cout << " | ||
| - | std::cout << " | ||
| - | |||
| - | | ||
| - | std::cout << " | ||
| - | std::cout << " | ||
| - | // | ||
| - | //check the calculation inside motormodel block | ||
| - | | ||
| - | | ||
| - | std::cout << " | ||
| - | */ | ||
| - | sleep(1); | ||
| - | } | ||
| - | |||
| - | |||
| - | //close hardware | ||
| - | controlSys.board.setReset(true); | ||
| - | controlSys.board.setEnable(false); | ||
| - | |||
| - | controlSys.board.run(); | ||
| - | controlSys.board.close(); | ||
| - | |||
| - | return 0; | ||
| - | } | ||
| - | </ | ||
delta/build_own_controller/start.1448525121.txt.gz · Last modified: 2015/11/26 09:05 (external edit)