BotNavSim  v0.4.3
Mobile Robot Simulation
BoeBot Class Reference

BoeBot differential drive control system. Built using data from: https://www.parallax.com/product/900-00008 See final report for diagram of implementation More...

Inheritance diagram for BoeBot:
Collaboration diagram for BoeBot:

Public Attributes

float maxWheelRpm = 50f
 The max wheel RPM (50RPM for parallax continuous rotation servo) More...
 
float maxWheelTorque = 0.268f
 The max wheel torque (0.268NM for parallax continuous rotation servo). More...
 
float Kp = 0.5f
 Control system gain parameter. More...
 

Private Member Functions

void Awake ()
 
void Update ()
 

Private Attributes

Robot _robot
 
WheelCollider _leftWheel
 
WheelCollider _rightWheel
 
float forwardAngle
 
float frontBack
 
float rightAngle
 
float rightLeft
 
float leftTarget
 
float rightTarget
 
float leftTorque
 
float rightTorque
 

Detailed Description

BoeBot differential drive control system. Built using data from: https://www.parallax.com/product/900-00008 See final report for diagram of implementation

Definition at line 10 of file BoeBot.cs.

Member Function Documentation

void BoeBot.Awake ( )
private

Definition at line 48 of file BoeBot.cs.

48  {
49  _robot = GetComponent<Robot>();
50  _leftWheel = transform.Find("Left Wheel").GetComponent<WheelCollider>();
51  _rightWheel = transform.Find("Right Wheel").GetComponent<WheelCollider>();
52  }
WheelCollider _leftWheel
Definition: BoeBot.cs:34
Robot _robot
Definition: BoeBot.cs:33
WheelCollider _rightWheel
Definition: BoeBot.cs:35
void BoeBot.Update ( )
private

Definition at line 54 of file BoeBot.cs.

54  {
55 
56  if (!_robot.moveEnabled) {
57  _leftWheel.motorTorque = 0f;
58  _rightWheel.motorTorque = 0f;
59  return;
60  }
61 
62  Vector3 target = _robot.navigationCommand;
63  target.y = 0f;
64  target.Normalize();
65  Debug.DrawRay(transform.position, target, Color.green);
66 
67  if(target.magnitude < 0.1f) {
68  rightTarget = 0f;
69  leftTarget = 0f;
70  } else {
71  forwardAngle = Vector3.Angle(target, transform.forward);
72  frontBack = Mathf.Cos(forwardAngle * Mathf.Deg2Rad); //1:forward, -1:backward, 0:(left or right)
73 
74  rightAngle = Vector3.Angle(target, transform.right);
75  rightLeft = Mathf.Cos(rightAngle * Mathf.Deg2Rad); //1:right, -1:left, 0:(forward or back)
76 
77  rightTarget = Mathf.Clamp(frontBack+rightLeft, -1f, 1f);
78  leftTarget = Mathf.Clamp(frontBack-rightLeft, -1f, 1f);
79  }
80 
81  // drive wheel
83  _leftWheel.motorTorque = Mathf.Clamp(leftTorque, -maxWheelTorque, maxWheelTorque);
85  _rightWheel.motorTorque = Mathf.Clamp(rightTorque, -maxWheelTorque, maxWheelTorque);
86 
87  Debug.DrawRay(_leftWheel.transform.position, transform.forward * leftTarget * 0.1f, Color.magenta);
88  Debug.DrawRay(_rightWheel.transform.position, transform.forward * rightTarget * 0.1f, Color.magenta);
89 
90  }
float maxWheelRpm
The max wheel RPM (50RPM for parallax continuous rotation servo)
Definition: BoeBot.cs:17
float frontBack
Definition: BoeBot.cs:38
Vector3 navigationCommand
The cached navigation bearing from INavigation.
Definition: Robot.cs:89
float leftTarget
Definition: BoeBot.cs:42
float rightTarget
Definition: BoeBot.cs:43
float rightLeft
Definition: BoeBot.cs:40
WheelCollider _leftWheel
Definition: BoeBot.cs:34
float rightTorque
Definition: BoeBot.cs:46
bool moveEnabled
A flag indicating whether the robot should try moving.
Definition: Robot.cs:29
Robot _robot
Definition: BoeBot.cs:33
float Kp
Control system gain parameter.
Definition: BoeBot.cs:27
float forwardAngle
Definition: BoeBot.cs:37
float leftTorque
Definition: BoeBot.cs:45
WheelCollider _rightWheel
Definition: BoeBot.cs:35
float maxWheelTorque
The max wheel torque (0.268NM for parallax continuous rotation servo).
Definition: BoeBot.cs:22
float rightAngle
Definition: BoeBot.cs:39

Member Data Documentation

WheelCollider BoeBot._leftWheel
private

Definition at line 34 of file BoeBot.cs.

WheelCollider BoeBot._rightWheel
private

Definition at line 35 of file BoeBot.cs.

Robot BoeBot._robot
private

Definition at line 33 of file BoeBot.cs.

float BoeBot.forwardAngle
private

Definition at line 37 of file BoeBot.cs.

float BoeBot.frontBack
private

Definition at line 38 of file BoeBot.cs.

float BoeBot.Kp = 0.5f

Control system gain parameter.

Definition at line 27 of file BoeBot.cs.

float BoeBot.leftTarget
private

Definition at line 42 of file BoeBot.cs.

float BoeBot.leftTorque
private

Definition at line 45 of file BoeBot.cs.

float BoeBot.maxWheelRpm = 50f

The max wheel RPM (50RPM for parallax continuous rotation servo)

Definition at line 17 of file BoeBot.cs.

float BoeBot.maxWheelTorque = 0.268f

The max wheel torque (0.268NM for parallax continuous rotation servo).

Definition at line 22 of file BoeBot.cs.

float BoeBot.rightAngle
private

Definition at line 39 of file BoeBot.cs.

float BoeBot.rightLeft
private

Definition at line 40 of file BoeBot.cs.

float BoeBot.rightTarget
private

Definition at line 43 of file BoeBot.cs.

float BoeBot.rightTorque
private

Definition at line 46 of file BoeBot.cs.


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