Model Boat Mayhem

Please login or register.

Login with username, password and session length.
Pages: 1 [2]   Go Down

Author Topic: Turret Rotation  (Read 13371 times)

g6swj

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 313
  • Short Wave Jammer! -.-
  • Location: Northamptonshire, UK
Re: Turret Rotation
« Reply #25 on: January 19, 2017, 05:00:50 pm »

Clever piece of kit - unless using sail servos you still have the 180 degree limitation.

From what I can make out it (MatchBox Servo Matching/Power System) allows 4 servo's all on the same channel and for each of the 4 servos you can configure:
  • direction of rotation (reverse the RX signal)
  • set end points - limit rotation
Clever piece of kit but not what is being proposed for the Andy (dreadnought72) /C-3PO solutions
Regards
Jonathan
Logged

dreadnought72

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 1,892
  • Wood butcher with ten thumbs
  • Location: Airdrie, Scotland
Re: Turret Rotation
« Reply #26 on: January 22, 2017, 08:50:27 pm »

Horrible restyling of post by forum software. Sorry
Logged
Enjoying every minute sailing W9465 Mertensia

Bob K

  • Bob K
  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 3,686
  • Location: Windsor
Re: Turret Rotation
« Reply #27 on: January 22, 2017, 09:00:44 pm »

    [/list]Clever piece of kit - unless using sail servos you still have the 180 degree limitation.

    270 degree servos are commonly available, other values too.  Its just the "standard" ones that only go 90 degrees
    Logged
    HMS Skirmisher (1905), HMS Amazon (1906), HMS K9 (1915), Type 212A (2002), HMS Polyphemus (1881), Descartes (1897), Iggle Piggle boat (CBBC), HMS Royal Marine (1943), HMS Marshall Soult, HMS Agincourt (1912)

    dreadnought72

    • Full Mayhemer
    • *****
    • Offline Offline
    • Posts: 1,892
    • Wood butcher with ten thumbs
    • Location: Airdrie, Scotland
    Re: Turret Rotation
    « Reply #28 on: January 22, 2017, 10:00:34 pm »

    Martin, an hour of editing and tweaking later, I'm told that the 'edit' time for a post has expiredl My post is lost!!  {:-{


    I was trying to publish software, using the code key, and it's all gone. Is there a handy list of 'do not use' particular [] commands anywhere, 'cos I need to use 'em?


    Andy, deeply frustrated.
    Logged
    Enjoying every minute sailing W9465 Mertensia

    dreadnought72

    • Full Mayhemer
    • *****
    • Offline Offline
    • Posts: 1,892
    • Wood butcher with ten thumbs
    • Location: Airdrie, Scotland
    Re: Turret Rotation
    « Reply #29 on: January 22, 2017, 10:48:33 pm »

    Oooo! Maybe a save!  ;)  File saved from the depths of copy-&-paste!!!  O0


    A Dip Into Programming!


    My previous flowchart contained a box asking "is targetBearing within turret training range?". There should be an image of this simple question below.


    Hmmm. Well, that's an easy question for us, eyeballing a solution, but in programming terms it needs to be defined more completely. There's a flowchart below which details precisely how to answer this question, producing the results which are either "not in range" or "in range", for any turret. How cool is that? (Answer, not very: all questions and queries in a flowchart should result in 'answerable', logical questions.)


    Off to the basics. I'm measuring all angles from the bow, clockwise (if you want to think in degrees, that's fine - though the program will gulp up stepper counts instead, still measured from zero).


    What's (vaguely) interesting here is that the second flowchart doesn't care what units are being used, it's only interested in the relationship between numbers, where these numbers are measured from the bow, clockwise.


    The anticlockwise limit to a training arc is defined as a variable. I'm using (the cunningly named) turretMin[ x ] for this, where 'x' is the turret number (for programmers, you'll notice that the turretMin variable is actually an array: "what's an array, Andy?" Ok. Think of a horizontal row of pigeon holes, one box for each turret, where each one is numbered by another variable called 'x'). That means turretMin[ 2 ], for example, will be the leftmost position allowed by the turret numbered 2 in our initial declaration of these variables. (Incidentally, good programming practice dictates that turret 2 will be the third turret, since we can - and should - number arrays from 0 upwards.)


    Similarly, turretMax[ x ] is the clockwise limit. This is ('I see the square brackets!') another array. Finally, targetBearing is the singular angle, measured from the bow, of the target we wish to point at.


    So what's happening in the expanded flowchart?


    Turrets, any turrets, have two mathematical formats. Type one have a training arc which crosses the '0 degrees' boundary. That is, the left limit (turretMin) might be 220 degrees, while the right limit (turretMax) might be 140 degrees. This is the situation for turret A in the Dreadnought, and (maybe different limits, but same result) for turrets A & B in Warspite, for example.


    Type two turrets have training arcs which do not cross the '0 degrees' boundary. Think of turrets P, Q, X & Y in Dreadnought. X & Y in Warspite. P, Q and X in Invincible. Their training arcs are completely outwith the 0 degrees boundary...incidentally, we can include Dreadnought's P turret as a type two, if we set a turretMax of 360 degrees.


    The flowchart, in its first query, differentiates between these two formats.


    Type two is forced to the right, one is to the left.


    On the right side of this flowchart, we first ask "is targetBearing >= turretMin[ x ]?" and then asks "is targetBearing <= turretMax[ x ]?". If (and only if!) the answer to both these questions is 'yes', then the targetBearing lies within the training arc: it's "in range". Simple! It's a question of "Are you bigger than that AND less than that?"


    To the left, the answer's a little more devious. "is targetBearing >= turretMin[ x ]?" will scope any bearing angles "above" the minimum angle to 360 degrees, and then (should this fail) will ask a further question "well then, is targetBearing <= turretMax[ x ]?", to fill in the other options. Our question now is "Are you bigger than that OR less than that?"


    If (and only if!) the answer to either these last two questions is 'yes', then the targetBearing lies within the training arc: we once again get the result "in range".


    The good news - while it's easy to pick our slow wetware through a flowchart, step-by-step, it actually makes it more complicated than the program. Here's how we could write the above for an Arduino, which uses a (close!) dialect of the language known as C.


    targetOpportunity = FALSE;           // we set a targetOpportunity variable = FALSE
    if(turretMax[ x }>turretMin[ x ]){   // this is first query in flowchart
    if(targetBearing>=turretMin[ x ]{   // this is the right-side 'YES' route
      if(targetBearing<=turretMax[ x ]{  //
       targetOpportunity = TRUE;         // if 'YES' AND 'YES', therefore the target is in arc
      }
    }
    } else {                             // a 'NO' to first query in flowchart: we'll go down the left-side     
    if(targetBearing>=turretMin[ x ]{   //
      targetOpportunity = TRUE;          // Above minimum? Good!
    } else {           
      if(targetBearing<=turretMax[ x ]{
       targetOpportunity = TRUE;         // OR below maximum? Just as good.
      }
    }
    }


    The outcome is a TRUE of FALSE flag set for any turret.


    Incidentally, "//" marks the start of any comment, and is disregarded by the microprocessor.


    The above works really well, and extremely quickly.


    But we could even speed it up. (... Can you see how? (Advanced Question Paper! Not obligatory!))


    More soon!


    Andy

    Logged
    Enjoying every minute sailing W9465 Mertensia

    ballastanksian

    • Full Mayhemer
    • *****
    • Offline Offline
    • Posts: 6,447
    • Model Boat Mayhem inspires me!
    • Location: Crewkerne
    Re: Turret Rotation
    « Reply #30 on: January 22, 2017, 11:00:36 pm »

    I have not the first clue Andy but I will be interested to see the answer. The simplicity of what is written as code above belies the amount of work you and C3PO have done on this in your own zones.

    A couple of future projects are very suitable for this type of technology and the cost is not prohibitive either  :-))
    Logged
    Pond weed is your enemy

    Bob K

    • Bob K
    • Full Mayhemer
    • *****
    • Offline Offline
    • Posts: 3,686
    • Location: Windsor
    Re: Turret Rotation
    « Reply #31 on: January 23, 2017, 07:54:50 am »

    Reducing a complex logic problem to a simple sequence of Boolean (yes/no) filters is producing a very elegant set of instructions.  Although I have not used "C" I appreciate how it works, avoiding spurious 'break outs' (IF/THEN/GOTO) which could confuse the logic under certain conditions.

    PS:  I always write my replies in MS Word, then copy / paste into the Reply box. That way if anything goes wrong I still have my saved copy to start again with.
    Logged
    HMS Skirmisher (1905), HMS Amazon (1906), HMS K9 (1915), Type 212A (2002), HMS Polyphemus (1881), Descartes (1897), Iggle Piggle boat (CBBC), HMS Royal Marine (1943), HMS Marshall Soult, HMS Agincourt (1912)

    dreadnought72

    • Full Mayhemer
    • *****
    • Offline Offline
    • Posts: 1,892
    • Wood butcher with ten thumbs
    • Location: Airdrie, Scotland
    Re: Turret Rotation
    « Reply #32 on: January 26, 2017, 09:52:38 pm »

    Finished soldering today - six steppers now attached to thecompass, LCD, LEDs, and my input devices. The next few days? Getting it all to talk to each other.


    This IS going to work: personal status? Quietly confident.


    Testing and video demos to follow  :-))


    Software afterwards.


    Andy, still aiming for the end of January.
    Logged
    Enjoying every minute sailing W9465 Mertensia

    Capricorn

    • Shipmate
    • *
    • Offline Offline
    • Posts: 19
    • Model Boat Mayhem is Great!
    • Location: Minnetonka, Minnesota USA
    Re: Turret Rotation
    « Reply #33 on: September 13, 2017, 01:59:49 am »

    Hi Andy, and all.  It's been quite a while since I've been on this forum.  I recall your project the dreadnaught, very interesting.  I thought you might be interested in my latest turret control, it's pretty basic, but I finally got it running.  Uses the same 5v geared steppers you are using.  An UNO and ULN2003/2803, and an LSM303 compass.  It certainly doesn't have ranging etc or the other fail safes you have.  Once I got the kinks out I was able to keep the steppers all synced.  Cap

    Here's video, hope the link works:
     
    https://www.youtube.com/watch?v=mgtidK7LFhA
    Logged

    Capricorn

    • Shipmate
    • *
    • Offline Offline
    • Posts: 19
    • Model Boat Mayhem is Great!
    • Location: Minnetonka, Minnesota USA
    Re: Turret Rotation
    « Reply #34 on: September 13, 2017, 04:54:08 am »

    I thought I'd mention a couple more things, I looked through your thread some more and Bob K Agincourt, all very interesting.

    You might have a look at the Customstepper.h library, it has one feature that I think really allowed me to get it to work the way I wanted.  It's the stepper.isDone() boolean check.  If you put all your stepper movements in loops that first check that the steppers are done rotating (ie the arduino finished sending each step pulse it needed to complete the last command), the new movement won't begin, so your motors complete their movements before the new movement command.  They don't loose count of where they were, although that can be done other ways, I just found it to work quite well.  Also, I have read people having problems running several steppers with Customstepper.h but it works, some bug in their sketch.

    I also have the primary pointing device (director) run the turrets, the director turns the full 360 or multiples, it runs off degrees 0 deadahead gotten from subtracting the current compass heading from the initial.  The way it's set up, when activated, it trains on dead ahead (but that could be 90, 270, whatever, or could be input).  It can be activated by a single radio channel.

    The LSM303 compass module breakout works really well in my opinion, has the calibration example and the heading example with the library.  It's tilt compensated, ie has magnetometer and triple axis acclerometer, it gives stable heading with random variation of usually 1 deg, up to just under 3, not too bad.

    For development purposes you might try biting off a smaller amount at first, then adding the other features.  All my steppers are stuck down with sculpting wax, and the turrets are stuck to the motor shafts with the same.  Makes retrials after errors much faster.  Of course the turrets will at some point need to be fixed and zeroed.  On my larger model from a while back I had set screws on the shafts with a hole in the turret for hex driver.  If small enough I'd probalby use a piece of tight fitting silicon tubing so if they get out of alignment you simply twist them back.  Once you get one turret to follow the director and not exceed its field it's easy to add more, 7 not a problem.

    Note that the director turrets in the video I  posted has three seperate stepper circuits, the director,  turrets 1 and 2 are wired directly to the same circuit, as are 3 and 4.  So that requires 4x3 digital outputs that's getting close to max for an UNO.  The Mega has plenty, good choice for 7 turrets :-))

    I'd be happy to share how it runs if anyones interested.   Cap
    Logged

    Mr.R.Duino

    • Shipmate
    • *
    • Offline Offline
    • Posts: 8
    • Model Boat Mayhem is Great!
    • Location: Duino Land
    Re: Turret Rotation
    « Reply #35 on: September 14, 2017, 09:00:00 am »

    Hi Capricorn,

    Nice video - looks like you have a pretty neat solution.

    Not sure if you have seen it but checkout this thread - http://www.modelboatmayhem.co.uk/forum/index.php/topic,56800.0.html

    And also https://login.proboards.com/login/6696601/1

    Do you have any plans to add other functionality?

    Logged

    Capricorn

    • Shipmate
    • *
    • Offline Offline
    • Posts: 19
    • Model Boat Mayhem is Great!
    • Location: Minnetonka, Minnesota USA
    Re: Turret Rotation
    « Reply #36 on: September 14, 2017, 09:48:44 pm »

    I did see the t.a.r.g.e.t. thread, I was a member on this site years ago when I was working on a 1:35 scale DD, that has functioning turrets, I conversed with Andy and some others on his dreadnaught project, probably they don't recall.  But Andy was the one that suggested the compass module to me.  I take rather long breaks (years) from working on my model ship, I only just got back into it a couple months ago on RCGroups, and this realy just a mini version of what I had before, with the compass added.  The 1:35 scale DD has guns that elevate also via steppers.

    Once I had it working well I posted the video and I searched around various sites to see what others may have similar.  I saw Andys post here, seems to have stalled a while back, I can understand that, thought I'd add some new life to it.

    I don't plan any additional features at the moment, not until I get a model to put it in.  I was contemplating a 1/200 scale BB plastic kit, probably the Bismarck, but that is a lot of work, not sure I want to commit.  What features did you have in mind, or suggest?  Cap

    PS what year was 1984 written, because I've googled it and I can't get past the cypher question.
    Logged

    AlexC

    • Full Mayhemer
    • *****
    • Offline Offline
    • Posts: 148
    • Location: West Coast Scotland
    Re: Turret Rotation
    « Reply #37 on: September 14, 2017, 11:56:14 pm »


    PS what year was 1984 written, because I've googled it and I can't get past the cypher question.

    A very ill (TB) George Orwell finally completed the manuscript for 1984 in December of 1948 on the Scottish Island of 'Jura' (inner Hebrides) the book was first published on 8th June 1949 in the UK.

    Hope this helps.

    Alex.
    Logged

    Capricorn

    • Shipmate
    • *
    • Offline Offline
    • Posts: 19
    • Model Boat Mayhem is Great!
    • Location: Minnetonka, Minnesota USA
    Re: Turret Rotation
    « Reply #38 on: September 15, 2017, 01:16:36 am »

    Thanks Alex, I misread the question, finally figured it out; "about what year was novel 1984 written?", duh, 1984....
    Logged

    Bob K

    • Bob K
    • Full Mayhemer
    • *****
    • Offline Offline
    • Posts: 3,686
    • Location: Windsor
    Re: Turret Rotation
    « Reply #39 on: September 15, 2017, 10:51:31 am »

    I believe this thread should be merged with . . .
    http://www.modelboatmayhem.co.uk/forum/index.php/topic,56800.0.html

    Progress is being made towards a working system.
    Logged
    HMS Skirmisher (1905), HMS Amazon (1906), HMS K9 (1915), Type 212A (2002), HMS Polyphemus (1881), Descartes (1897), Iggle Piggle boat (CBBC), HMS Royal Marine (1943), HMS Marshall Soult, HMS Agincourt (1912)

    dreadnought72

    • Full Mayhemer
    • *****
    • Offline Offline
    • Posts: 1,892
    • Wood butcher with ten thumbs
    • Location: Airdrie, Scotland
    Re: Turret Rotation
    « Reply #40 on: October 11, 2017, 11:25:19 pm »

    January, I initially said? Well, it's been a busy year.  %%


    But I'm off this week. And it's only Wednesday. :-))


    Status? Everything is wired up. Code is flowing. Things are working. There's been a few setbacks, but I'm getting there.


    Currently I'm writing error correction stuff to chuck out spurious reports from the MPU6050. There's maybe one returned a minute, at fifty calls per second. Not too bad. But none would be better.


    And the imu does drift, at 360° per day, which is kind of cute. (No one is going to track a target for 24 hours!)


    Oh, and there's an issue with the Arduino - the software will keel over if it's run for about two months, non-stop. Though I don't see this as a deal-breaker for general lake use.  ;)


    Meanwhile my cheapo steppers are throwing up their own issues - I suspect I can 'only' achieve 40-minutes-of-arc accuracy with these guys. Warning: there are several flavours of cheapo steppers available. Caveat emptor. Same can, some 12V, most 5V, and many with different gearing options. These fellas do 509 microsteps per revolution. Fine for model purposes, but there are ways (=£) to be far more accurate. At the moment, I'll nail this version before thinking ahead.


    In general: I'm picking my way through the 'turning flowcharts into code' which is just time-consuming more than anything else. Add a chunk, test, add a chunk...


    More later!


    Andy
    Logged
    Enjoying every minute sailing W9465 Mertensia

    C-3PO

    • Full Mayhemer
    • *****
    • Offline Offline
    • Posts: 1,107
    • I thought that hairy beast would be the end of me
    • Location: Outer Rim world of Tatooine
    Re: Turret Rotation
    « Reply #41 on: October 12, 2017, 09:24:22 am »

    Hi Andy,

    Good to see you back attacking the solution.

    What steppers are you using? 28BYJ48? I have them at 2048/4096 steps per revolution - am I missing something?

    Quote
    • Step Angle (8-Step sequence: Internal Motor alone): 5.625° (64 steps per revolution)
    • Step Angle (4-Step sequence: Internal Motor alone): 11.25° (32 steps per revolution)
    • Gear Reduction ratio: 1 / 64 (Not really exact: probably 63.68395.:1 )
    • SO: it takes (64*64 = 4096 steps per output shaft revolution.. In 8-step sequence.
    • SO: it takes (32*64 = 2048 steps per output shaft revolution.. In 4-step sequence.

    Regards
    C-3PO
    Logged
    I think it's the way I have learnt most of my stuff - getting very stuck first...

    dreadnought72

    • Full Mayhemer
    • *****
    • Offline Offline
    • Posts: 1,892
    • Wood butcher with ten thumbs
    • Location: Airdrie, Scotland
    Re: Turret Rotation
    « Reply #42 on: October 12, 2017, 11:01:23 am »

    There seem to be several versions of the gearing under the can. I've been sending four steps (HLLH, HHLL, LHHL and LLHH) per subroutine-call, and get one rev through 509 calls.


    Which threw me for a while: what insanity is this?


    ...and then it struck me. 2^8 calls is pretty much 180°. Given these steppers are made in the hundreds of thousands to control vanes in cars' blower systems, I've obviously got a set of these.


    Andy
    Logged
    Enjoying every minute sailing W9465 Mertensia

    C-3PO

    • Full Mayhemer
    • *****
    • Offline Offline
    • Posts: 1,107
    • I thought that hairy beast would be the end of me
    • Location: Outer Rim world of Tatooine
    Re: Turret Rotation
    « Reply #43 on: October 12, 2017, 12:53:36 pm »

    Andy,

    If they are 28BYJ48's then I am sure you should be at 2048 steps per revolution - your HLLH etc sequence makes sense - could it be the pin sequence 1,3,2,4?

    Maybe worth a try of the second sketch on this link to see if you get one revolution. "Test Sketch: Rotate 1 turn in each direction, repeat."

    https://arduino-info.wikispaces.com/SmallSteppers

    The common steppers have a gear box @ Gear Reduction ratio: 1 / 64 (Not really exact: probably 63.68395.:1 )

    So motor 32 steps per revolution x gearbox 64 you end up with 2048  steps

    The 509 just doesn't seem to make sense

    C-3PO
    Logged
    I think it's the way I have learnt most of my stuff - getting very stuck first...

    C-3PO

    • Full Mayhemer
    • *****
    • Offline Offline
    • Posts: 1,107
    • I thought that hairy beast would be the end of me
    • Location: Outer Rim world of Tatooine
    Re: Turret Rotation
    « Reply #44 on: October 12, 2017, 09:37:02 pm »

    Hi Andy,

    I am certain you have standard steppers  - The answer is eluding me - but check this out:

    63.68395 x 64 = 4075.7728 ( 63.68395 x 32 = 2037.88)

    4075.7728 / 8 = 509.4716 or your 509 steps per revolution. ( 2037.88/4 = 509)

    I think you are full stepping not half stepping

    So I think you should be stepping (HLLH, HLLL, HHLL, LHLL, LHHL , LLHL, LLHH, LLLH)  - red one are additions that will give you 2048 steps per revolution

    C-3PO
    Logged
    I think it's the way I have learnt most of my stuff - getting very stuck first...

    dreadnought72

    • Full Mayhemer
    • *****
    • Offline Offline
    • Posts: 1,892
    • Wood butcher with ten thumbs
    • Location: Airdrie, Scotland
    Re: Turret Rotation
    « Reply #45 on: October 12, 2017, 11:33:11 pm »

    Mmm. I tried half stepping.


    I'm having to add a small delay() between steps in order for the steppers to not choke on the stream of commands - just a couple of milliseconds is required.


    A non-moving stepper in a sequence then needs to equate to a solid delay() equal to that of a moving turret in order to not 'speed up' those that are moving, in total meaning that (for five turrets and a r/f) the sum of delays per full step is around 40ms. At the resultant 25ish full steps a second, turret rotation is about 360° in twenty seconds, which feels about right. Half stepping would double this...and my gut reaction is it feels a bit 'slow'.


    That said, these delays are set as variables, and eminently tweakable once everything's working. We'll see what balance between angular accuracy (and it's sub degree at 509 steps) and speed/'feel' look like at the end of the day.


    Final point - I'm using a user-brewed stepper subroutine, so it's not impossible to adjust this to run in singular 'part' fullsteps (2038ish bits of 360 degrees) with little alteration - better accuracy, a little bit more code.


    Andy
    Logged
    Enjoying every minute sailing W9465 Mertensia

    C-3PO

    • Full Mayhemer
    • *****
    • Offline Offline
    • Posts: 1,107
    • I thought that hairy beast would be the end of me
    • Location: Outer Rim world of Tatooine
    Re: Turret Rotation
    « Reply #46 on: October 13, 2017, 08:45:45 am »

    Hi Andy,

    You are a brave man creating your own stepper driver.

    Found this video online - so well presented https://www.youtube.com/watch?v=B86nqDRskVU

    Check out 17:20 minutes - it clarifies it all.

    I wonder how much time and money this video cost to put together! - it existence does show how widely used the 28BYJ steppers are...

    C-3PO
    Logged
    I think it's the way I have learnt most of my stuff - getting very stuck first...
    Pages: 1 [2]   Go Up
     

    Page created in 0.128 seconds with 23 queries.