Added initial BB2B example
This commit is contained in:
parent
29625fb8f9
commit
26d4f56aec
@ -5,8 +5,9 @@ if(ESP_PLATFORM)
|
|||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
project(RoboidCOntrol)
|
project(RoboidControl)
|
||||||
add_subdirectory(LinearAlgebra)
|
add_subdirectory(LinearAlgebra)
|
||||||
|
add_subdirectory(Examples)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17) # Enable c++11 standard
|
set(CMAKE_CXX_STANDARD 17) # Enable c++11 standard
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
|
41
Examples/BB2B.cpp
Normal file
41
Examples/BB2B.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "Thing.h"
|
||||||
|
#include "Things/DifferentialDrive.h"
|
||||||
|
#include "Things/TouchSensor.h"
|
||||||
|
|
||||||
|
using namespace RoboidControl;
|
||||||
|
|
||||||
|
void CollisionSteering();
|
||||||
|
|
||||||
|
DifferentialDrive* bb2b = nullptr;
|
||||||
|
TouchSensor* touchLeft = nullptr;
|
||||||
|
TouchSensor* touchRight = nullptr;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
bb2b = new DifferentialDrive();
|
||||||
|
|
||||||
|
touchLeft = new TouchSensor();
|
||||||
|
touchLeft->SetParent(bb2b);
|
||||||
|
|
||||||
|
touchRight = new TouchSensor();
|
||||||
|
touchRight->SetParent(bb2b);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
CollisionSteering();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CollisionSteering() {
|
||||||
|
if (touchLeft->touchedSomething)
|
||||||
|
bb2b->SetWheelVelocity(bb2b->rightWheel, -0.5f);
|
||||||
|
else
|
||||||
|
bb2b->SetWheelVelocity(bb2b->rightWheel, 0.5f);
|
||||||
|
|
||||||
|
if (touchRight->touchedSomething)
|
||||||
|
bb2b->SetWheelVelocity(bb2b->leftWheel, -0.5f);
|
||||||
|
else
|
||||||
|
bb2b->SetWheelVelocity(bb2b->leftWheel, 0.5f);
|
||||||
|
}
|
22
Examples/CMakeLists.txt
Normal file
22
Examples/CMakeLists.txt
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# examples/CMakeLists.txt
|
||||||
|
|
||||||
|
# Specify the minimum CMake version
|
||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
|
# Specify the path to the main project directory
|
||||||
|
set(MAIN_PROJECT_DIR "${CMAKE_SOURCE_DIR}/..")
|
||||||
|
|
||||||
|
# Set the project name
|
||||||
|
project(Examples)
|
||||||
|
|
||||||
|
include_directories(..)
|
||||||
|
|
||||||
|
# Add the executable for the main project
|
||||||
|
#add_executable(MainExecutable ${SOURCES})
|
||||||
|
# Find the main project library (assuming it's defined in the root CMakeLists.txt)
|
||||||
|
#find_package(RoboidControl REQUIRED) # Replace MyLibrary with your actual library name
|
||||||
|
|
||||||
|
# Add example executables
|
||||||
|
add_executable(BB2B BB2B.cpp)
|
||||||
|
target_link_libraries(BB2B RoboidControl) # Link against your library
|
||||||
|
|
@ -2,14 +2,18 @@
|
|||||||
|
|
||||||
namespace RoboidControl {
|
namespace RoboidControl {
|
||||||
|
|
||||||
RoboidControl::DifferentialDrive::DifferentialDrive(Participant* participant) : Thing(participant) {
|
RoboidControl::DifferentialDrive::DifferentialDrive(Participant* participant)
|
||||||
|
: Thing(participant) {
|
||||||
// this->leftWheel = new Thing(participant);
|
// this->leftWheel = new Thing(participant);
|
||||||
// this->rightWheel = new Thing(participant);
|
// this->rightWheel = new Thing(participant);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DifferentialDrive::SetDimensions(float wheelDiameter, float wheelSeparation) {
|
void DifferentialDrive::SetDimensions(float wheelDiameter,
|
||||||
this->wheelRadius = wheelDiameter > 0 ? wheelDiameter / 2 : -wheelDiameter / 2;
|
float wheelSeparation) {
|
||||||
this->wheelSeparation = wheelSeparation > 0 ? wheelSeparation : -wheelSeparation;
|
this->wheelRadius =
|
||||||
|
wheelDiameter > 0 ? wheelDiameter / 2 : -wheelDiameter / 2;
|
||||||
|
this->wheelSeparation =
|
||||||
|
wheelSeparation > 0 ? wheelSeparation : -wheelSeparation;
|
||||||
this->rpsToMs = wheelDiameter * Passer::LinearAlgebra::pi;
|
this->rpsToMs = wheelDiameter * Passer::LinearAlgebra::pi;
|
||||||
|
|
||||||
float distance = this->wheelSeparation / 2;
|
float distance = this->wheelSeparation / 2;
|
||||||
@ -30,6 +34,10 @@ void DifferentialDrive::SetMotors(Thing* leftWheel, Thing* rightWheel) {
|
|||||||
this->rightWheel->SetPosition(Spherical(distance, Direction::right));
|
this->rightWheel->SetPosition(Spherical(distance, Direction::right));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DifferentialDrive::SetLeftWheelVelocity(float angularSpeed) {}
|
||||||
|
|
||||||
|
void DifferentialDrive::SetRightWheelVelocity(float angularSpeed) {}
|
||||||
|
|
||||||
void DifferentialDrive::Update(unsigned long currentMs) {
|
void DifferentialDrive::Update(unsigned long currentMs) {
|
||||||
// this assumes forward velocity only....
|
// this assumes forward velocity only....
|
||||||
float linearVelocity = this->GetLinearVelocity().distance;
|
float linearVelocity = this->GetLinearVelocity().distance;
|
||||||
@ -41,16 +49,22 @@ void DifferentialDrive::Update(unsigned long currentMs) {
|
|||||||
angularSpeed = -angularSpeed;
|
angularSpeed = -angularSpeed;
|
||||||
|
|
||||||
// wheel separation can be replaced by this->leftwheel->position->distance
|
// wheel separation can be replaced by this->leftwheel->position->distance
|
||||||
float speedLeft = (linearVelocity + angularSpeed * this->wheelSeparation / 2) / this->wheelRadius * Rad2Deg;
|
float speedLeft =
|
||||||
|
(linearVelocity + angularSpeed * this->wheelSeparation / 2) /
|
||||||
|
this->wheelRadius * Rad2Deg;
|
||||||
if (this->leftWheel != nullptr)
|
if (this->leftWheel != nullptr)
|
||||||
this->leftWheel->SetAngularVelocity(Spherical(speedLeft, Direction::left));
|
this->leftWheel->SetAngularVelocity(Spherical(speedLeft, Direction::left));
|
||||||
|
|
||||||
float speedRight = (linearVelocity - angularSpeed * this->wheelSeparation / 2) / this->wheelRadius * Rad2Deg;
|
float speedRight =
|
||||||
|
(linearVelocity - angularSpeed * this->wheelSeparation / 2) /
|
||||||
|
this->wheelRadius * Rad2Deg;
|
||||||
if (this->rightWheel != nullptr)
|
if (this->rightWheel != nullptr)
|
||||||
this->rightWheel->SetAngularVelocity(Spherical(speedRight, Direction::right));
|
this->rightWheel->SetAngularVelocity(
|
||||||
|
Spherical(speedRight, Direction::right));
|
||||||
|
|
||||||
// std::cout << "lin. speed " << linearVelocity << " ang. speed " << angularVelocity.distance << " left wheel "
|
// std::cout << "lin. speed " << linearVelocity << " ang. speed " <<
|
||||||
// << speedLeft << " right wheel " << speedRight << "\n";
|
// angularVelocity.distance << " left wheel "
|
||||||
|
// << speedLeft << " right wheel " << speedRight << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace RoboidControl
|
} // namespace RoboidControl
|
@ -12,6 +12,9 @@ class DifferentialDrive : public Thing {
|
|||||||
void SetDimensions(float wheelDiameter, float wheelSeparation);
|
void SetDimensions(float wheelDiameter, float wheelSeparation);
|
||||||
void SetMotors(Thing* leftWheel, Thing* rightWheel);
|
void SetMotors(Thing* leftWheel, Thing* rightWheel);
|
||||||
|
|
||||||
|
void SetLeftWheelVelocity(float angularSpeed);
|
||||||
|
void SetRightWheelVelocity(float angularSpeed);
|
||||||
|
|
||||||
virtual void Update(unsigned long currentMs) override;
|
virtual void Update(unsigned long currentMs) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user