Problems creating parts

16 views
Skip to first unread message

David Estévez Fernández

unread,
Mar 24, 2012, 12:37:05 PM3/24/12
to oo...@googlegroups.com
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

Alberto

unread,
Mar 24, 2012, 9:22:57 PM3/24/12
to oo...@googlegroups.com
David, you can give a look to the SimpleWheel part in the ooml trunk.

The constructor, after initializing the variables calls: rebuild(), which is declared and defined in AbstractPart.

Instead you are calling build(), which does not make anything, as it returns a Component which you are not collecting.

Then, on the add_cross function you modify some parameters, but you do not regenerate the part. At the end of the add_cross function you should call rebuild(), in order to "rebuild" the part. In any case, it might be simpler if you add those parameters to the constructor with a default value = 0 if you do not want to set them or with the value you set, but that's up to you.

I hope this can be of help.

If you still have a problem after making these changes it can be helpful if you indicate us in which line of code your program segments. For doing so you can write a cout at each line and you will know.

Best,
Alberto.


2012/3/24 David Estévez Fernández <david.est...@gmail.com>

David Estévez Fernández

unread,
Mar 26, 2012, 5:12:23 AM3/26/12
to oo...@googlegroups.com
Now it works!! Thank you very much!!

That build() instead of rebuild() was the problem. I was using build() since the tutorial said so:

http://iearobotics.com/oomlwiki/doku.php?id=tutorials:toroid
Reply all
Reply to author
Forward
0 new messages