Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
praphulkallakuri committed Oct 26, 2021
1 parent dc19334 commit dadc596
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
12 changes: 7 additions & 5 deletions Source/RapyutaSimulationPlugins/Private/Robots/RobotVehicle.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// Copyright 2020-2021 Rapyuta Robotics Co., Ltd.

#include "Robots/RobotVehicle.h"

#include "Drives/RobotVehicleMovementComponent.h"
#include "Msgs/ROS2TFMsg.h"
#include "ROS2Node.h"

ARobotVehicle::ARobotVehicle(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
void ARobotVehicle::InitializeMoveComponent()
{
RobotVehicleMoveComponent = NewObject<URobotVehicleMovementComponent>(this, TEXT("RobotVehicleMoveComponent"));
verify(RobotVehicleMoveComponent);
RobotVehicleMoveComponent->InitMovementComponent();
}

void ARobotVehicle::Tick(float DeltaSeconds)
Expand All @@ -17,18 +20,17 @@ void ARobotVehicle::Tick(float DeltaSeconds)
void ARobotVehicle::SetLinearVel(const FVector& InLinearVelocity)
{
// We're assuming input is in meters, so convert to centimeters.
MoveComponent->Velocity = InLinearVelocity;
RobotVehicleMoveComponent->Velocity = InLinearVelocity;
}

void ARobotVehicle::SetAngularVel(const FVector& InAngularVelocity)
{
MoveComponent->AngularVelocity = InAngularVelocity;
RobotVehicleMoveComponent->AngularVelocity = InAngularVelocity;
}

void ARobotVehicle::BeginPlay()
{
Super::BeginPlay();
MoveComponent->InitMovementComponent();
}

void ARobotVehicle::EndPlay(const EEndPlayReason::Type EndPlayReason)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ ATurtlebotBurger::ATurtlebotBurger(const FObjectInitializer& ObjectInitializer)
PrimaryActorTick.bCanEverTick = true;

Init();

}

void ATurtlebotBurger::InitializeMoveComponent()
{
DifferentialDriveComponent = NewObject<UDifferentialDriveComponent>(this, TEXT("DifferentialDriveComponent"));
}

void ATurtlebotBurger::Init()
{
if (!IsInitialized)
{
InitializeMoveComponent();
Base = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Base"));
LidarSensor = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("LidarSensor"));
WheelLeft = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("WheelLeft"));
Expand Down Expand Up @@ -56,8 +61,6 @@ void ATurtlebotBurger::SetupWheels()
{
if (IsInitialized)
{
MoveComponent = CreateDefaultSubobject<UDifferentialDriveComponent>(TEXT("MoveComponent"));
UDifferentialDriveComponent* DifferentialDriveComponent = Cast<UDifferentialDriveComponent>(MoveComponent);
DifferentialDriveComponent->SetWheels(Base_WheelLeft, Base_WheelRight);
DifferentialDriveComponent->SetPerimeter();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Copyright 2020-2021 Rapyuta Robotics Co., Ltd.

#pragma once

#include <random>
#include <Msgs/ROS2OdometryMsg.h>
#include "CoreMinimal.h"
#include "GameFramework/FloatingPawnMovement.h"
#include "Kismet/GameplayStatics.h"
#include "RobotVehicleMovementComponent.generated.h"

// #include <ran>
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class RCLUE_API URobotVehicleMovementComponent : public UPawnMovementComponent
{
Expand Down Expand Up @@ -43,7 +44,7 @@ class RCLUE_API URobotVehicleMovementComponent : public UPawnMovementComponent
FTransform GetOdomTF();

UFUNCTION(BlueprintCallable)
virtual void InitMovementComponent();
virtual void InitMovementComponent(); //change the

protected:
virtual void BeginPlay() override;
Expand Down
12 changes: 10 additions & 2 deletions Source/RapyutaSimulationPlugins/Public/Robots/RobotVehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "RobotVehicle.generated.h"

class URobotVehicleMovementComponent;
UCLASS()
class RAPYUTASIMULATIONPLUGINS_API ARobotVehicle : public APawn
{
Expand All @@ -16,10 +17,17 @@ class RAPYUTASIMULATIONPLUGINS_API ARobotVehicle : public APawn
public:

UPROPERTY(EditAnywhere, BlueprintReadWrite)
URobotVehicleMovementComponent *MoveComponent;
URobotVehicleMovementComponent* RobotVehicleMoveComponent = nullptr;

virtual void InitializeMoveComponent();

template<typename TMovementComponent>
TMovementComponent* GetOwnMovementComponent() const
{
return Cast<TMovementComponent>(GetMovementComponent());
}

public:
ARobotVehicle(const FObjectInitializer& ObjectInitializer);

virtual void Tick(float DeltaSeconds) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class RAPYUTASIMULATIONPLUGINS_API ATurtlebotBurger : public ARobotVehicle
public:
ATurtlebotBurger(const FObjectInitializer& ObjectInitializer);

UPROPERTY(EditAnywhere, BlueprintReadWrite)
UDifferentialDriveComponent* DifferentialDriveComponent = nullptr;

virtual void InitializeMoveComponent() override;

protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
Expand Down Expand Up @@ -79,7 +84,5 @@ class RAPYUTASIMULATIONPLUGINS_API ATurtlebotBurger : public ARobotVehicle
void SetupConstraintsAndPhysics();

UFUNCTION()
void SetupWheels();


void SetupWheels();
};

0 comments on commit dadc596

Please sign in to comment.