Roboid Control for C++
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | List of all members
RoboidControl::DifferentialDrive Class Reference

Detailed Description

A thing which can move itself using a differential drive system.

See also
https://en.wikipedia.org/wiki/Differential_wheeled_robot

#include <DifferentialDrive.h>

Inheritance diagram for RoboidControl::DifferentialDrive:
RoboidControl::Thing

Public Types

enum  Type : unsigned char {
  Undetermined , Switch , DistanceSensor , DirectionalSensor ,
  TemperatureSensor , TouchSensor , ControlledMotor , UncontrolledMotor ,
  Servo , Roboid , Humanoid , ExternalSensor ,
  DifferentialDrive
}
 Predefined thing types.
 

Public Member Functions

 DifferentialDrive ()
 Create a differential drive without networking support.
 
 DifferentialDrive (Participant *participant, unsigned char thingId=0)
 Create a differential drive with networking support.
 
 DifferentialDrive (Thing *parent, unsigned char thingId=0)
 Create a new child differential drive.
 
void SetDriveDimensions (float wheelDiameter, float wheelSeparation)
 Configures the dimensions of the drive.
 
void SetMotors (Thing *leftWheel, Thing *rightWheel)
 Congures the motors for the wheels.
 
void SetWheelVelocity (float speedLeft, float speedRight)
 Directly specify the speeds of the motors.
 
virtual void Update (unsigned long currentMs, bool recursive=true) override
 
void SetName (const char *name)
 
const char * GetName () const
 
void SetModel (const char *url)
 Sets the location from where the 3D model of this Thing can be loaded from.
 
virtual void SetParent (Thing *parent)
 Sets the parent of this Thing.
 
ThingGetParent ()
 Gets the parent of this Thing.
 
ThingGetChildByIndex (unsigned char ix)
 Get a child by index.
 
virtual void AddChild (Thing *child)
 Add a child Thing to this Thing.
 
ThingRemoveChild (Thing *child)
 Remove the given thing as a child of this thing.
 
ThingGetChild (unsigned char id, bool recurse=false)
 Get a child by thing Id.
 
ThingFindChild (const char *name, bool recurse=true)
 Find a thing by name.
 
void SetPosition (Spherical position)
 Set the position of the thing.
 
Spherical GetPosition ()
 Get the position of the thing.
 
void SetOrientation (SwingTwist orientation)
 Set the orientation of the thing.
 
SwingTwist GetOrientation ()
 Get the orientation of the thing.
 
void SetLinearVelocity (Spherical linearVelocity)
 Set the linear velocity of the thing.
 
virtual Spherical GetLinearVelocity ()
 Get the linear velocity of the thing.
 
virtual void SetAngularVelocity (Spherical angularVelocity)
 Set the angular velocity of the thing.
 
virtual Spherical GetAngularVelocity ()
 Get the angular velocity of the thing.
 
void Update (bool recursive=false)
 Updates the state of the thing.
 
virtual int GenerateBinary (char *buffer, unsigned char *ix)
 Function used to generate binary data for this thing.
 
virtual void ProcessBinary (char *bytes)
 Function used to process binary data received for this thing.
 

Static Public Member Functions

static unsigned long GetTimeMs ()
 Get the current time in milliseconds.
 
static void UpdateThings (unsigned long currentTimeMs)
 

Public Attributes

bool terminate = false
 Terminated things are no longer updated.
 
Participantowner = nullptr
 The participant managing this thing.
 
unsigned char id = 0
 The ID of the thing.
 
unsigned char type = Type::Undetermined
 The type of Thing This can be either a Thing::Type of a byte value for custom types.
 
const char * name = nullptr
 The name of the thing.
 
bool nameChanged = false
 
const char * modelUrl = nullptr
 An URL pointing to the location where a model of the thing can be found.
 
float modelScale = 1
 The scale of the model (deprecated I think)
 
unsigned char childCount = 0
 The number of children.
 
bool hierarchyChanged = true
 Indicator that the hierarchy of the thing has changed.
 
bool positionUpdated = false
 Boolean indicating that the thing has an updated position.
 
bool orientationUpdated = false
 Boolean indicating the thing has an updated orientation.
 
bool linearVelocityUpdated = false
 Boolean indicating the thing has an updated linear velocity.
 
bool angularVelocityUpdated = false
 Boolean indicating the thing has an updated angular velocity.
 

Protected Attributes

float wheelRadius = 1.0f
 The radius of a wheel in meters.
 
float wheelSeparation = 1.0f
 The distance between the wheels in meters.
 
float rpsToMs = 1.0f
 Convert revolutions per second to meters per second.
 
ThingleftWheel = nullptr
 The left wheel.
 
ThingrightWheel = nullptr
 The right wheel.
 

Constructor & Destructor Documentation

◆ DifferentialDrive() [1/2]

RoboidControl::DifferentialDrive::DifferentialDrive ( Participant participant,
unsigned char  thingId = 0 
)

Create a differential drive with networking support.

Parameters
participantThe local participant
thingIdThe ID of the thing, leave out or set to zero to generate an ID

◆ DifferentialDrive() [2/2]

RoboidControl::DifferentialDrive::DifferentialDrive ( Thing parent,
unsigned char  thingId = 0 
)

Create a new child differential drive.

Parameters
parentThe parent thing
thingIdThe ID of the thing, leave out or set to zero to generate an ID

Member Function Documentation

◆ SetDriveDimensions()

void RoboidControl::DifferentialDrive::SetDriveDimensions ( float  wheelDiameter,
float  wheelSeparation 
)

Configures the dimensions of the drive.

Parameters
wheelDiameterThe diameter of the wheels in meters
wheelSeparationThe distance between the wheels in meters

These values are used to compute the desired wheel speed from the set linear and angular velocity.

See also
SetLinearVelocity SetAngularVelocity

◆ SetMotors()

void RoboidControl::DifferentialDrive::SetMotors ( Thing leftWheel,
Thing rightWheel 
)

Congures the motors for the wheels.

Parameters
leftWheelThe motor for the left wheel
rightWheelThe motor for the right wheel

◆ SetWheelVelocity()

void RoboidControl::DifferentialDrive::SetWheelVelocity ( float  speedLeft,
float  speedRight 
)

Directly specify the speeds of the motors.

Parameters
speedLeftThe speed of the left wheel in degrees per second. Positive moves the robot in the forward direction.
speedRightThe speed of the right wheel in degrees per second. Positive moves the robot in the forward direction.

◆ Update()

void RoboidControl::DifferentialDrive::Update ( unsigned long  currentMs,
bool  recursive = true 
)
overridevirtual

Reimplemented from RoboidControl::Thing.

◆ SetModel()

void RoboidControl::Thing::SetModel ( const char *  url)
inherited

Sets the location from where the 3D model of this Thing can be loaded from.

Parameters
urlThe url of the model
Remarks
Although the roboid implementation is not dependent on the model, the only official supported model format is .obj

◆ SetParent()

void RoboidControl::Thing::SetParent ( Thing parent)
virtualinherited

Sets the parent of this Thing.

Parameters
parentThe Thing which should become the parent

◆ GetParent()

Thing * RoboidControl::Thing::GetParent ( )
inherited

Gets the parent of this Thing.

Returns
The parent Thing

◆ GetChildByIndex()

Thing * RoboidControl::Thing::GetChildByIndex ( unsigned char  ix)
inherited

Get a child by index.

Parameters
ixThe child index
Returns
The found thing of nullptr when nothing is found

◆ AddChild()

void RoboidControl::Thing::AddChild ( Thing child)
virtualinherited

Add a child Thing to this Thing.

Parameters
childThe Thing which should become a child
Remarks
When the Thing is already a child, it will not be added again

◆ RemoveChild()

Thing * RoboidControl::Thing::RemoveChild ( Thing child)
inherited

Remove the given thing as a child of this thing.

Parameters
childThe child to remove
Returns
The removed child or nullptr if the child could not be found

◆ GetChild()

Thing * RoboidControl::Thing::GetChild ( unsigned char  id,
bool  recurse = false 
)
inherited

Get a child by thing Id.

Parameters
idThe thing ID to find
recurseLook recursively through all descendants
Returns
The found thing of nullptr when nothing is found

◆ FindChild()

Thing * RoboidControl::Thing::FindChild ( const char *  name,
bool  recurse = true 
)
inherited

Find a thing by name.

Parameters
nameThe name of the thing
recurseLook recursively through all descendants
Returns
The found thing or nullptr when nothing is found

◆ SetPosition()

void RoboidControl::Thing::SetPosition ( Spherical  position)
inherited

Set the position of the thing.

Parameters
positionThe new position in local space, in meters

◆ GetPosition()

Spherical RoboidControl::Thing::GetPosition ( )
inherited

Get the position of the thing.

Returns
The position in local space, in meters

◆ SetOrientation()

void RoboidControl::Thing::SetOrientation ( SwingTwist  orientation)
inherited

Set the orientation of the thing.

Parameters
orientationThe new orientation in local space

◆ GetOrientation()

SwingTwist RoboidControl::Thing::GetOrientation ( )
inherited

Get the orientation of the thing.

Returns
The orienation in local space

◆ SetLinearVelocity()

void RoboidControl::Thing::SetLinearVelocity ( Spherical  linearVelocity)
inherited

Set the linear velocity of the thing.

Parameters
linearVelocityThe new linear velocity in local space, in meters per second

◆ GetLinearVelocity()

Spherical RoboidControl::Thing::GetLinearVelocity ( )
virtualinherited

Get the linear velocity of the thing.

Returns
The linear velocity in local space, in meters per second

◆ SetAngularVelocity()

void RoboidControl::Thing::SetAngularVelocity ( Spherical  angularVelocity)
virtualinherited

Set the angular velocity of the thing.

Parameters
angularVelocitythe new angular velocity in local space

Reimplemented in RoboidControl::Arduino::DRV8833Motor.

◆ GetAngularVelocity()

Spherical RoboidControl::Thing::GetAngularVelocity ( )
virtualinherited

Get the angular velocity of the thing.

Returns
The angular velocity in local space

◆ GetTimeMs()

unsigned long RoboidControl::Thing::GetTimeMs ( )
staticinherited

Get the current time in milliseconds.

Returns
The current time in milliseconds

◆ GenerateBinary()

int RoboidControl::Thing::GenerateBinary ( char *  buffer,
unsigned char *  ix 
)
virtualinherited

Function used to generate binary data for this thing.

Parameters
bufferThe byte array for thw binary data
ixThe starting position for writing the binary data
Returns
The size of the binary data

Reimplemented in RoboidControl::DigitalSensor, RoboidControl::TemperatureSensor, and RoboidControl::TouchSensor.

◆ ProcessBinary()

void RoboidControl::Thing::ProcessBinary ( char *  bytes)
virtualinherited

Function used to process binary data received for this thing.

Parameters
bytesThe binary data

Reimplemented in RoboidControl::DigitalSensor, RoboidControl::TemperatureSensor, and RoboidControl::TouchSensor.