diy solar

diy solar

OpenSCAD Free Computer Aided Design Program

curiouscarbon

Science Penguin
Joined
Jun 29, 2020
Messages
3,014

This free program lets you design your solar rack or battery pack by writing a text file that describes it, and the 3D model is automatically generated from the description text file.

For example, to make a battery cell all you need to do is type cube([200,100,50]);

This will make a rectangular prism of dimensions 200 x 100 x 50 (mm).

Another example, to move the battery cell, use translate([200,0,0]) just before the cube command. This will move it 200 (mm) in the X axis before placing it.

To make two cells each a 100mm cube can do this:

Code:
cube([100,100,100]);
translate([100,0,0])
cube([100,100,100]);

You might find yourself wanting to reuse stuff you wrote, and that’s where module command comes in. By writing
Code:
module name_of_module()
{
    cube([100,100,100]);
}

This lets you type name_of_module(); somewhere and all of the stuff written into the module will be put there together in a repeatable way.

One more tip, make sure to add a semicolon ; to the end of when you declare an object/module.

Like this: cube([1,1,1]; not cube([1,1,1])

Guessing this tool might appeal more to programmers and stuff, but either way hopefully this mini tutorial can allow people to gauge whether it would be a useful addition to their box.

Here’s an example of something I’m designing in OpenSCAD
1626172484201.jpeg

If anyone has questions about how to write OpenSCAD, I can try to help in this thread. I’m learning too!

Cheers, and good luck with your project.
 
Is it all created from text commands? Or, can it be changed in the visual view?

I'm a software developer, but I'm fairly visually oriented. I could do the textual definition, but the visual part would be necessary for me.

I've been using Sketchup for quite a few years. It may not be the best, but it does what I need.
 
1688447323273.png

C-like:
// definitions

InterCellGap = 1.0;
EPS_SUB      = 0.1;

///////////////////////////////////////////////////
// FREY CELL DEFINITION

// Body
// Vent
// Terminal Components
//   Base
//   Pad
//   Pedestal
//   Post

CellBodyWidth  =  130.4;
CellBodyDepth  =  36.22;
CellBodyHeight =  270;

CellTerminalOffset = 74;

CellTerminalBaseWidth  = 30.55;
CellTerminalBaseDepth  = 25.6;
CellTerminalBaseHeight = 1.3;

CellTerminalPadDiameter   = 5.82;
CellTerminalPadHeight     = 0.8;
CellTerminalPadWidthSpace = 21.08;
CellTerminalPadDepthSpace = 16.08;

CellTerminalPedestalDiameter = 16.0;
CellTerminalPedestalHeight   = 1.43;

CellTerminalPostDiameter  = 9.65;
CellTerminalPostHeight    = 15.0;

CellVentPortDiameterA = 13;
CellVentPortDiameterB = 5.2;
CellVentPortHeight    = 1.3;

module CellBody()
{
  color(c = [0.2,0.4,0.95,1])
  {
    cube([CellBodyWidth,CellBodyDepth,CellBodyHeight],center=true);
  }
 
  color(c = [0,0,0,1])
  {
    translate([0,0,CellBodyHeight*0.5+0.05])
    {
      cube([CellBodyWidth,CellBodyDepth,0.05], center=true);
    }
  }

}

module CellTerminalBase()
{
  cube([CellTerminalBaseWidth,CellTerminalBaseDepth,CellTerminalBaseHeight],center=true);
}

module CellTerminalPad()
{
  cylinder(h = CellTerminalPadHeight, d = CellTerminalPadDiameter, $fn=32, center = true);
}

module CellTerminalPads()
{
  for(i=[-1:2:1])
  {
    for(j=[-1:2:1])
    {
      translate([i*CellTerminalPadWidthSpace*0.5,j*CellTerminalPadDepthSpace*0.5,0])
      {
        CellTerminalPad();
      }
    }
  }
}

module CellTerminalPedestal()
{
  cylinder(h = CellTerminalPedestalHeight, d = CellTerminalPedestalDiameter, $fn=64, center = true);
}

module CellTerminalPost()
{
  cylinder(h = CellTerminalPostHeight, d = CellTerminalPostDiameter, $fn=64, center = true);
 
}

module CellTerminalComplete()
{
  translate([0,0,CellTerminalBaseHeight*0.5])
  {
    CellTerminalBase();
  }
  translate([0,0,CellTerminalBaseHeight+CellTerminalPadHeight*0.5])
  {
    CellTerminalPads();
  }
 
  translate([0,0,CellTerminalBaseHeight+CellTerminalPedestalHeight*0.5])
  {
    CellTerminalPedestal();
  }
 
  translate([0,0,CellTerminalBaseHeight+CellTerminalPedestalHeight+CellTerminalPostHeight*0.5])
  {
    CellTerminalPost();
  }
}

module CellTerminals()
{
  for(i=[-1:2:1])
  {
    translate([CellTerminalOffset*0.5*i,0,0])
    {
      CellTerminalComplete();
    }
  }
}

module CellComplete()
{
  translate([0,0,CellBodyHeight*0.5])
  {
    CellBody();
  }
  translate([0,0,CellBodyHeight])
  {
    CellTerminals();
  }
}

module CellEightPack()
{
  CELLS = 8;
  for(i=[-ceil(CELLS/2-0.5):1:floor(CELLS/2-0.5)])
  {
    translate([0,(CellBodyDepth+InterCellGap)*i,0])
    {
      CellComplete();
    }
  }
}

// end frey cell definition
//////////////////////////////////////////////////////////////



//////////////////////////////////////////////////////////////
// JBD BMS DEFINITION

BMSTotalWidth     = 102;
BMSTotalDepth     = 138;
BMSTotalHeight    =  16.5;
BMSPCBHeight      =   1.6;
BMSHeatSinkHeight =   1.9;

BMSHeatSinkIndentOffsetA    = 10;
BMSHeatSinkIndentWidthA     = 25;
BMSHeatSinkIndentDepthA     = 71.0;
BMSHeatSinkIndentWidthB     = 82;
BMSHeatSinkIndentDepthB     = 15.45;

BMSMountPostOuterDiameter   = 4.0;
BMSMountPostInnerDiameter   = 2.45;

BMSMountPostIndentWidthA    = 4.765;
BMSMountPostIndentDepthA    = 5.155;
BMSMountPostIndentDepthB    = (BMSHeatSinkIndentOffsetA + BMSHeatSinkIndentDepthA + BMSMountPostIndentDepthA) - (BMSTotalDepth*0.5);

BMSTerminalPostWidth        = 14.7;
BMSTerminalPostDepth        = 14.7;
BMSTerminalPostHeight       =  8.0;
BMSTerminalPostThickness    =  1.4;
BMSTerminalPostIndentWidth  =  4.10;
BMSTerminalPostIndentDepth  = 38.6;
//BMSTerminalPostSpacingDepth = 34.5;

BMSTerminalPostInsetDepth   = 47.0;
BMSTerminalPostSpacingDepth = 32.4;
BMSTerminalPostHoleDiameter = 4.8;


module BMSCircuitBoard()
{
  color(c=[0.1,0.5,0.1,1])
  {
    cube([BMSTotalWidth,BMSTotalDepth,BMSPCBHeight],center=true);
  }
}

module BMSHeatSinkBase()
{
    cube([BMSTotalWidth,BMSTotalDepth,BMSHeatSinkHeight],center=true);
}

module BMSHeatSinkNegativeSpace()
{
  translate([0,0,0])
  {
    // larger indent pair on sides for BMS terminals
    for(i=[-1:2:1])
    {
      translate([
         (BMSTotalWidth*0.5-BMSHeatSinkIndentWidthA*0.5)*i,
        -(BMSTotalDepth*0.5-BMSHeatSinkIndentDepthA*0.5)+BMSHeatSinkIndentOffsetA,
          0
      ])
      {
        cube([BMSHeatSinkIndentWidthA+EPS_SUB,BMSHeatSinkIndentDepthA,BMSHeatSinkHeight*2],center=true);
      }
    }
  
    // single indent on bottom edge for BMS communication ports
    translate([0,BMSTotalDepth*0.5-BMSHeatSinkIndentDepthB*0.5,0])
    {
      cube([BMSHeatSinkIndentWidthB,BMSHeatSinkIndentDepthB+EPS_SUB,BMSHeatSinkHeight*2],center=true);
    }
  }
}

module BMSHeatSink()
{
  color(c=[0.6,0.6,0.6,1])
  {
    difference()
    {
        BMSHeatSinkBase();
        BMSHeatSinkNegativeSpace();
    }
  }
}

module BMSMountPost()
{
  cylinder(h=BMSTotalHeight, d = BMSMountPostOuterDiameter, center=true);
}

module BMSMountPostLayout()
{
  for(i=[-1:2:1])
  {
    translate([i*(BMSTotalWidth*0.5-BMSMountPostIndentDepthA),-BMSTotalDepth*0.5+BMSMountPostIndentDepthA, 0.5])
    {
      BMSMountPost();
    }
    translate([i*(BMSTotalWidth*0.5-BMSMountPostIndentDepthA),BMSMountPostIndentDepthB, 0.5])
    {
      BMSMountPost();
    }
    translate([i*(BMSTotalWidth*0.5-BMSMountPostIndentDepthA),BMSTotalDepth*0.5-BMSMountPostIndentDepthA, 0.5])
    {
      BMSMountPost();
    }
  }
}

module BMSTerminalPost()
{
//  BMSTerminalPostWidth      = 14.7;
//  BMSTerminalPostDepth      = 14.7;
//  BMSTerminalPostHeight     =  8.0;
//  BMSTerminalPostThickness  = 1.4;
 
  translate([0,0,0])
  {
    difference()
    {
      // primary post structure
      translate([0,0,BMSTerminalPostHeight*0.5])
      {
        cube([BMSTerminalPostWidth,BMSTerminalPostDepth,BMSTerminalPostHeight], center=true);
      }
      // negative space subtracted
      union()
      {
        translate([0,0,BMSTerminalPostHeight*0.5])
        {
          cube([
            BMSTerminalPostWidth+EPS_SUB,
            BMSTerminalPostDepth-BMSTerminalPostThickness,
            BMSTerminalPostHeight-BMSTerminalPostThickness
          ], center=true);
        }
        cylinder(h=40, d = BMSTerminalPostHoleDiameter, center=true, $fn=32);
      }
    }
  }
}

module BMSTerminalLayout()
{
  // width : i
  for(i=[-1:2:1])
  {
    // depth : j
    for(j=[-1:2:1])
    {
      OffsetWidth = BMSTotalWidth - BMSTerminalPostIndentWidth - BMSTerminalPostWidth;
      OffsetDepth = BMSTotalHeight*0.5 - BMSTerminalPostIndentDepth;
    
//      BMSTerminalPostInsetDepth   = 55.0;
//      BMSTerminalPostSpacingDepth = 32.4;
    
//      translate([i*OffsetWidth*0.5,j*0-BMSTotalDepth*0.5+BMSTerminalPostInsetDepth])
      translate([i*OffsetWidth*0.5, -BMSTotalDepth*0.5+BMSTerminalPostInsetDepth + j*BMSTerminalPostSpacingDepth*0.5])
      {
        BMSTerminalPost();
      }
    }
  }
}

module BMSComplete()
{
  BMSCircuitBoard();
  translate([0,0,7.6])
  {
    BMSHeatSink();
  }
  translate([0,0,-6.7])
  {
    BMSHeatSink();
  }
  BMSMountPostLayout();
  BMSTerminalLayout();
 
}

/// end JBD BMS definition
//////////////////////////////////////////////////////////////



CellEightPack();

translate([120,0,CellBodyHeight*1.25])
{
  BMSComplete();
}

To use this script in OpenSCAD, copy the code and paste it into the text editor.

JBD BMS and Frey 100Ah Cells are modeled.

Arranging the parts in CAD can be fun!
 
Back
Top