mirror of
https://github.com/wassname/metacar.git
synced 2026-09-11 12:20:12 +08:00
Update README.md
This commit is contained in:
@@ -81,18 +81,97 @@ You also have to create the container in your HTML file.
|
||||
<b>Wonderful! You just create your first metacar environement. </b> You can take sometime to play around with the key arrow to move the car. The current collision system support the detection of the following events:
|
||||
|
||||
* Collisions with other vehicles
|
||||
* Detection of the road, ground and road with the lidar
|
||||
* Detection of the vehicles, ground and road with the lidar
|
||||
* Detection of the car going out track
|
||||
|
||||
If you want to see add features to the detection system you can considere [contributing to the project](#link) :)
|
||||
|
||||
If you want to add new features to the detection system you can considere [contributing to the project](#link) :)
|
||||
|
||||
<a id='interact-env'></a>
|
||||
Interact with the environement
|
||||
------------
|
||||
|
||||
#### Create your first event
|
||||
#### Train your agent
|
||||
### Action space
|
||||
|
||||
By default the environement comes with a simple motion engine ([How to change the motion engine ?](#link)) who let you control the car with the arrow. Then, the actions are either UP, LEFT, RIGHT, DOWN, WAIT. Once the environement is loaded you can take a look at the action space.
|
||||
|
||||
```javascript
|
||||
env.load(() => {
|
||||
console.log(env.actionSpace());
|
||||
});
|
||||
```
|
||||
|
||||
```
|
||||
{
|
||||
type: "Discrete", // The number is discrete
|
||||
size: 1, // Only one number is expected
|
||||
range: [0, 1, 2, 3, 4] // The action can be either 0, 1, 2, 3 or 4
|
||||
}
|
||||
```
|
||||
|
||||
### Play & Stop
|
||||
|
||||
Let's suppose your agent is already trained to move forward whatever happens (Fortunately we are in a simulation). Then you want might want to test it in real time to see the result.
|
||||
|
||||
The quickest way to do so is to simply ask the environement to call a given function at each lopp run.
|
||||
|
||||
```javascript
|
||||
env.load().then(() => {
|
||||
|
||||
env.addEvent("play", () => {
|
||||
// Move forward
|
||||
const reward = env.step(0);
|
||||
// Log the reward
|
||||
console.log(reward);
|
||||
});
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
You should see a <b>play</b> button on the screen. On click, the car will move forward and the reward should be positive as long as the car is on track, then negative when the car quit the road.<br>
|
||||
|
||||
To stop calling your fonction you cann add a stop button on the screen.
|
||||
|
||||
```javascript
|
||||
env.load().then(() => {
|
||||
|
||||
env.addEvent("play", () => {
|
||||
// Move forward
|
||||
const reward = env.step(0);
|
||||
// Log the reward
|
||||
console.log(reward);
|
||||
});
|
||||
|
||||
env.addEvent("stop", () => {
|
||||
console.log("The stop button have been pressed.");
|
||||
});
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
### Train your agent
|
||||
|
||||
During the training, the environement is not render on the screen anymore. Once you're training is finish you have to notify the environement by calling env.render(true) to render the environement again. <br>
|
||||
|
||||
The state of the environement is the the value of each lidar point. Of course, because the car still want to go forward it doesn't care about the value of the state :) <br>
|
||||
|
||||
Here is an example of basic training function.
|
||||
|
||||
```
|
||||
env.load().then(() => {
|
||||
|
||||
env.addEvent("train", () => {
|
||||
for (let s=0; s < 100; s++){
|
||||
// Get the current state of the lidar
|
||||
const state = env.getState();
|
||||
// Move forward
|
||||
const reward = env.step(0);
|
||||
}
|
||||
// Log the reward
|
||||
env.render(true);
|
||||
});
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
<a id='other-interact-env'></a>
|
||||
Other events
|
||||
|
||||
Reference in New Issue
Block a user