Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
78e8957
added trajectory saving
ladaegorova18 Mar 11, 2022
861d908
Added net connection, trajectory serialization to json and pause/run …
Apr 10, 2022
21156a0
Removed .proto file
Apr 10, 2022
3d6e534
added net connection run/pause/restart from Unity, renamed trajectory…
Apr 15, 2022
710e851
added some comments, fixed tabulations
Apr 15, 2022
ac8c00e
Added sending run/pause/restart signals from TRIK Studio to Unity
Apr 20, 2022
53a413d
added checkBox sendData and comboBox UnityIp to additionalPreferences
Apr 24, 2022
cc7c592
fixed vera errors, added license
May 5, 2022
7a87218
Merged upstream/master
May 5, 2022
21400ba
lupdate
May 5, 2022
65e7037
added QT += network
May 5, 2022
64df440
renamed some variables to mVariables
May 6, 2022
5ef1af1
removed some empty strings
May 6, 2022
8688514
lupdate
May 6, 2022
c738a8f
added passing parameters by link
May 10, 2022
441910c
lupdate
May 10, 2022
8b6149b
added forward declarations
May 10, 2022
40b7ffd
changed lines length
May 11, 2022
169906c
lupdate
May 11, 2022
d0b13f5
renamed ConnectionToVizualizator -> ConnectionToVisualizer
May 11, 2022
5131260
added QScopedPointers, separated saving position and rotation
May 12, 2022
b3c21e3
added comments
May 12, 2022
0d5d1f1
changed lines length
May 11, 2022
c2c4e10
renamed ConnectionToVizualizator -> ConnectionToVisualizer
May 11, 2022
5989474
added QScopedPointers, separated saving position and rotation
May 12, 2022
45e25cf
added comments
May 12, 2022
6437234
rebased upstream/master
May 12, 2022
57566f2
Merge branch 'master' into master
ladaegorova18 May 12, 2022
56f96e2
lupdate
May 12, 2022
33286dd
removed sizeof(8)
May 13, 2022
3d94758
removed qcsopedpointers
May 13, 2022
f8d9ce5
added endState in the end of trajectory
May 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,19 @@ public slots:
/// Emitted when left or right wheel was reconnected to another port.
void wheelOnPortChanged(WheelEnum wheel, const kitBase::robotModel::PortInfo &port);

/// Emitted when robot starts or ends play beep sound
void trajectorySoundStateChanged(QString id, int time);

/// Emitted when robot starts or ends draw
void trajectoryMarkerColorChanged(QString id, QColor color);

/// Emitted when robot position and/or rotation changed
void trajectoryPosOrAngleChanged(QString id, QPointF position, qreal rotation);
void trajectoryOnitemDragged(QString id, QPointF position, qreal rotation);

void trajectorySave();
void onStopPlaying();

private:
QVector2D robotDirectionVector() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "twoDModel/engine/twoDModelDisplayWidget.h"

#include "twoDModel/twoDModelDeclSpec.h"
#include "plugins/robots/common/twoDModel/src/engine/trajectory/connectionToVizualizator.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем этот #include?


class QComboBox;
class QPushButton;
Expand All @@ -47,6 +48,10 @@ class ControllerInterface;

namespace twoDModel {

//namespace trajectory {
//class ConnectionToVizualizator;
//}

namespace model {
class Model;
class RobotModel;
Expand Down Expand Up @@ -108,6 +113,7 @@ class TWO_D_MODEL_EXPORT TwoDModelWidget : public QWidget
QDomDocument generateWorldModelWithBlobsXml() const;
QDomDocument generateWorldModelXml() const;
QDomDocument generateBlobsXml() const;
ConnectionToVizualizator *mConnToVizualizator;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отсутствует инициализация {}, не указано, кто владеет объектом


public slots:
void zoomIn() override;
Expand All @@ -129,6 +135,9 @@ public slots:
/// Emitted when user has stopped intepretation from the 2D model window.
void stopButtonPressed();

/// Emitted when user has stopped intepretation from the remote vizualizator
void restartRequested();

protected:
void changeEvent(QEvent *e) override;
void showEvent(QShowEvent *e) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <qrutils/graphicsUtils/abstractItem.h>

#include "twoDModel/engine/model/robotModel.h"
#include "src/engine/trajectory/trajectorySaver.h"
#include "twoDModel/engine/model/constants.h"
#include "twoDModel/engine/model/worldModel.h"
#include "src/engine/view/scene/twoDModelScene.h"
Expand Down Expand Up @@ -44,6 +45,7 @@ Box2DPhysicsEngine::Box2DPhysicsEngine (const WorldModel &worldModel
, mWorld(new b2World(b2Vec2(0, 0)))
, mPrevPosition(b2Vec2(0, 0))
, mPrevAngle(0)
, mTrajSaver(new TrajectorySaver(nullptr))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Думаю, что тут надо бы не nullptr

{
connect(&worldModel, &model::WorldModel::wallAdded,
this, [this](const QSharedPointer<QGraphicsItem> &i) {itemAdded(i.data());});
Expand All @@ -53,6 +55,10 @@ Box2DPhysicsEngine::Box2DPhysicsEngine (const WorldModel &worldModel
this, [this](const QSharedPointer<QGraphicsItem> &i) {itemAdded(i.data());});
connect(&worldModel, &model::WorldModel::itemRemoved,
this, [this](const QSharedPointer<QGraphicsItem> &i) {itemRemoved(i.data());});

connect(this, &Box2DPhysicsEngine::trajectoryPosOrAngleChanged, mTrajSaver, &TrajectorySaver::saveItemPosOrAngle);
connect(this, &Box2DPhysicsEngine::trajectoryItemDragged, mTrajSaver, &TrajectorySaver::onItemDragged);
connect(this, &Box2DPhysicsEngine::sendNextFrame, mTrajSaver, &TrajectorySaver::sendFrame);
}

Box2DPhysicsEngine::~Box2DPhysicsEngine(){
Expand Down Expand Up @@ -143,8 +149,13 @@ void Box2DPhysicsEngine::addRobot(model::RobotModel * const robot)
auto model = &rItem->robotModel();
mBox2DRobots[model]->reinitSensor(sensor);
});

connect(robot, &model::RobotModel::deserialized, this, &Box2DPhysicsEngine::onMouseReleased);
connect(robot, &RobotModel::trajectorySoundStateChanged, mTrajSaver, &TrajectorySaver::saveBeepState);
connect(robot, &RobotModel::trajectoryMarkerColorChanged, mTrajSaver, &TrajectorySaver::saveMarkerState);
connect(robot, &RobotModel::trajectoryPosOrAngleChanged, mTrajSaver, &TrajectorySaver::saveItemPosOrAngle);
connect(robot, &RobotModel::trajectoryOnitemDragged, mTrajSaver, &TrajectorySaver::onItemDragged);
connect(robot, &RobotModel::trajectorySave, mTrajSaver, &TrajectorySaver::saveToFile);
connect(robot, &RobotModel::onStopPlaying, mTrajSaver, &TrajectorySaver::onStopInterpretation);
});
}

Expand Down Expand Up @@ -353,7 +364,10 @@ void Box2DPhysicsEngine::nextFrame()
item->setPos(scenePos - item->boundingRect().center());
item->setRotation(angleToScene(mBox2DDynamicItems[item]->getRotation()));
}
auto *abstractItem = dynamic_cast<graphicsUtils::AbstractItem *>(item);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qobject_cast не подойдёт?

emit trajectoryPosOrAngleChanged(abstractItem->id(), abstractItem->pos(), abstractItem->rotation());
}
emit sendNextFrame();
}

void Box2DPhysicsEngine::clearForcesAndStop()
Expand All @@ -364,6 +378,7 @@ void Box2DPhysicsEngine::clearForcesAndStop()
body->SetLinearVelocity({0, 0});
body->SetAngularVelocity(0);
}
//emit trajectorySave();
}

bool Box2DPhysicsEngine::isRobotStuck() const
Expand Down Expand Up @@ -428,6 +443,7 @@ void Box2DPhysicsEngine::onItemDragged(graphicsUtils::AbstractItem *item)
bItem->setRotation(0);
bItem->moveToPosition(positionToBox2D(localScenePos + localCenter));
bItem->setRotation(angleToBox2D(localRotation));
emit trajectoryItemDragged(item->id(), item->pos(), item->rotation());
}
} else {
b2Vec2 pos = positionToBox2D(collidingPolygon.boundingRect().center());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <qrutils/mathUtils/geometry.h>

#include "twoDModel/engine/model/worldModel.h"
#include "plugins/robots/common/twoDModel/src/engine/trajectory/trajectorySaver.h"

class b2World;
class b2Body;
Expand All @@ -34,6 +35,10 @@ namespace twoDModel {
class SensorItem;
}

namespace trajectory {
class TrajectorySaver;
}

namespace model {
namespace physics {
namespace parts {
Expand All @@ -44,6 +49,7 @@ namespace twoDModel {

class Box2DPhysicsEngine : public PhysicsEngineBase
{
Q_OBJECT
public:
Box2DPhysicsEngine(const WorldModel &worldModel, const QList<RobotModel *> &robots);
~Box2DPhysicsEngine();
Expand Down Expand Up @@ -84,6 +90,12 @@ public slots:
void onMousePressed();
void onRecoverRobotPosition(const QPointF &pos);

signals:
void trajectoryPosOrAngleChanged(QString id, QPointF pos, qreal rotation);
void trajectoryItemDragged(QString id, QPointF pos, qreal rotation);
void trajectorySave();
void sendNextFrame();

protected:
void onPixelsInCmChanged(qreal value) override;
void itemAdded(QGraphicsItem *item) override;
Expand All @@ -104,9 +116,11 @@ public slots:
QMap<QGraphicsItem *, parts::Box2DItem *> mBox2DResizableItems; // Takes ownership on b2Body instances
QMap<QGraphicsItem *, parts::Box2DItem *> mBox2DDynamicItems; // Doesn't take ownership
QMap<RobotModel *, QSet<twoDModel::view::SensorItem *>> mRobotSensors; // Doesn't take ownership
QList<parts::Box2DItem *> inMoveItems;

b2Vec2 mPrevPosition;
float mPrevAngle;
TrajectorySaver const *mTrajSaver {};
};

}
Expand Down
15 changes: 14 additions & 1 deletion plugins/robots/common/twoDModel/src/engine/model/robotModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void RobotModel::reinit()
mBeepTime = 0;
mDeltaDegreesOfAngle = 0;
mAcceleration = QPointF(0, 0);
//emit OnStartPlaying();
}

void RobotModel::clear()
Expand Down Expand Up @@ -111,6 +112,7 @@ RobotModel::Wheel *RobotModel::initMotor(int radius, int speed, uint64_t degrees
void RobotModel::playSound(int timeInMs)
{
mBeepTime = qMax(mBeepTime, timeInMs);
emit trajectorySoundStateChanged(mRobotModel.robotId(), mBeepTime);
}

void RobotModel::setNewMotor(int speed, uint degrees, const PortInfo &port, bool breakMode)
Expand Down Expand Up @@ -179,6 +181,8 @@ void RobotModel::stopRobot()
mIsFirstAngleStamp = true;
mPosStamps.clear();
emit playingSoundChanged(false);
emit onStopPlaying();
emit trajectorySave();
for (auto &&engine : mMotors) {
engine->speed = 0;
engine->breakMode = true;
Expand Down Expand Up @@ -301,11 +305,13 @@ QColor RobotModel::markerColor() const
void RobotModel::markerDown(const QColor &color)
{
mMarker = color;
emit trajectoryMarkerColorChanged(mRobotModel.robotId(), color);
}

void RobotModel::markerUp()
{
mMarker = Qt::transparent;
emit trajectoryMarkerColorChanged(mRobotModel.robotId(), Qt::transparent);
}

QVector<int> RobotModel::accelerometerReading() const
Expand Down Expand Up @@ -372,6 +378,10 @@ void RobotModel::nextFragment()
}

emit robotRided(mPos, mAngle);
if (isRiding())
{
emit trajectoryPosOrAngleChanged(mRobotModel.robotId(), mPos, mAngle);
}
}

QPointF RobotModel::position() const
Expand All @@ -384,6 +394,7 @@ void RobotModel::setPosition(const QPointF &newPos)
if (newPos != mPos) {
mPos = newPos;
emit positionChanged(newPos);
emit trajectoryOnitemDragged(mRobotModel.robotId(), mPos, mAngle);
}
}

Expand All @@ -397,6 +408,7 @@ void RobotModel::setRotation(qreal angle)
if (!mathUtils::Math::eq(mAngle, angle)) {
mAngle = angle;
emit rotationChanged(angle);
emit trajectoryOnitemDragged(mRobotModel.robotId(), mPos, mAngle);
}
}

Expand All @@ -415,10 +427,11 @@ bool RobotModel::onTheGround() const
return mIsOnTheGround;
}


void RobotModel::serialize(QDomElement &parent) const
{
QDomElement curRobot = parent.ownerDocument().createElement("robot");
curRobot.setAttribute("id", mRobotModel.robotId());
curRobot.setAttribute("id", mRobotModel.robotId());
mSensorsConfiguration.serialize(curRobot);
serializeWheels(curRobot);

Expand Down
Loading