The Chirp class implements the simulation model of the Chirp robot. More...
#include <chirp.h>
Public Member Functions | |
Chirp (b2World *world, unsigned id, QPointF position, float startAngle, float noiseMax, float radius, float wheelDistance, float wheelRadius, float wheelWidth) | |
Constructor creating a Chirp object based on a number of parameters. More... | |
~Chirp () | |
QRectF | boundingRect () const |
Returns the computed bounding rectangle used for drawing and redrawing the object. More... | |
void | paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
Draws the robot and wheels for display. More... | |
void | setSpeed (QVector< float > speeds) |
Simple setter for wheel speeds. More... | |
QVector< float > | sensors () const |
Getter for all the sensors on the robot. More... | |
b2Body * | body () const |
Simple getter for _body field. More... | |
QGraphicsItem * | item () const |
Simple getter for returning QGraphicsItem connected to this object. More... | |
void | step (float dt) |
This is called by World each step to help implement more custom behaviors in the simulation (like wheels not sliding sideways) and to update the sensor values. More... | |
void | stepGraphics () |
Updates the viewable model of the robot to reflect the current world state. More... | |
![]() | |
unsigned | id () const |
Controller * | controller () |
![]() | |
PhysicalObject () | |
virtual | ~PhysicalObject () |
Private Member Functions | |
void | applyImpulses () |
void | removeLateralSpeed () |
void | computeBoundingRect () |
void | createPhysicalBody (QPointF position, float startAngle, b2World *world) |
void | createSensors () |
Private Attributes | |
b2Body * | _body |
float | _halfWheelDistance |
float | _wheelRadius |
float | _wheelWidth |
float | _radius |
float | _noiseMax |
quint32 | _id |
QRectF | _boundingRect |
QVector< Sensor * > | _sensors |
float | _leftWheelSpeed |
float | _rightWheelSpeed |
bool | _isSelected |
Friends | |
PhysicalObject * | chirpFactory (World *world, const QJsonObject &obj) |
chirpFactory follows the PhysicalObject FactoryFunction, creating the Chirp object from a JSON object. More... | |
Additional Inherited Members | |
![]() | |
void | setId (unsigned id) |
void | setController (Controller *controller) |
The Chirp class implements the simulation model of the Chirp robot.
It implements the Robot interface, the PhysicalObject abstract base class and the QGraphicsItem abstract base class. It handles the custom physics required to make the robot not slide like the wheels have no sideways friction, drawing the main body and both wheels, and lastly holds a ChirpController that can control the speeds of the wheels along with reading sensor datas.
The Chirp robot in simulation:
|
explicit |
Constructor creating a Chirp object based on a number of parameters.
world | World for the robot to be created in. |
id | Unique id for the robot. |
position | Starting position of the robot. |
startAngle | Starting angle of the robot. |
noiseMax | Max noise values on the wheel speeds. |
radius | Radius of the robot body. |
wheelDistance | Distance between wheels. |
wheelRadius | Radius of the wheels. |
wheelWidth | Width of the wheels. |
Creates a physical model of the robot with Box2D, sets up the drawing of the robot and sets up the sensors of the robot.
References _halfWheelDistance, _leftWheelSpeed, _noiseMax, _radius, _rightWheelSpeed, _wheelRadius, _wheelWidth, computeBoundingRect(), createPhysicalBody(), createSensors(), Robot::setController(), and Robot::setId().
|
private |
References _body, _halfWheelDistance, _leftWheelSpeed, _noiseMax, and _rightWheelSpeed.
Referenced by step().
|
inlinevirtual |
Simple getter for _body field.
Implements PhysicalObject.
References _body.
QRectF Chirp::boundingRect | ( | ) | const |
Returns the computed bounding rectangle used for drawing and redrawing the object.
References _boundingRect.
Referenced by paint().
|
private |
References _body, _boundingRect, max(), and min().
Referenced by Chirp().
|
private |
References _body, _halfWheelDistance, _radius, _wheelRadius, and _wheelWidth.
Referenced by Chirp().
|
private |
|
inlinevirtual |
Simple getter for returning QGraphicsItem connected to this object.
Implements PhysicalObject.
void Chirp::paint | ( | QPainter * | painter, |
const QStyleOptionGraphicsItem * | option, | ||
QWidget * | widget | ||
) |
Draws the robot and wheels for display.
References _halfWheelDistance, _radius, _wheelRadius, _wheelWidth, and boundingRect().
|
private |
|
virtual |
Getter for all the sensors on the robot.
Implements Robot.
References _sensors.
Referenced by ChirpNetworkController::handleGetSensorsMessage().
|
virtual |
Simple setter for wheel speeds.
speeds | Contains two floats, first for left wheel and second for right wheel. |
Implements Robot.
References _leftWheelSpeed, and _rightWheelSpeed.
Referenced by ChirpNetworkController::handleSetSpeedMessage().
|
virtual |
This is called by World each step to help implement more custom behaviors in the simulation (like wheels not sliding sideways) and to update the sensor values.
dt | The time in seconds since last step. |
Reimplemented from PhysicalObject.
References _sensors, applyImpulses(), removeLateralSpeed(), and Sensor::update().
|
virtual |
Updates the viewable model of the robot to reflect the current world state.
Reimplemented from PhysicalObject.
|
friend |
chirpFactory follows the PhysicalObject FactoryFunction, creating the Chirp object from a JSON object.
world | World to put the physical object model in. |
obj | JSON object containing the parameters for the robot. |
|
private |
Referenced by applyImpulses(), body(), computeBoundingRect(), createPhysicalBody(), removeLateralSpeed(), stepGraphics(), and ~Chirp().
|
private |
Referenced by boundingRect(), and computeBoundingRect().
|
private |
Referenced by applyImpulses(), Chirp(), createPhysicalBody(), and paint().
|
private |
|
private |
|
private |
Referenced by applyImpulses(), Chirp(), and setSpeed().
|
private |
Referenced by applyImpulses(), and Chirp().
|
private |
Referenced by Chirp(), createPhysicalBody(), createSensors(), and paint().
|
private |
Referenced by applyImpulses(), Chirp(), and setSpeed().
|
private |
Referenced by createSensors(), sensors(), step(), and ~Chirp().
|
private |
Referenced by Chirp(), createPhysicalBody(), and paint().
|
private |
Referenced by Chirp(), createPhysicalBody(), and paint().