Click here to Skip to main content
15,067,251 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am currently working on an application for a cnc machine that I run and need some help with how to structure the data models. The machine has a Turret represented by the Turret class which has a set number of stations where ToolBlocks can be "mounted" to in either forward or reverse. Each ToolBlock has a set number of BlockPositions that a "Tool" can be mounted to, one per position. In the app I need a list of unmounted ToolBlocks and Tools. Then, when I mount a ToolBlock to a Station I need it to become unavailable in the list of unmounted ToolBlocks. The same with mounting the Tool to the BlockPosition.

The part that is stumping me is when I mount the Tool to the BlockPosition I also need to save an integer that represents what offset number the machine will be using and the BlockPosition to reference the Tool that is mounted. To me it doesn't make sense to have a "Tool" object property in the BlockPosition class when I only need it if it is a mounted ToolBlock.

On the application startup I just need to reload what ToolBlock was on what station and Tool was on what BlockPosition. So the question I have is if anyone has a good way to structure these models.

Here are the very simplified classes I'm working with:
public class ToolBlock
{
    public int ID { get; set; }
    public string Name { get; set; }
    public List<BlockPosition> Positions { get; set; }
}
public class BlockPosition
{ 
    public int ID { get; set; }
    public string Name { get; set; }
    public double Offset { get; set; }
}
public class Station
{
    public int ID { get; set; }
    public ToolBlock ToolBlock { get; set; }
    public BlockMountingPositionEnum BlockPosition { get; set; }
}
public class Turret
{
    public List<Station> Stations { get; set; }
}
public class Tool
{
    public int ID { get; set; }
    public double Offset { get; set; }
    public string Name{ get; set; }
}
public enum BlockMountingPositionEnum
{
    Foward = 0,
    Reverse = 1
}


What I have tried:

So far I have tried to Inherit from ToolBlock and BlockPosition class to make a MountedToolBlock and MountedBlockPosition class like this:
public class MountedToolBlock : ToolBlock
{
    public MountedBlockPositionEnum BlockPosition { get; set; }
}
public class MountedBlockPosition : BlockPosition
{
    public int OffsetNo { get; set; }
    public Tool Tool { get; set; }
}
I Just cant seem to do this in a graceful way that makes sense. I have also tried to implement interfaces instead of concrete classes for the List of BlockPositions. Thought of using Dictionary<> to store the BlockPosition with the OffsetNo and Tool but I am getting nowhere. I am getting stuck on the process of actually mounting ToolBlocks and Tools and structuring that data so I can than save it to xml.

If it helps there will only be up to 4 BlockPositions per ToolBlock so maybe a List is not the best approach.

Hopefully I am making sense, any help would be appreciated.
Posted
Updated 1-Jan-18 23:50pm

1 solution

So far i understand that each Tool should be mounted into ToolBlock, then into Station. The list of stations has common name: Turret.
Seems, you've got 2 set of data: one - unmounted tools (Tool class) and the second - mounted tools which create stations (Station class).
Mounted tools:
Turret
|_Station
  |_ToolBlock

Unmounted tools:
Warehouse
|_Tool


Since a ToolBlock has several properties of Tool, than ToolBlock should inherits from that object.

If you would like to know that Tool has been mounted into ToolBlock, you can add some marker into Tool class. It may be IsMounted property or even better StationID, which can be used to identify Station where the Tool has been mounted. By default, the StationID property of Tool object should be equal to 0 (zero) and any value greater than zero after mounting.


As to me your model is unclear... Every CNC machine have to know the order (sequence) and the localization of each element. I have no idea how your machine will be able to recognize Station. I'll try to expain it on simple diagram (below).
-----------------------------TURRET-----------------------------------------
 _STATION_  _________  _________  _________ 
|  _   _  ||  _   _  ||  _   _  ||  _   _  |
| |_| |_| || |_| |_| || |_| |_| || |_| |_|-----Tools (ToolBlock)
|  _   _  ||  _   _  ||  _   _  ||  _   _  |    |
| |_| |_| || |_| |_| || |_| |_| || |_| |_|------|
| _______ || ________|| ________|| _______ |
------------------------------------------------------------------------

Imagine that Turret object is like a tape (or any other object, such as a piece of wood, a sheet of plastic or a tinware). In simplified model only one station after another may be mounted. But - in real - there might be several stations with set of tools in specifc order and localization.

-----------------------------TURRET-----------------------------------------
 _STATION_  _________  _________  _________ 
|  _   _  ||  _   _  ||  _   _  ||  _   _  |
| |_| |_| || |_| |_| || |_| |_| || |_| |_|-----Tools (ToolBlock)  >--
|  _   _  ||  _   _  ||  _   _  ||  _   _  |    |                    |
| |_| |_| || |_| |_| || |_| |_| || |_| |_|------|                    |
| _______ || _______ || _______ || _______ |                         ˅
 _STATION_  _________  _________  _________               the direction of laying
|  _   _  ||  _   _  ||  _   _  ||  _   _  |                         ˅
| |_| |_| || |_| |_| || |_| |_| || |_| |_| |                         |
|  _   _  ||  _   _  ||  _   _  ||  _   _  |<-----------<------------|
| |_| |_| || |_| |_| || |_| |_| || |_| |_| |
| _______ || _______ || _______ || _______ |
------------------------------------------------------------------------


I'd suggest to get a sheet of paper and a pencil, than draw a model of Turret on it. When you finish, you'll be able to define classes.
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900