ChirpSim
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
Chirp Class Reference

The Chirp class implements the simulation model of the Chirp robot. More...

#include <chirp.h>

Inheritance diagram for Chirp:
Inheritance graph

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...
 
- Public Member Functions inherited from Robot
unsigned id () const
 
Controllercontroller ()
 
- Public Member Functions inherited from PhysicalObject
 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

PhysicalObjectchirpFactory (World *world, const QJsonObject &obj)
 chirpFactory follows the PhysicalObject FactoryFunction, creating the Chirp object from a JSON object. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Robot
void setId (unsigned id)
 
void setController (Controller *controller)
 

Detailed Description

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:

chirp.png

Constructor & Destructor Documentation

Chirp::Chirp ( b2World *  world,
unsigned  id,
QPointF  position,
float  startAngle,
float  noiseMax,
float  radius,
float  wheelDistance,
float  wheelRadius,
float  wheelWidth 
)
explicit

Constructor creating a Chirp object based on a number of parameters.

Parameters
worldWorld for the robot to be created in.
idUnique id for the robot.
positionStarting position of the robot.
startAngleStarting angle of the robot.
noiseMaxMax noise values on the wheel speeds.
radiusRadius of the robot body.
wheelDistanceDistance between wheels.
wheelRadiusRadius of the wheels.
wheelWidthWidth 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().

Here is the call graph for this function:

Chirp::~Chirp ( )

References _body, and _sensors.

Member Function Documentation

void Chirp::applyImpulses ( )
private

References _body, _halfWheelDistance, _leftWheelSpeed, _noiseMax, and _rightWheelSpeed.

Referenced by step().

Here is the caller graph for this function:

b2Body* Chirp::body ( ) const
inlinevirtual

Simple getter for _body field.

Returns
Physical representation of object used by b2World class.

Implements PhysicalObject.

References _body.

QRectF Chirp::boundingRect ( ) const

Returns the computed bounding rectangle used for drawing and redrawing the object.

Returns
bounding rectangle.

References _boundingRect.

Referenced by paint().

Here is the caller graph for this function:

void Chirp::computeBoundingRect ( )
private

References _body, _boundingRect, max(), and min().

Referenced by Chirp().

Here is the call graph for this function:

Here is the caller graph for this function:

void Chirp::createPhysicalBody ( QPointF  position,
float  startAngle,
b2World *  world 
)
private

References _body, _halfWheelDistance, _radius, _wheelRadius, and _wheelWidth.

Referenced by Chirp().

Here is the caller graph for this function:

void Chirp::createSensors ( )
private

References _radius, _sensors, and DEGTORAD.

Referenced by Chirp().

Here is the caller graph for this function:

QGraphicsItem* Chirp::item ( ) const
inlinevirtual

Simple getter for returning QGraphicsItem connected to this object.

Returns
this casted to a non-const pointer.

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().

Here is the call graph for this function:

void Chirp::removeLateralSpeed ( )
private

References _body.

Referenced by step().

Here is the caller graph for this function:

QVector< float > Chirp::sensors ( ) const
virtual

Getter for all the sensors on the robot.

Returns
Array containing sensor values read at the time of calling.

Implements Robot.

References _sensors.

Referenced by ChirpNetworkController::handleGetSensorsMessage().

Here is the caller graph for this function:

void Chirp::setSpeed ( QVector< float >  speeds)
virtual

Simple setter for wheel speeds.

Parameters
speedsContains two floats, first for left wheel and second for right wheel.

Implements Robot.

References _leftWheelSpeed, and _rightWheelSpeed.

Referenced by ChirpNetworkController::handleSetSpeedMessage().

Here is the caller graph for this function:

void Chirp::step ( float  dt)
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.

Parameters
dtThe time in seconds since last step.

Reimplemented from PhysicalObject.

References _sensors, applyImpulses(), removeLateralSpeed(), and Sensor::update().

Here is the call graph for this function:

void Chirp::stepGraphics ( )
virtual

Updates the viewable model of the robot to reflect the current world state.

Reimplemented from PhysicalObject.

References _body, and RADTODEG.

Friends And Related Function Documentation

PhysicalObject* chirpFactory ( World world,
const QJsonObject &  obj 
)
friend

chirpFactory follows the PhysicalObject FactoryFunction, creating the Chirp object from a JSON object.

See Also
physicalobjectfactory.h
Parameters
worldWorld to put the physical object model in.
objJSON object containing the parameters for the robot.
Returns
A constructed Chirp object.

Member Data Documentation

b2Body* Chirp::_body
private
QRectF Chirp::_boundingRect
private
float Chirp::_halfWheelDistance
private
quint32 Chirp::_id
private
bool Chirp::_isSelected
private
float Chirp::_leftWheelSpeed
private

Referenced by applyImpulses(), Chirp(), and setSpeed().

float Chirp::_noiseMax
private

Referenced by applyImpulses(), and Chirp().

float Chirp::_radius
private
float Chirp::_rightWheelSpeed
private

Referenced by applyImpulses(), Chirp(), and setSpeed().

QVector<Sensor*> Chirp::_sensors
private

Referenced by createSensors(), sensors(), step(), and ~Chirp().

float Chirp::_wheelRadius
private

Referenced by Chirp(), createPhysicalBody(), and paint().

float Chirp::_wheelWidth
private

Referenced by Chirp(), createPhysicalBody(), and paint().


The documentation for this class was generated from the following files: