Hi all, I was wondering if I could get some advice on this project I'm working on. It's not really realted to UAVs, but is somewhat similar as it's using an Arduino and Simulink with RC hardware.

I'm doing a project at university to create a PID controller using an arduino to detect the angle of a see-saw type beam, and control two motors, one either side of it. It kind of models a Chinook.

For the moment though I want to start of simply, and so for my test rig I am using an analogue thumbstick to control the motors.

The two motors are each joined to their own electronic speed controllers, the same sort used in RC aircraft. These take their power from a LiPo battery, and are controlled using a single wire carrying a PWM signal, joined to the Arduino (Mega 2560). 
So as far as the motors are concerned, all I need to worry about is a PWM for left, and another for right.

The analogue thumbstick I'm using is this one:
http://dx.com/p/repair-parts-replacement-analog-stick-module-for-ps2-controller-black-121340

As it says in the description, this is simply two analogue potentiometers, one for each axis.

My aim is for the up/down on this to control the overall speed going to both motors, such that moving it up (and holding it there) will increment the power, and moving it back to centre will leave it at that constant speed. I.e. not having them powered while its held up, but just having it always at a power that  can be increased or decreased by moving the stick up or down.

The left and right directions will vary the power to the left or right motor, giving each one a percentage of the total power, as determined by the up/down as described above. i.e having it half the total left distance might give the left motor 75% of the total max power level, and the right 25%.

I want to achieve this using the Arduino plugin within simulink. I want to keep it within simulink rather than the arduino IDE as the eventual PID controller is to be done in simulink, and this may be used as an over-ride.

I know that the first blocks I need are analogue in (one for each pot), and the outputs are PWM signals, one for each motor. But I really don't know where to start with what goes in between. I know each of the pot signals will need to be combined somewhere, and I also know that I'll need to split that into left and right somewhere.
I'm pretty sure I'll use a product block to link the signals from the two pots, as in the screenshot. I don't know what to do to the up/down pot signal to make it stay at a certain power level unless the pot is moved to give more though. (Some stuff in between the analogue read and summation I guess) And I don't know how to determine a percentage for left and a percentage for right... 3691088845?profile=originalBut then I really don't know where to start for the rest of it :\.
(The thumbstick is in the post, but when it comes I'll of course test it out to determine the range of signals I get from it, but the rest can be done without this information.)

Note, I have used Arduino briefly before, and have completed tutorials for a analogue pot controlled servo, both using simulink and the Arduino IDE. I understood both. So I guess I'm fine with the input and output from that simple example, but not so sure on the logic, and the use of Simulink and its various blocks.

If anyone has any ideas, or if anyone has done something similar and has some advise, that would be very appreciated.


Thanks in advance,

Edmund.

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Hi Edmund,

    To have the signal increase or decrease as the vertical channel input is held at a certain value, you'll need to use an integrator. To have the horizontal channel affect the output proportion between left and right motors, you can just divide the input signal by its maximum value and then multiple the result by the total power. This can be seen in the following screenshot;

    3701680622?profile=original

    You can adjust the Gain value in the Discrete Time Integrator from 0.2 to another value to influence how quickly the resulting signal increases or decreases with respect to how long you hold the channel. 

    Here is a small table of resulting % values from this model, where thrust is the vertical channel, and proportion is the horizontal channel. You can multiply these percentages by the maximum values of 1023 at the input and 255 at the output to get the Simulink block values;

    [Thrust Proportion] -> [Left Right]

    [100  50]                   [50   50]

    [100  25]                   [75   25]

    [100    0]                  [100    0]

    [50 50]                     [25    25]

    Best,

    Sergio 

This reply was deleted.

Activity