Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* A two-link robotic arm driven by Box2D revolute-joint motors.
*/
model Box2D_Articulated_Arm

global parent: physical_world {
string library <- "box2D";
float step <- 1.0 / 60;
int world_width <- 200;
int world_height <- 100;
geometry shape <- rectangle(world_width, world_height);
point gravity <- {0, 0, 0};
joint shoulder_joint <- nil;
joint elbow_joint <- nil;

init {
create arm_base {
location <- {45, 50};
}
create arm_link number: 2 {
location <- index = 0 ? {75, 50} : {125, 50};
}

shoulder_joint <- create_hinge_joint(arm_base[0], arm_link[0], {50, 50}, -1.2, 1.2, 0.0, 80.0);
elbow_joint <- create_hinge_joint(arm_link[0], arm_link[1], {100, 50}, -1.2, 1.2, 0.0, 45.0);
}

reflex drive_arm {
shoulder_joint.motorSpeed <- 1.5 * sin(cycle * 3);
elbow_joint.motorSpeed <- 2.0 * sin(cycle * 3 + 90);
}
}

species arm_base skills: [static_body] {
geometry shape <- box(10, 14, 0.1);

aspect default {
draw shape color: #darkgray;
}
}

species arm_link skills: [dynamic_body] {
geometry shape <- box(50, 8, 0.1);
float mass <- 2.0;
float friction <- 0.5;

aspect default {
draw shape color: #steelblue rotate: float(rotation.key);
}
}

experiment "Box2D Articulated Arm" type: gui {
output {
display Arm type: 2d axes: false {
species arm_base;
species arm_link;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/**
* A car whose wheels are Box2D wheel joints (suspension + motor), followed by a trailer
* attached with a rope joint and a hanging load attached with a distance (spring) joint.
*/
model Box2D_Wheel_Car

global parent: physical_world {
string library <- "box2D";
float step <- 1.0 / 60;
int world_width <- 300;
int world_height <- 100;
geometry shape <- rectangle(world_width, world_height);
point gravity <- {0, -9.81, 0};
list<joint> motors <- [];

init {
create ground {
location <- {150, 5};
}
create chassis {
location <- {40, 25};
}
create wheel number: 2 {
location <- index = 0 ? {30, 17} : {50, 17};
}
loop i from: 0 to: 1 {
point anchor <- wheel[i].location;
motors << create_wheel_joint(chassis[0], wheel[i], anchor, {0, 1, 0}, 4.0, 0.7, -8.0, 200.0);
}
create trailer {
location <- {10, 25};
}
joint tow <- create_rope_joint(chassis[0], trailer[0], {32, 25}, {16, 25}, 12.0);
create load {
location <- {40, 40};
}
joint spring <- create_distance_joint(chassis[0], load[0], {40, 28}, {40, 38}, 2.0, 0.3);
}

reflex report when: every(60 #cycle) {
write "wheel translation: " + motors[0].translation with_precision 2;
}
}

species ground skills: [static_body] {
geometry shape <- box(300, 10, 0.1);

aspect default {
draw shape color: #gray;
}
}

species chassis skills: [dynamic_body] {
geometry shape <- box(30, 6, 0.1);
float mass <- 5.0;

aspect default {
draw shape color: #firebrick rotate: float(rotation.key);
}
}

species wheel skills: [dynamic_body] {
geometry shape <- circle(5);
float mass <- 1.0;
float friction <- 1.0;

aspect default {
draw shape color: #black;
}
}

species trailer skills: [dynamic_body] {
geometry shape <- box(14, 4, 0.1);
float mass <- 1.0;

aspect default {
draw shape color: #steelblue rotate: float(rotation.key);
}
}

species load skills: [dynamic_body] {
geometry shape <- circle(2);
float mass <- 0.5;

aspect default {
draw shape color: #gold;
}
}

experiment "Box2D Wheel Car" type: gui {
output {
display Car type: 2d axes: false {
species ground;
species chassis;
species wheel;
species trailer;
species load;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* A tentacle made of boxes linked by cone-twist joints (ragdoll-style), anchored to a fixed base
* with a fixed joint, and swung around by an initial push. Runs on native Bullet when available.
*/
model Bullet_ConeTwist_Tentacle

global parent: physical_world {
string library <- "bullet";
bool use_native <- true;
int segment_count <- 8;
float segment_length <- 10.0;
geometry shape <- box(160, 80, 80);
point gravity <- {0, 0, -9.81};

init {
do register([self]);
create tentacle_base {
location <- {30, 40, 60};
}
create tentacle_segment number: segment_count;
ask tentacle_segment {
location <- {30 + (index + 1) * segment_length, 40, 60};
}
joint root <- create_fixed_joint(tentacle_base[0], tentacle_segment[0], {30 + segment_length / 2, 40, 60});
loop i from: 0 to: segment_count - 2 {
point anchor <- {30 + (i + 1.5) * segment_length, 40, 60};
joint j <- create_cone_twist_joint(tentacle_segment[i], tentacle_segment[i + 1], anchor, {1, 0, 0}, 0.5, 0.3);
}
}
}

species tentacle_base skills: [static_body] {
geometry shape <- box(10, 10, 10);

aspect default {
draw shape color: #darkgray;
}
}

species tentacle_segment skills: [dynamic_body] {
geometry shape <- box(10, 4, 4);
float mass <- 0.5;
float friction <- 0.4;

aspect default {
draw shape color: rgb(255, 120 + index * 15, 60) rotate: float(rotation.key);
}
}

experiment Tentacle type: gui {
output {
display Tentacle type: 3d {
graphics "World" {
draw shape color: #white wireframe: true;
}
species tentacle_base;
species tentacle_segment;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* A simple articulated chain driven by hinge motors.
*/
model Jointed_Snake

global parent: physical_world {
string library <- "bullet";
bool use_native <- true;
int segment_count <- 8;
float segment_length <- 16.0;
list<joint> joints <- [];
geometry shape <- box(160, 80, 40);
point gravity <- {0, 0, 0};

init {
do register([self]);
create snake_segment number: segment_count;
ask snake_segment {
location <- {30 + index * segment_length, 40, 20};
}
loop i from: 0 to: segment_count - 2 {
point anchor <- {30 + (i + 1) * segment_length - segment_length / 2, 40, 20};
joints << create_hinge_joint_with_axis(snake_segment[i], snake_segment[i + 1], anchor, {0, 0, 1},
-0.6, 0.6, 0.0, 8.0);
}
}

reflex drive_joints {
loop i from: 0 to: length(joints) - 1 {
joints[i].motorSpeed <- 1.2 * sin(cycle * 8 + i * 45);
}
}
}

species snake_segment skills: [dynamic_body] {
geometry shape <- box(16, 5, 5);
float mass <- 1.0;
float friction <- 0.4;

aspect default {
draw shape color: #orange rotate: float(rotation.key);
}
}

experiment Snake type: gui {
output {
display Snake type: 3d {
graphics "World" {
draw shape color: #white;
}
species snake_segment;
}
}
}
Loading
Loading