Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Part 2 robot simulator #309

Merged

Conversation

JoelChanZhiYang
Copy link
Contributor

@JoelChanZhiYang JoelChanZhiYang commented Apr 15, 2024

Description

The EV3 robot simulator implementation is in PR. This looks like a big PR but about half of it is tests.

image

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

There is 119 tests to test the main aspects of the robot simulation.

image

To try out the robot simulation. You can try out this snippet.

In this snippet, you will observe

  • Wheels
  • Motors
  • Paper and url loading
  • Ultrasonic sensor
  • ev3_pause
  • Floor and Wall
import {
  ev3_motorA,
  ev3_motorB,
  ev3_motorC,
  ev3_motorD,
  ev3_runToRelativePosition,
  ev3_colorSensorRed,
  ev3_colorSensorGreen,
  ev3_pause,
  ev3_colorSensorBlue,
  ev3_ultrasonicSensor,
  ev3_ultrasonicSensorDistance,
  init_simulation,
  createRenderer,
  createPhysics,
  createTimer,
  createWorld,
  createPaper,
  createWall,
  createEv3,
  createFloor,
  createCSE,
  createRobotConsole,
  addControllerToWorld,
  saveToContext
} from "robot_simulation";


init_simulation(() => {
    const physics = createPhysics();
    const renderer = createRenderer();
    const timer = createTimer();
    const robot_console = createRobotConsole();
    
    const world = createWorld(physics, renderer, timer, robot_console);
    
    const program = createCSE();
    addControllerToWorld(program, world);
    
    const paper = createPaper(
        renderer, 
        "https://www.shutterstock.com/image-vector/black-white-stripes-260nw-785326606.jpg", 
        1, 
        1);
        
    addControllerToWorld(paper, world);
    
    const floor = createFloor(physics, renderer);
    addControllerToWorld(floor, world);
    
    const wall = createWall(physics, renderer);
    addControllerToWorld(wall, world);
    
    const ev3 = createEv3(physics, renderer);
    addControllerToWorld(ev3, world);
    
    saveToContext("world", world);
    saveToContext("ev3", ev3);
    
    return world;
});

// Student code below

let motorA = ev3_motorA();
let motorB = ev3_motorB();
let ultrasonicSensor = ev3_ultrasonicSensor();

ev3_pause(2000);

let loop = true;

while (loop) {
    let distance = ev3_ultrasonicSensorDistance(ultrasonicSensor);
    
    if (distance < 50) {
        loop = false;
        continue;
    }
    
    ev3_runToRelativePosition(motorA, 360, 200);
    ev3_runToRelativePosition(motorB, 360, 200);
    ev3_pause(3000);
}

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@JoelChanZhiYang JoelChanZhiYang marked this pull request as ready for review April 15, 2024 02:34
Copy link
Member

@RichDom2185 RichDom2185 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for working on this! Very excited to try it out; have not looked through all the files but in the meantime, here are some preliminary comments:

Copy link
Member

@RichDom2185 RichDom2185 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, sorry for the delayed review, thanks a lot for working on this! LGTM, though I just have a few minor comments; would kindly ask if you could reply to them.

Thanks and it looks really good too! 🤩

};

export const meshConfig: Ev3MeshConfig = {
url: 'https://keen-longma-3c1be1.netlify.app/6_remove_wheels.gltf',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we going to eventually move this into a/the repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! Sorry for the slow reply!

How do other modules host their static files? Is it inside the modules repo or in a separate repo?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far I think the only other module with static assets is unity academy, and we host the files in an S3 bucket on AWS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah alright. How do I go about to do that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's take this over to Telegram.

height: 0.0575,
length: 0.0575,
},
url: 'https://keen-longma-3c1be1.netlify.app/6_wheel.gltf',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.


// steps per tick
for (let i = 0; i < this.config.stepsPerTick; i++) {
const result = this.iterator.next();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this unused variable intentional?

@RichDom2185 RichDom2185 enabled auto-merge (squash) April 24, 2024 14:28
@RichDom2185 RichDom2185 merged commit 75efcf9 into source-academy:master Apr 24, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants