VisibleSim icon indicating copy to clipboard operation
VisibleSim copied to clipboard

[BUG?] This motion is allowed?

Open kazogihara opened this issue 3 years ago • 0 comments

Hi! I found module motion that seems to be not allowed. Could you check it?

  • Motion Video https://youtu.be/shIH0Xp4t4s

  • VisibleSim Version VS2022.3.1

  • myMotionTestCode.cpp

#include "myMotionTestCode.hpp"

MyMotionTestCode::MyMotionTestCode(Catoms3DBlock *host) : Catoms3DBlockCode(host), module(host)
{
    // @warning Do not remove block below, as a blockcode with a NULL host might be created
    //  for command line parsing
    if (not host)
        return;
}

void MyMotionTestCode::startup()
{
    console << "start " << module->blockId << "\n";
    if (module->blockId == 2)
    {
        module->setColor(RED);
        Cell3DPosition target_pos = module->position + Cell3DPosition(1, 1, -1);
        module->moveTo(target_pos);
    }else if(module->blockId == 3){
        module->setColor(RED);
        Cell3DPosition target_pos = module->position + Cell3DPosition(0, 1, -1);
        module->moveTo(target_pos);        
    }
}
  • myMotionTestCode.hpp
#ifndef myMotionTestCode_H_
#define myMotionTestCode_H_

#include "robots/catoms3D/catoms3DSimulator.h"
#include "robots/catoms3D/catoms3DWorld.h"
#include "robots/catoms3D/catoms3DBlockCode.h"
#include "robots/catoms3D/catoms3DMotionEngine.h" 
#include "robots/catoms3D/catoms3DRotationEvents.h"

using namespace Catoms3D;

class MyMotionTestCode : public Catoms3DBlockCode {
private:
	Catoms3DBlock *module = nullptr;
public :
	MyMotionTestCode(Catoms3DBlock *host);
	~MyMotionTestCode() {};
  Cell3DPosition targetPos;
/**
  * This function is called on startup of the blockCode, it can be used to perform initial
  *  configuration of the host or this instance of the program.
  * @note this can be thought of as the main function of the module
  */
    void startup() override;

/*****************************************************************************/
/** needed to associate code to module                                      **/
	static BlockCode *buildNewBlockCode(BuildingBlock *host) {
	    return(new MyMotionTestCode((Catoms3DBlock*)host));
	}
/*****************************************************************************/
};

#endif /* myMotionTestCode_H_ */
  • myMotionTest.cpp
#include <iostream>
#include "myMotionTestCode.hpp"

using namespace std;
using namespace Catoms3D;

int main(int argc, char **argv) {
    try {
        createSimulator(argc, argv, MyMotionTestCode::buildNewBlockCode);
        getSimulator()->printInfo();
        BaseSimulator::getWorld()->printInfo();
        deleteSimulator();
    } catch(std::exception const& e) {
        cerr << "Uncaught exception: " << e.what();
    }

    return 0;
}

config.xml

<?xml version="1.0" standalone="no" ?>
<world gridSize="26,26,26" visual="1024,800">
    <camera target="54.5554,56.3875,22.0596" directionSpherical="-2561.64,33.8501,220" angle="45.000000" near="0.100000" far="2000.000000" />
    <spotlight target="0,0,0" directionSpherical="135,80,800" angle="43.152390" />
    <blockList blockSize="10,10,10">
        <block position="5,5,0" color="255,140,0" orientation="0" />
        <block position="5,4,1" color="255,140,0" orientation="0" />
        <block position="7,4,1" color="255,140,0" orientation="0" />
        <block position="8,5,0" color="255,140,0" orientation="0" />
    </blockList>
</world>

kazogihara avatar Aug 30 '22 11:08 kazogihara