User Tools

Site Tools


marvin:ecp3

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
marvin:ecp3 [2009/01/28 23:16] devamarvin:ecp3 [2009/01/29 11:01] (current) rieper
Line 15: Line 15:
   * Create a Motor Control class that can append extra power to the motors individually to control how the robot is behaving.   * Create a Motor Control class that can append extra power to the motors individually to control how the robot is behaving.
  
-=====The Motor in Theory===== +=====Theory===== 
-=== DC Motor Drives ===+====DC Motor Drives====
 {{ :marvin:motor.png |The NXT DC Motor}} {{ :marvin:motor.png |The NXT DC Motor}}
-The Lego Mindstorm kit comes with a set of DC Motors and therefore we shall give a short introduction to the DC motor and the DC motor controller. This will hopefully add nicely to the presentation of the H-bridge and DC servo motors given in the lesson given in week 4 of the course. Let us begin with the DC motor.((http://hyperphysics.phy-astr.gsu.edu/hbase/hframe.html))\\+The Lego Mindstorm kit comes with a set of DC Motors and therefore we shall give a short introduction to the DC motor and the DC motor controller. This will hopefully add nicely to the presentation of the H-bridge and DC servo motors(([[http://csel.cs.colorado.edu/~bauerk/legorobots/motors.html#SECTION001210000000000000000|motors]])) given in week 4 of the course. Let us begin with the DC motor.(([[http://hyperphysics.phy-astr.gsu.edu/hbase/hframe.html|Hyper Physics]]))\\
    
 {{ :marvin:dcmotor.png?300 |NXT DC Motor Diagram}} {{ :marvin:dcmotor.png?300 |NXT DC Motor Diagram}}
Line 26: Line 26:
 {{ :marvin:4quadrant.png?300 |4 Quadrant Motor Control}} {{ :marvin:4quadrant.png?300 |4 Quadrant Motor Control}}
  
-=== Power Electronic Converter ===+====Power Electronic Converter====
 We see that the four quadrants refers to the four combinations of voltage and current directions. As mentioned the motor is actually transferring energy back to the supply when breaking and this requires special attention when designing a motor controller. In order to control the DC motor a Power Electric Converter (PEC) that satisfies the following conditions is needed. ((Power Electronics, Mohan, Undeland and Robbins, Wiley, ISBN 0-471-22693-9)) We see that the four quadrants refers to the four combinations of voltage and current directions. As mentioned the motor is actually transferring energy back to the supply when breaking and this requires special attention when designing a motor controller. In order to control the DC motor a Power Electric Converter (PEC) that satisfies the following conditions is needed. ((Power Electronics, Mohan, Undeland and Robbins, Wiley, ISBN 0-471-22693-9))
   * The converter must allow both output voltage and current to reverse in order to yield a four-quadrant operation.    * The converter must allow both output voltage and current to reverse in order to yield a four-quadrant operation. 
Line 43: Line 43:
 Fortunately the motor control is linear, which is a requirement in our control loop as it is a linear controller. However, the average voltage output does not vary linear with the control input voltage during the blanking time, which occurs when the motor direction changes. In our case this happens all the time to keep the robot in state of equilibrium and we may therefore expect some non linear behaviour from the motors.  Fortunately the motor control is linear, which is a requirement in our control loop as it is a linear controller. However, the average voltage output does not vary linear with the control input voltage during the blanking time, which occurs when the motor direction changes. In our case this happens all the time to keep the robot in state of equilibrium and we may therefore expect some non linear behaviour from the motors. 
  
-=== Motor Encoder/Tacho Counter === +====Motor Encoder/Tacho Counter==== 
-When designing the motors, wheels and drive train, it will almost always be important to have some sort of encoder feedback. In the LeJOS framework there are methods to get readings from the tacho counters and these sensor readings have proven to be very useful when designing a balancing robot cf. the research literature in the [[http://wiki.aasimon.org/doku.php?id=marvin:ecp0|introduction]]. In order to illustrate the concept of an encoder we use this simple set-up, which is explained in the excellent SRS Encoder article by David Anderson((http://www.seattlerobotics.org/encoder/200109/dpa.html)). Imagine a DC motor without an encoder which is illustrated in the top of the figure. If we mount a circular image with a pattern determining our resolution, we can use a simple IR transceiver to get readings back to our micro controller or signal processing unit. In the LEGO Mindstorm kit(([[http://mindstorms.lego.com/overview/]])) each motor has a built-in Rotation Sensor. This allows us to control the robot’s movements quite accurate. The Rotation Sensor measures motor rotations in degrees or full rotations [accuracy of +/- one degree]. One rotation is equal to 360 degrees, so if we set a motor to turn 180 degrees, its output shaft will make half a turn. This allows us to evaluate both the body angle and angle velocity of the balancing robot by means of simple differentiation, which is explained in one of the following sections. +When designing the motors, wheels and drive train, it will almost always be important to have some sort of encoder feedback. In the LeJOS framework there are methods to get readings from the tacho counters and these sensor readings have proven to be very useful when designing a balancing robot cf. the research literature in the [[http://wiki.aasimon.org/doku.php?id=marvin:ecp0|introduction]]. In order to illustrate the concept of an encoder we use this simple set-up, which is explained in the excellent SRS Encoder article by David Anderson(([[http://www.seattlerobotics.org/encoder/200109/dpa.html|Home-Brew Shaft Encoders]])). Imagine a DC motor without an encoder which is illustrated in the top of the figure. If we mount a circular image with a pattern determining our resolution, we can use a simple IR transceiver to get readings back to our micro controller or signal processing unit. In the LEGO Mindstorm Kit(([[http://mindstorms.lego.com/overview/|LEGO Mindstorms]])) each motor has a built-in Rotation Sensor. This allows us to control the robot’s movements quite accurate. The Rotation Sensor measures motor rotations in degrees or full rotations [accuracy of +/- one degree]. One rotation is equal to 360 degrees, so if we set a motor to turn 180 degrees, its output shaft will make half a turn. This allows us to evaluate both the body angle and angle velocity of the balancing robot by means of simple differentiation, which is explained in one of the following sections. 
  
 {{ :marvin:ecoder.jpg?300 |Principle of TACHO Encoder}} {{ :marvin:ecoder.jpg?300 |Principle of TACHO Encoder}}
  
-=====Driving the Robot=====+=====Implementation=====
 ====Right/Left Steering==== ====Right/Left Steering====
 Now that the robot is balancing it ought to be simple to make it drive around. We expect the controller to maintain its balance even though we apply the necessary offset to the PWM in order to make it move. At first we added a small offset to one wheel and subtracted from the other, which caused the robot to drive in a circle. The robot actually seemed to be more robust when turning and we were able to reach a high speeds when pivoting "on the spot" Maybe this has to do with the angular momentum that is being build up when turning on the spot - similar to the ice skater doing a pirouette. Also we reduce the slip in the motor by keeping the robot rotating. This can be seen on the following video\\ Now that the robot is balancing it ought to be simple to make it drive around. We expect the controller to maintain its balance even though we apply the necessary offset to the PWM in order to make it move. At first we added a small offset to one wheel and subtracted from the other, which caused the robot to drive in a circle. The robot actually seemed to be more robust when turning and we were able to reach a high speeds when pivoting "on the spot" Maybe this has to do with the angular momentum that is being build up when turning on the spot - similar to the ice skater doing a pirouette. Also we reduce the slip in the motor by keeping the robot rotating. This can be seen on the following video\\
Line 70: Line 70:
 We tried several solutions to the problem, in the following they will be outlined, together with the reasons for why they did not work (apart from the last one which in fact worked):\\ We tried several solutions to the problem, in the following they will be outlined, together with the reasons for why they did not work (apart from the last one which in fact worked):\\
   * The first approach was based on the fact that when the robot was in perfect balance (the angle velocities were below a threshold for some amount of time) we could redefine the angle as zero, thus reset the gyroscope angle. This however would make the robot reset its angle at a position //not// vertical whenever driving forward, for some period of time long enough to exceed the threshold buffer length.   * The first approach was based on the fact that when the robot was in perfect balance (the angle velocities were below a threshold for some amount of time) we could redefine the angle as zero, thus reset the gyroscope angle. This however would make the robot reset its angle at a position //not// vertical whenever driving forward, for some period of time long enough to exceed the threshold buffer length.
-  * Second we used the fact that when the angle offset had reached a certain level, the robot continuously tried to straighten up, resulting in the wheels spinning up to maximum in the opposite direction. Based on this observation, we tried to detect when the wheels were driving above a threshold, and thereafter adjust the offset angle towards the thought actual zero. This did not seem to fix the problem at all, since the time we detected the large offset, was way too late+  * Second we used the fact that when the angle offset had reached a certain level, the robot continuously tried to straighten up, resulting in the wheels spinning up to maximum speed in the opposite direction. Based on this observation, we tried to detect when the wheels were driving above a threshold, and thereafter adjust the offset angle towards the actual zero. This did not seem to fix the problem at all, since the time we used to detect the large offset, was way too long for us to prevent Marvin from falling
-  * Next we tried to calculate the drift size by multiplying the angle with some constant. We tried to adjust this constant for a long time, with a lot of measurements, but all in vein. If the drift size could be calculated as a function of the angle, it was certainly not a linear function+  * Next we tried to calculate the drift size by multiplying the angle with constant. We put a lot of effort into tuning this constant, but all in vein. If the drift size can be calculated as a function of the angle, it is certainly not a linear one
-  * We had read somewhere that there might be a problem with the ADC based on its reference voltage, due to drop in battery level. This lead to an attempt to calculate the drift size based on the current battery level measured against the initial battery level. This however did not seem to be the way to things either, since the battery level dropped faster than the drift size would grow+  * We had read, on an NXT/gyroscope forum, that there might be a problem with the ADC based on its reference voltage, due to drop in battery level. This lead to an attempt to calculate the drift size based on the current battery level measured against the initial battery level. This however did not seem to be the way to things either, since there were no obvious connection between the battery level and the angle drift. 
-  * We later tried to simply add constant number to the calculated angle, and tried to adjust it manually, by modifying it, tweaking it, until we thought it as accurate as possible. This seemed to work to a certain point. The drift grew smaller, but did not seem to disappear. +  * We later tried to simply add constant to the calculated angle after each iteration, and tried to adjust it manually, by modifying it, tweaking it, until we thought it as accurate as we could possibly make it. This seemed to work to a certain point. The drift grew smaller, but never seemed to disappear entirely
-  * We for some time suspected the gyroscope reading in itself of being too inaccurate, which lead to a fix, where we made a number of readouts, averaging them out and using this as the actual reading instead. This seemed to work while the robot was in balance, but had negative effect when it was tilting fast, which made the gyroscope reading smaller than the actual value due to the averaging out, so this was obviously not a satisfying solution either. +  * For some time we suspected the gyroscope reading in itself of being too inaccurate, which lead to a fix, where we replaced every reading with the average of a number of readouts, each with a 3ms interval. This seemed to work while the robot was in balance, but had negative effect when it was tilting fast, since this very same method would dampen the large values of the gyroscope, so this was obviously not a satisfying solution either. 
-  * The last attempt was to simply make a running weighted average of all the gyroscope readings, based on the assumption, that the robot is tilting equally forward and backwards. This seemed to work, so that was the solution we chose.+  * The last attempt was to simply make a running weighted average of all the gyroscope readings, with an initial value measured by hand. This method was based on the assumption, that the robot would be tilting equally much forward and backwards, which seems plausible. This seemed to work, so that was the solution we chose.
  
-=====MotorControl=====+All of these considerations lead to the programming of the ''MotorControl'' class. 
 +====The MotorControl Class====
 {{ :marvin:motorcontrol.png?450 }} {{ :marvin:motorcontrol.png?450 }}
-The MotorControl class handles the motors. It works as a control interface on top of the actual Motor ports, and ca report angle and angle velocity (using the TACHO counter) of both of them, as well as set the power and direction.\\+The MotorControl class  handles the motors exclusively. It works as a control interface on top of the actual Motor ports, and can report angle and angle velocity (using the TACHO counter) of both of them, as well as set the power and direction.\\
  
-small stabilizing algorithm is located at the top of the ''setPower(...)'' method. It makes sure that the gears of the motors are always tightened, to minimize the slack on direction change.\\ +The small stabilizing algorithm is located at the top of the ''setPower(...)'' method. Recall that it makes sure that the gears of the motors are always tightened, to minimize the slack on direction change.\\ 
-This is done by adding a small amount of power controlled by a sin function, which makes the robot wriggle a tiny bit when standing absolutely still (this is actually noticeable if whatched carefully).+The small amount of power added by the sine function, makes the robot wriggle a little when standing absolutely still, which is actually noticeable when observed carefully.
  
 The motor angle and angle velocity methods simply uses the average of the values from the actual motor ports.\\ The motor angle and angle velocity methods simply uses the average of the values from the actual motor ports.\\
-The code for these things can be seen below:+The code for these methods can be seen below:
 <code java> <code java>
 class MotorControl class MotorControl
Line 134: Line 135:
  
  
-=====Ctrl=====+====Ctrl====
 {{ :marvin:ctrl.png?500 }} {{ :marvin:ctrl.png?500 }}
 The Ctrl class is used to handle the control parameters of Marvin. The Ctrl class is used to handle the control parameters of Marvin.
-It is used for cross thread communication, and simply sets and gets a number of parameters through synchronized methods.+It is used for cross thread communication, and simply sets and reads a number of parameters through synchronized methods.
 The parameters are left and right motor power offsets, and gyroscope tilt angle offset. The parameters are left and right motor power offsets, and gyroscope tilt angle offset.
  
-way to make Marvin drive in a hardcoded path was to set these values directly in the Ctrl class, and use a counter to switch values after a predefined number of iterations (simply increment the counter upon each ''get'' call and switch when the value is high enough).+The way we made Marvin drive in a hard coded path was to set these values directly in the Ctrl class, and use a counter to switch values after a predefined number of iterations (simply increment the counter upon each ''read'' call and switch when the value is high enough).
  
 The code for the ''offsetLeft'' value can be seen below, the code for ''rightOffset'' and ''tiltOffset'' works similar. The code for the ''offsetLeft'' value can be seen below, the code for ''rightOffset'' and ''tiltOffset'' works similar.
marvin/ecp3.1233180999.txt.gz · Last modified: 2009/01/28 23:16 by deva