Hi everyone,
I am currently developing a piece in ooml that is composed by many similar parts, so I decided to make a general part and then use it several times in my piece. I have written the code and compiled it with no errors, but when I execute the resulting program, I get an error:
The program has unexpectedly finished.
HARDWARE exited with code 0
And when I execute it through the terminal, I get this:
Violación de segmento
This is the code of the main piece:
#include <ooml/core.h>
#include <ooml/components.h>
#include <iostream>
#include <fstream>
#include "ear.h"
#include "base.h"
using namespace std;
int main()
{
Base base( 52, 4, 15, 15, 3/2);
base.add_cross( 20, 40);
base.translate(10,10,10);
Ear ear(50, 10, 50, 25/2, 4);
ear.add_drill(3/2);
Component result = base + ear;
IndentWriter writer;
writer << result;
cout << writer << endl << endl;
ofstream file("TEST01.scad");
if (file)
{
file << "//-------------------------------------------------------------------------" << endl;
file << "//-- TEST01.scad" << endl;
file << "//-------------------------------------------------------------------------" << endl;
file << "//--This file has been generated automatically according to your data."<< endl;
file << "//--For more info, visit:
http://iearobotics.com/oomlwiki/"<< endl;
file << "//--------------------------------------------------------------------------" << endl << endl;
file << writer;
file.close();
}
else
{
cerr << "Error, cannot open the file" << endl;
}
return 0;
}
And one of the parts is this (the other is quite similar, but this is simpler):
//-- base.h
#include <ooml/core.h>
#include <ooml/components.h>
#ifndef BASE_H
#define BASE_H
class Base: public AbstractPart
{
public:
//-- Constructor
Base();
Base(double side, double thickness, double drill_x, double drill_y, double drill_r);
//--Add a cross-shaped hole to the base of the module
void add_cross( double small, double large);
protected:
virtual Component build();
private:
/*Main parameters*/
double _side;
double _thickness;
double _drill_x;
double _drill_y;
double _drill_r;
/*For the optional cross hole*/
double _cross_small;
double _cross_large;
};
#endif // BASE_H
And :
// base.cpp
#include <ooml/core.h>
#include <ooml/components.h>
#include "base.h"
Base::Base(): AbstractPart()
{
//--Default values
_side = 52;
_thickness = 4;
_drill_x = 15;
_drill_y = 15;
_drill_r = 3/2;
//-- Optional parameters
_cross_small = 0;
_cross_large = 0;
build();
}
Base::Base(double side, double thickness, double drill_x, double drill_y, double drill_r): AbstractPart()
{
_side = side;
_thickness = thickness;
_drill_x = drill_x;
_drill_y = drill_y;
_drill_r = drill_r;
//-- Optional parameters
_cross_small = 0;
_cross_large = 0;
build();
}
Component Base::build()
{
//-- Create the main part
Component main = Cube::create(_side, _side, _thickness);
//--Create the holes
Component drill01 = Cylinder::create( _drill_r, _thickness+0.1, 20, true);
drill01.translate( _drill_x, _drill_y, 0);
Component drill02 = Cylinder::create( _drill_r, _thickness+0.1, 20, true);
drill02.translate( _drill_x, -_drill_y, 0);
Component drill03 = Cylinder::create( _drill_r, _thickness+0.1, 20, true);
drill03.translate( -_drill_x, _drill_y, 0);
Component drill04 = Cylinder::create( _drill_r, _thickness+0.1, 20, true);
drill04.translate( -_drill_x, -_drill_y, 0);
Component holes = drill01 + drill02 + drill03 + drill04;
//-- Create the cross-shaped hole
if (_cross_small > 0 && _cross_large > 0)
{
Component cross01 = Cube::create(_cross_small, _cross_large, _thickness + 0.1);
Component cross02 = Cube::create(_cross_large, _cross_small, _thickness + 0.1);
holes = holes - cross01 - cross02;
}
//-- Add up all the components
Component piece = main - holes;
return piece;
}
//-- Add a cross-shaped hole to the base
void Base::add_cross( double small, double large)
{
_cross_small = small;
_cross_large = large;
}
The whole project can be found at this repository:
https://github.com/David-Estevez/REPY-2.0
Thanks in advance!!
--
---
David Estévez Fernández