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

Add multiplier support for web protos #5756

Merged
merged 10 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
4 changes: 2 additions & 2 deletions projects/robots/a4/portal/protos/Portal.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#VRML_SIM R2023b utf8
# license: Copyright Cyberbotics Ltd. Licensed for use only with Webots.
# license url: https://cyberbotics.com/webots_assets_license
# documentation url: https://www.cyberbotics.com/doc/guide/portal
# documentation url: https://proto.webots.cloud/run?url=https://github.com/cyberbotics/webots/blob/released/projects/robots/a4/portal/protos/Portal.proto
# Portal PICAXE-28X2 (A4 TECHNOLOGIE)
# This small portal model is used for education with PICAXE programming tools

Expand Down Expand Up @@ -314,7 +314,7 @@ PROTO Portal [
}
DEF GEAR_JOINT HingeJoint {
jointParameters HingeJointParameters {
position 0.12
position 1,2
BenjaminDeleze marked this conversation as resolved.
Show resolved Hide resolved
axis 0 0 1
anchor -0.0058 0.057 0.012
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions projects/robots/a4/portal/protos/docs/portal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
The [A4 Portal](http://www.a4.fr/automatisme-et-robotique/maquettes-automatisees/portail-coulissant-automatise.html) is a sliding portal designed for teaching automatized systems.
It uses the PICAXE programming kit.

### Movie Presentation

![youtube video](https://www.youtube.com/watch?v=vBS7t1eQINs)

### Portal PROTO

Derived from [Robot](https://cyberbotics.com/doc/reference/robot).

```
Portal {
SFVec3f translation 0 0 0
SFRotation rotation 0 0 1 0
SFString name "Portal"
SFString controller "<generic>"
MFString controllerArgs []
SFString customData ""
SFBool supervisor FALSE
SFBool synchronization TRUE
MFNode extensionSlot []
}
```

#### Portal Field Summary

- `extensionSlot`: Extends the robot with new nodes in the extension slot.

### Samples

You will find the following sample in this folder: "WEBOTS\_HOME/projects/robots/a4/portal/worlds".

#### portal\_pe.wbt

![portal_pe.wbt.png](images/portal/portal_pe.wbt.thumbnail.jpg) This simulation shows the portal model.
1 change: 1 addition & 0 deletions projects/robots/a4/portal/webots.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
publish: true
14 changes: 8 additions & 6 deletions resources/web/wwi/FloatingProtoParameterWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -1505,11 +1505,11 @@ export default class FloatingProtoParameterWindow extends FloatingWindow {

div.appendChild(this.#createJointInfo(jointType, endPointName, joint.device));
const parameters = joint.jointParameters;
this.#createSlider(parameters, joint.device, div, _ => {
this.#createSlider(parameters, joint.device, div, value => {
if (parameters)
parameters.position = _.target.value;
parameters.position = value;
else
joint.position = _.target.value;
joint.position = value;
this.#view.x3dScene.render();
});

Expand Down Expand Up @@ -1709,14 +1709,15 @@ export default class FloatingProtoParameterWindow extends FloatingWindow {

slider.addEventListener('input', _ => {
if (typeof callback === 'function')
callback(_);
callback(_.target.value);

if (slider.motorName?.includes('::')) {
const coupledMotorName = slider.motorName.split('::')[0];
for (let i = 0; i < this.coupledSlidersList.length; i++) {
if (this.coupledSlidersList[i].motorName.startsWith(coupledMotorName)) {
this.coupledSlidersList[i].value = slider.value;
this.coupledSlidersList[i].callback(_);
const newValue = slider.value * this.coupledSlidersList[i].multiplier / slider.multiplier;
this.coupledSlidersList[i].value = newValue;
this.coupledSlidersList[i].callback(newValue);
}
}
}
Expand All @@ -1730,6 +1731,7 @@ export default class FloatingProtoParameterWindow extends FloatingWindow {
if (motor.deviceName.includes('::')) {
slider.motorName = motor.deviceName;
slider.callback = callback;
slider.multiplier = motor.multiplier;

this.coupledSlidersList.push(slider);
}
Expand Down
5 changes: 3 additions & 2 deletions resources/web/wwi/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,10 +869,11 @@ export default class Parser {
else if (node.tagName === 'RotationalMotor' || node.tagName === 'LinearMotor') {
const minPosition = parseFloat(getNodeAttribute(node, 'minPosition', '0'));
const maxPosition = parseFloat(getNodeAttribute(node, 'maxPosition', '0'));
const multiplier = parseFloat(getNodeAttribute(node, 'multiplier', '1'));
if (node.tagName === 'RotationalMotor')
logicalDevice = new WbRotationalMotor(id, name, minPosition, maxPosition);
logicalDevice = new WbRotationalMotor(id, name, minPosition, maxPosition, multiplier);
else
logicalDevice = new WbLinearMotor(id, name, minPosition, maxPosition);
logicalDevice = new WbLinearMotor(id, name, minPosition, maxPosition, multiplier);
}

WbWorld.instance.nodes.set(logicalDevice.id, logicalDevice);
Expand Down
8 changes: 7 additions & 1 deletion resources/web/wwi/nodes/WbMotor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import WbLogicalDevice from './WbLogicalDevice.js';
export default class WbMotor extends WbLogicalDevice {
#minPosition;
#maxPosition;
constructor(id, deviceName, minPosition, maxPosition) {
#multiplier;
constructor(id, deviceName, minPosition, maxPosition, multiplier) {
super(id, deviceName);
this.#minPosition = minPosition;
this.#maxPosition = maxPosition;
this.#multiplier = multiplier;
}

get minPosition() {
Expand All @@ -16,4 +18,8 @@ export default class WbMotor extends WbLogicalDevice {
get maxPosition() {
return this.#maxPosition;
}

get multiplier() {
return this.#multiplier;
}
}