Model Boat Mayhem - Forum

Please login or register.

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

Author Topic: Turret Rotation  (Read 7818 times)

dreadnought72

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 1,865
  • Wood butcher with ten thumbs
  • Location: Airdrie, Scotland
Turret Rotation
« on: January 02, 2017, 01:15:27 AM »

 
As promised, this thread will be the home for my attempt to create a microprocessor-based system for turret control. I'm going to kick off with a pile of text first, not least because I need to define and explain some of the basics, and my reasoning behind it all.

Over the next few weeks I'll dip into the hardware and the tech, and then we'll look at the software as it develops towards a (hopefully) all-singing, all-dancing system. If you have any (on-topic, please!) comments or questions, fire away!

A DEFINITION OF THE SYSTEM

The very basics: I want to develop a system to control the movement of turrets on a capital ship. My desire is to control the turrets on a 1/72nd scale HMS Dreadnought whose hull is still awaiting completion. Bob K re-ignited my interest in this subject with his recent acquisition of a 1/96th scale HMS Agincourt.

The system will simulate the training of turrets from a set 'parked' position,to acquire and follow a chosen bearing to a designated target, independent of any change in the capital ship's heading.The system needs to control fore and aft turrets, along with wing turrets that, in some circumstances, may have had opportunities to fire across the deck:  this will enable me to implement the system on any historical capital ship with any arrangement or number of turrets.To prevent the appearance of robotic operation, individual turrets will be equipped to have variable start times and training speeds.The ability to 'park' turrets after training, and alter the target bearing during operation, must be included.

The system must output information that allows or precludes a turret's ability to fire once 'on target', depending on the physical layout of the vessel it's implemented on.

Fire effects (smoke, noise, flash) will notbe modelled or expected, but as a separate system could be combined with the output to allow this. Similarly, gun elevation (typically 0-20 for WW1 equipment) will not be part of this system, nor any changes in elevation during 'reloading': all that's for the future. This system is for realistic turret motion only.
The system will rely on a microprocessor, a MEMs compass, stepper motors and a typical transmitter. Battery draw will be minimal compared to shaft power, smoke generators, etc. Total cost, excluding RC gear, is to be under 100. User control must not take up unnecessary channels.

Finally, software must be easily editable and re-definable to allow it to work on a variety of capital ships.

A QUICK LOOK AT TIME

Model ships generate correct wakes in water following a formula well-known to modellers: scale time = time / sqrt (scale factor)
For a 1/96th scale model, scale time is just about one-tenth of real time. That is, a ship capable of 20 knots will, if built to 1/96th scale, generate a realistic wake at about 2 knots. One scale minute will pass in six real seconds. Back in the days when models were used in film-making, cameras would be overclocked by the inverse of the scale time to produce (more or less!) realistic motion when slowed down on screen.

As capital ship turrets of the WW1 era could typically train from three to five degrees per second ( to 5/6 rpm) the system should, if following the above, be capable of rotating turrets at around thirty to fifty degrees per second (5 to 8 1/3 rpm). However, motion that is 'too fast' on a model, while 'correct' in terms of  the maths, can look as bad as the 'robotic' element of pure, unadulterated, digital stepper motion that the system is anxious to avoid. As a result a compromise is needed: a top training speed of 4 rpm appears to be suitable, both at 1/72nd and 1/96th scales.

One last comment on time! Microprocessors are just small computers; but even so, they have blisteringly fast clock speeds and can handle enormous amounts of data extremely quickly.
Programs written for them typically use loops to minimise code and increase efficiency.
Human senses are not so fast. To provide an illusion of smooth motion to the eye, especially when using stepper motors with digital jumps between angles, the system is expected to run its main loop a few hundred times a second. Fast enough to trick the viewer, easily slow enough to chew on the maths. We'll see!

A THEORY OF RELATIVITY!


Imagine a boat containing rotatable turrets which are pointing at a bearing in a lake. The bearing can change. The boat might alter course. The turrets can move. There's an obvious need to define a fixedframe of reference which will enable us to convert between these various (and variable) angles quickly and easily.
Mathematically, any frame of reference is as good as any other. Practically, it's a different matter.
At first glance, as we're relying on the output of a compass, it might be thought that the lake, being static, is the best choice. Surely everything is relative to that?
Or perhaps taking the point of view of a turret could work: let's face it (!) there's little more obvious to us than thinking we need to turn left or right to point at a particular target.

Both these systems have some benefits and would work, but after a lot of thought it's become clear to me that the primary frame of reference should be that of the boat: our target bearing should be set relative to the boat at some time-zero (T0), say 'port 30', and should measure heading changes of the vessel to calculate and reflect a new target bearing at any future time, Tn, perhaps by now 'starboard 80'.
As our turrets' training limits and parking positions are intrinsically defined relative to the boat, along with our turrets' current training angles, it's trivial to work out where the ship-relative target bearing lies in relation to individual turrets, and therefore we can easily calculate the direction of rotation and the required rotational angle to acquire that target bearing.
That sentence is possibly the worst I've ever written. If you're interested in this thread, and want to understand what will eventually be happening 'under the bonnet' later on, it's maybe worth re-reading.

In essence, the chosen frame of reference is identical to those men in a spotting-top with binoculars, shouting down voice-tubes. In the maths that will follow, the hull is the thing.Work will take me out of the loop for a few days - I'll be back later in the week. With pictures.
Logged
Enjoying every minute sailing W9465 Mertensia

dreadnought72

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 1,865
  • Wood butcher with ten thumbs
  • Location: Airdrie, Scotland
Re: Turret Rotation
« Reply #1 on: January 02, 2017, 01:17:47 AM »

Ouch - the Mayhem text editor, when used with copy & pasted plain text written elsewhere, really hates me. It was formatted ok when it left!  :embarrassed:
Logged
Enjoying every minute sailing W9465 Mertensia

srcampb

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 56
  • Location: La Center Washington, USA
Re: Turret Rotation
« Reply #2 on: January 02, 2017, 06:43:28 AM »

Watching with great interest!
Logged

Bob K

  • Bob K
  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 3,694
  • Location: Windsor
Re: Turret Rotation
« Reply #3 on: January 02, 2017, 07:41:15 AM »

Very succinctly written Andy, and in the wee hours too.  At this rate I can envisage bread-boarding stepper motors and controls long before I am able to mount turrets in my new project.  IMO the realistic deployment of turret movements has been an aspect of model making that has long been waiting for such an elegant solution.  Just imagine having a period warship on your lake that can replicate this in real time.  A slight change of course, and the gun bearings change to follow the "target".  It will look awesome on the water  :-))
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)

Martin [Admin]

  • Administrator
  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 19,039
  • Location: Peterborough, UK
    • Model Boat Mayhem
Re: Turret Rotation
« Reply #4 on: January 02, 2017, 09:45:48 AM »

Ouch - the Mayhem text editor, when used with copy & pasted plain text written elsewhere, really hates me. It was formatted OK when it left!

Not sure what was going on there, the formatting code was all still in place?!?  :embarrassed:
Logged
"This is my firm opinion, but what do I know?!"    -   Mayhem FaceBook Group!

Colin Bishop

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 10,288
  • Location: SW Surrey, UK
Re: Turret Rotation
« Reply #5 on: January 02, 2017, 09:48:59 AM »

Same thing happened to me Martin when I posted my pseudo code spec.

Good specification Andy. We will be watching you and your fellow Arduainites with interest.

Colin
Logged

dreadnought72

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 1,865
  • Wood butcher with ten thumbs
  • Location: Airdrie, Scotland
Re: Turret Rotation
« Reply #6 on: January 07, 2017, 03:38:11 PM »

The hardware:


MICROPROCESSOR



I'm going to be using an Arduino Mega 2560. Mostly because it's what I've got. It is currently just under 30 from Maplins, while compatible models are around a tenner online.


It comes with 54 digital I/O pins, 16 analogue inputs, and particularly enjoys PWM inputs. All this is good.


For testing, I'm running it off a USB cable from the PC to provide power and to enable me to upload edited software with ease. It has a power socket enabling it the ability to run off 6 to 20V once it's in a boat.


There's about 250KB of flash memory (plenty) and the internal clock runs at about 16MHz (more than enough).


COMPASS


I've got an MPU6050 mounted in a GY-521 breakout board. This was about 4 online, and it's powered off the Arduino.


First off, I should point out that it's not a compass. I tried a compass, and wasn't impressed, though it did tell me the kind of magnetic dip at my latitude. This device is a combined gyroscope and accelerometer each of which measure in three axes, giving us 6 degrees of freedom - enabling it to be used as a fully functional inertial measuring unit. It comes with a DMP (digital motion processor) which chews up the MPU6050 data and spits out information that we can use. And all in a 4*4*0.9mm box. In this instance, all I want to know is rotation about its vertical axis - I'll be ignoring pitch and roll and linear acceleration. I'm grossly under-utilising its abilities, but this would be the obvious go-to for people wishing to model active stabilisation systems, or just download their boat's performance around a course.


STEPPER MOTORS


I'm using six 28BYJ-48 stepper motors with associated ULN2003APG drivers. Under 2 each, online. (Wait a minute, Andy - you said HMS Dreadnought. That's got 5 turrets. Why six motors?) I'm using six motors so that one is dedicated to the tracking of targets - If you like, think of later capital ships with large, armoured rangefinders. They don't move like the turrets, but it'll be good to model their actions. Power for the steppers has to be independent of the Arduino. 5V is plenty.


OTHER BITS?


Breadboard, wire (lots of wire!) and some clever thinking.


Andy
Logged
Enjoying every minute sailing W9465 Mertensia

dreadnought72

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 1,865
  • Wood butcher with ten thumbs
  • Location: Airdrie, Scotland
Re: Turret Rotation
« Reply #7 on: January 07, 2017, 04:14:04 PM »

The Other Hardware:

INPUTS

Along with data from the compass, I want to be able to send my target bearing to the ship, and to request the turrets train to that target, or return to park. For test purposes, I'll be using the box on the left. This is a rotary pot and a couple of switches, which will be read in real-time by the Arduino. Ultimately, these can be replicated by one channel and a couple of switches on a standard TX, with output from the receiver going to PWM and digital input pins on the microprocessor.

OUTPUTS

This is my mockup of the deck of Dreadnought - there are six steppers to drive five gun turrets (A, P, Q, X and Y) and the rangefinder (RF). Status for these steppers will be displayed by LEDs. There are five states:

1/ Parked
2/ Going to park
3/ Training to target
4/ On target
5/ Free to fire (you might think 4 naturally leads to 5, but, for example, while turret X may be on target when pointing aft there's a bit of superstructure in the way)

Andy
Logged
Enjoying every minute sailing W9465 Mertensia

Bob K

  • Bob K
  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 3,694
  • Location: Windsor
Re: Turret Rotation
« Reply #8 on: January 07, 2017, 06:58:02 PM »

Great progress so far Andy.  Interesting.  Will those little steppers be up to driving a turret?
Looks like several battery voltages required? 
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)

g6swj

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 313
  • Short Wave Jammer! -.-
  • Location: Northamptonshire, UK
Re: Turret Rotation
« Reply #9 on: January 07, 2017, 07:50:39 PM »

Following with interest...

Andy are you mounting/rotating your "compass" sensor on one of the the steppers?

Regards
Jonathan
Logged

dreadnought72

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 1,865
  • Wood butcher with ten thumbs
  • Location: Airdrie, Scotland
Re: Turret Rotation
« Reply #10 on: January 08, 2017, 04:15:40 AM »

Hi!

Bob, there needs to be a dedicated power supply for the steppers: you can't run them directly off the Arduino, else bad things happen. The Arduino's wide voltage range means it could be run off 6 or 12V, such as the one powering the model. I suspect a small separate regulator for the steppers from the same supply would be the way to go, to keep things simple.

Jonathan, the compass will be firmly fixed to the hull. The physical 'direction' of the unit isn't important, as long as it's mounted level with the Z axis vertical. In use, it's the change of rotation around this axis that's the thing.

Andy

Logged
Enjoying every minute sailing W9465 Mertensia

g6swj

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 313
  • Short Wave Jammer! -.-
  • Location: Northamptonshire, UK
Re: Turret Rotation
« Reply #11 on: January 08, 2017, 06:42:51 AM »

Re power supply - 5v could easily be supplied from the USB stick chargers people use for recharging their phones on the go - small and high capacity devices.


You can get 12v versions of the 28byj steppers ...


Andy - I will be interested to see how you get on with the MPU6050 - I chucked mine in the bin!


Regards
Jonathan
Logged

dreadnought72

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 1,865
  • Wood butcher with ten thumbs
  • Location: Airdrie, Scotland
Re: Turret Rotation
« Reply #12 on: January 10, 2017, 01:31:06 PM »

You can get 12v versions of the 28byj steppers ...


Checking the spec for the steppers I've got, they've got 5V stamped on them, while the driver board says 5-12V. These beasties get warm on 6V, I don't think I'd want to run them much higher than that.


Meanwhile ... an update!


The good news:


My inputs are talking to the code no problem. The compass is chatting away. The LCD display I thought I'd fried months ago is actually all right. And I have precise stepper control in any direction and speed I fancy which I can only describe as phenomenal.  :-))


The not so good news:


To run six steppers simultaneously, I'm having to write a driver to do it. I became increasingly aware that the libraries available for an Arduino to control stepper motion are not quite suitable for this application. Great for one stepper, great for multiple steppers doing nothing else, but as I need to monitor inputs and process the compass in real time, I think I need to go for the bespoke approach. That's not a big hassle, really - the code so far is well under 10k, nowhere near the Arduino Mega's limit. There ARE boards dedicated to running multiple steppers which "ease the pain" by only needing a 'direction' and 'step' signal, but I'm going to continue down this route for the moment.


Back to tinkering!


Andy
Logged
Enjoying every minute sailing W9465 Mertensia

g6swj

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 313
  • Short Wave Jammer! -.-
  • Location: Northamptonshire, UK
Re: Turret Rotation
« Reply #13 on: January 10, 2017, 02:07:57 PM »

Andy,

Both 5vdc and 12vdc are readily available - the stepper driver board stamped 5-12vdc will drive both.

Regards
Jonathan
Logged

dreadnought72

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 1,865
  • Wood butcher with ten thumbs
  • Location: Airdrie, Scotland
Re: Turret Rotation
« Reply #14 on: January 10, 2017, 02:50:56 PM »

Probably worth going for the 12V option, then, for those out to buy cheap steppers - that is, if there's really a difference under the can.  ;)


Andy
Logged
Enjoying every minute sailing W9465 Mertensia

g6swj

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 313
  • Short Wave Jammer! -.-
  • Location: Northamptonshire, UK
Re: Turret Rotation
« Reply #15 on: January 10, 2017, 03:54:25 PM »

Andy,
Probably worth going for the 12V option, then, for those out to buy cheap steppers - that is, if there's really a difference under the can.  ;)

Andy

You cynic :) - you've got me wondering now...
maybe the extra lug on the 12vdc version case is an additional cooling fin for the standard 5vdc innards.

Logged

Bob K

  • Bob K
  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 3,694
  • Location: Windsor
Re: Turret Rotation
« Reply #16 on: January 10, 2017, 04:06:58 PM »

I will not be buying any kit at this early stage of development, but would appreciate a complete parts list (with links) when this reaches a more advanced stage.  I would love a breadboard to watch seven slowly revolving turrets go through their paces.  Patience  {-) {-) {-)
I've not even laid the keel yet  :embarrassed:
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,865
  • Wood butcher with ten thumbs
  • Location: Airdrie, Scotland
Re: Turret Rotation
« Reply #17 on: January 18, 2017, 11:14:24 PM »

Here's a look at the general flow of the program.

I can 'subroutine' some chunks, but it seems pretty solid here.

Andy

Logged
Enjoying every minute sailing W9465 Mertensia

andrewh

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 3,064
  • Location: Melbourne, Australia
Re: Turret Rotation
« Reply #18 on: January 19, 2017, 12:16:26 AM »

Hi, Andy and followers (and Racundra)


I am following this like a hawk - I have Arduino and a slew of steppers, and just need the time to get it all together


So, thanks for the relevant nudge.  I even have the impression that I understand a lot of your wisdom


andrew
Logged

dreadnought72

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 1,865
  • Wood butcher with ten thumbs
  • Location: Airdrie, Scotland
Re: Turret Rotation
« Reply #19 on: January 19, 2017, 12:37:24 AM »

Andrew - a good impression to have!  :-)


Things get ugly when reading the compass, and determining where a turret is in its 'safe to train' zone but there's nothing, so far, which is insurmountable. I think.


Got to get some cable, pin connectors and soldering done, come payday - I should be experimenting this weekend.  :-))


Videos to follow. Hopefully!


Andy
Logged
Enjoying every minute sailing W9465 Mertensia

g6swj

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 313
  • Short Wave Jammer! -.-
  • Location: Northamptonshire, UK
Re: Turret Rotation
« Reply #20 on: January 19, 2017, 09:30:06 AM »

Andy,

Great flow chart - haven't seen this type of thing since the 80's - this is more complex than you first think.

Looking forward to next update.

Regards
Jonathan
Logged

dreadnought72

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 1,865
  • Wood butcher with ten thumbs
  • Location: Airdrie, Scotland
Re: Turret Rotation
« Reply #21 on: January 19, 2017, 09:59:07 AM »

You'll no doubt note, Jonathan, that the coding will be less complex than the chart: huge swathes of it can be handled by stand-alone functions, called multiple times. (Seven turrets or five? Doesn't matter!) The benefit of the flowchart at this stage is that:
  • I've got my head around what I want to see happen.
  • It defines the variables I need to handle.
  • It's transferable to any other programming languages.
...and that, I think, is part of my goal with this project: to help demystify microprocessors, accept them as a useful (and affordable) tool, and use them for whatever we want them to do.


I'll publish some code next.


Andy
Logged
Enjoying every minute sailing W9465 Mertensia

C-3PO

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 819
  • I thought that hairy beast would be the end of me
  • Location: Outer Rim world of Tatooine
Re: Turret Rotation
« Reply #22 on: January 19, 2017, 10:32:36 AM »

Andy,

Wow what a flow chart - makes me feel a little inadequate! My programming is a little undisciplined and always happens with fingers at the keyboard rather than pen and pencil first which in the long term no doubt takes longer but adds to the frustration fun

It will be very interesting to compare our solutions at some stage - I guess we will both be interested in each other's logic/ approach and I am always up for condensing multiple lines of clumsy code into what others sometimes make a single line :)

PS When I locate the SD card for my video camera which has gone AWOL I will post some video also...

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

Bob K

  • Bob K
  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 3,694
  • Location: Windsor
Re: Turret Rotation
« Reply #23 on: January 19, 2017, 10:53:25 AM »

Nicely written flow chart Andy.  Even I can follow (mostly) the logic. 
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)

Colin Bishop

  • Full Mayhemer
  • *****
  • Offline Offline
  • Posts: 10,288
  • Location: SW Surrey, UK
Re: Turret Rotation
« Reply #24 on: January 19, 2017, 04:48:33 PM »

Paul Freshney, MB Editor, has a correspondent with a model of USS Missouri which uses a 'Matchbox Hub' to keep his turrets pointing in the right directions. Apparently this is a device developed for model aircraft to stop their flaps getting into a flap and has been adapted for turret control. Not cheap at $69.99 but apparently has 4 outputs per unit, not clear if they can be doubled up though. Some information here:

http://www.horizonhobby.com/product/radios/radio-accessories/miscellaneous-15069--1/matchbox-servo-matching-power-system-jrpa900

Might be worth checking out although I suspect the Arduino solution could be rather cheaper - maybe?

Colin
Logged
Pages: [1] 2   Go Up