-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathracecar.gd
More file actions
48 lines (35 loc) · 1.31 KB
/
racecar.gd
File metadata and controls
48 lines (35 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
extends CharacterBody3D
var ground_truth_publisher: GodotRosFloat64ArrayPublisher
const MAX_SPEED = 2.0
const MAX_STEERING = 3.1415 * 30.0 / 180.0
const JUMP_VELOCITY = 4.5
const WHEELBASE = 1
var yaw = 0.0
var velocity_forward: float = 0.0
var dstate: Vector3
var prev_position: Vector3 = Vector3.ZERO
var angular_velocity: float
func _ready():
var topic_name = Config.get_config().get_value("racecar", "ground_truth_topic", "ground_truth")
ground_truth_publisher = GodotRosFloat64ArrayPublisher.new()
ground_truth_publisher.init(Global.ros2_node, topic_name, 10);
func upload_ground_truth():
if not ground_truth_publisher: return
var p = [position.x, position.z, rotation.y, velocity.x, velocity.z]
var ground_truth = PackedFloat64Array(p);
ground_truth_publisher.publish(ground_truth);
func _physics_process(delta: float) -> void:
upload_ground_truth()
# Inputs
var speed = MAX_SPEED * InputSource.get_speed()
var steering = MAX_STEERING * InputSource.get_steering()
#
angular_velocity = speed * tan(steering) / WHEELBASE
rotation.y += angular_velocity * delta
dstate = Vector3(speed, 0, 0).rotated(Vector3.UP, rotation.y) * delta
velocity_forward = speed;
velocity = (position - prev_position) / delta
prev_position = position;
#velocity = dstate/delta;
move_and_collide(dstate)
#move_and_slide();