From adf94cb95a652dbd7636a9ae83fc3cdf69da69f9 Mon Sep 17 00:00:00 2001 From: utcoupe-dev rpi3-3 Date: Tue, 23 May 2017 20:34:01 +0000 Subject: [PATCH] Place robot working (pos bullshit) --- clients/asserv/asserv.js | 2 ++ clients/asserv/asserv.real.js | 13 ++++++++++--- clients/asserv/asserv.simu.js | 4 ++++ clients/robot/robot.js | 3 +++ ia/gr.class.js | 15 +++++++++++++++ ia/pr.class.js | 20 ++++++++++++++++++++ ia/robot.class.js | 6 ++++-- webclient/index.js | 3 +++ webclient/index.tpl.html | 2 ++ 9 files changed, 63 insertions(+), 5 deletions(-) diff --git a/clients/asserv/asserv.js b/clients/asserv/asserv.js index 8de71e3..e814130 100644 --- a/clients/asserv/asserv.js +++ b/clients/asserv/asserv.js @@ -134,6 +134,8 @@ class Asserv{ */ setPid(p, i, d){} + doStartSequence(params) {} + addOrderToFifo(name, params){ this.logger.debug("Adding order to fifo : " + name); // this.logger.debug(order.params); diff --git a/clients/asserv/asserv.real.js b/clients/asserv/asserv.real.js index 8953b5c..7d0b436 100644 --- a/clients/asserv/asserv.real.js +++ b/clients/asserv/asserv.real.js @@ -75,7 +75,9 @@ class AsservReal extends Asserv{ /********************************************************************/ setPos(pos) { - this.ordersSerial.sendOrder(this.asservCommands.SET_POS, [parseInt(pos.x), parseInt(pos.y), this.myWriteFloat(pos.a)], function() { this.fifo.orderFinished(); }.bind(this)); + if (!!this.ordersSerial) { + this.ordersSerial.sendOrder(this.asservCommands.SET_POS, [parseInt(pos.x), parseInt(pos.y), this.myWriteFloat(pos.a)], function() { this.fifo.orderFinished(); }.bind(this)); + } } clean(){ @@ -112,8 +114,8 @@ class AsservReal extends Asserv{ goxy(x, y, sens) { //todo sens in english var sensInt; - if(sens == "avant") sensInt = 1; - else if(sens == "arriere") sensInt = -1; + if(sens == "forward") sensInt = 1; + else if(sens == "backward") sensInt = -1; else sensInt = 0; this.ordersSerial.sendOrder(this.asservCommands.GOTO, [parseInt(x), parseInt(y), parseInt(sensInt)], function() { this.fifo.orderFinished(); }.bind(this)); } @@ -126,6 +128,11 @@ class AsservReal extends Asserv{ this.ordersSerial.sendOrder(this.asservCommands.PIDALL, [this.myWriteFloat(p), this.myWriteFloat(i), this.myWriteFloat(d)], function() { this.fifo.orderFinished(); }.bind(this)); } + doStartSequence(params){ + this.goxy(params.x, params.y, "forward"); + this.goa(params.a, () => {}); + } + /********************************************************************\ * * HELPERS FUNCTIONS diff --git a/clients/asserv/asserv.simu.js b/clients/asserv/asserv.simu.js index 322af6b..47311de 100644 --- a/clients/asserv/asserv.simu.js +++ b/clients/asserv/asserv.simu.js @@ -208,6 +208,10 @@ class AsservSimu extends Asserv{ this.fifo.orderFinished(); } + doStartSequence(params){ + this.fifo.orderFinished(); + } + simu_speed(speed, x, y, a, dt) { return function() { this.pos = { diff --git a/clients/robot/robot.js b/clients/robot/robot.js index 18f6e81..1271660 100644 --- a/clients/robot/robot.js +++ b/clients/robot/robot.js @@ -80,6 +80,9 @@ class Robot extends Client{ //this.acts.clean(); this.orderInProgress = false; break; + case "do_start_sequence": + this.asserv.doStartSequence(params); + break; case "stop": //TODO DO it with new actuators //this.acts.clean(); diff --git a/ia/gr.class.js b/ia/gr.class.js index 2ec5799..fa0bf93 100644 --- a/ia/gr.class.js +++ b/ia/gr.class.js @@ -36,6 +36,11 @@ class Gr extends Robot{ d: 390 }; + /** Initial position */ + if (this.ia.color == "blue") { + } else { + } + /** Initial position */ if (this.ia.color == "blue") { this.initialPos = { @@ -43,12 +48,22 @@ class Gr extends Robot{ y: 175, a: 0, } + this.startPos = { + x: 275, + y: 175, + a: 0, + } } else { this.initialPos = { x: 2825, y: 175, a: 3.1415, } + this.startPos = { + x: 2725, + y: 175, + a: 3.1415, + } } this.pos.x = this.initialPos.x; diff --git a/ia/pr.class.js b/ia/pr.class.js index 630fb45..55454a3 100644 --- a/ia/pr.class.js +++ b/ia/pr.class.js @@ -43,6 +43,26 @@ class Pr extends Robot{ y: 175, a: 1.5707, } + this.startPos = { + x: 900, + y: 175, + a: 0, + } + } else { + this.initialPos = { + x: 2100, + y: 175, + a: 1.5707, + } + this.startPos = { + x: 2100, + y: 175, + a: 3.1415, + } + } + + /** Place position */ + if (this.ia.color == "blue") { } else { this.initialPos = { x: 2100, diff --git a/ia/robot.class.js b/ia/robot.class.js index cfac3f3..3cccb57 100644 --- a/ia/robot.class.js +++ b/ia/robot.class.js @@ -65,6 +65,8 @@ class Robot{ /** Robot actions */ this.actions = null; this.Actions = require('./actions.class.js'); + + this.startPos = this.initialPos; } /** @@ -178,9 +180,9 @@ class Robot{ * Place robot before starting the match */ place () { - this.ia.client.send(this.name, "asserv.setpos", this.initialPos); + this.sendInitialPos () - this.ia.client.send(this.name, "do_start_sequence", {}); + this.ia.client.send(this.name, "do_start_sequence", this.startPos); } /** diff --git a/webclient/index.js b/webclient/index.js index 09f0cae..78c35ec 100644 --- a/webclient/index.js +++ b/webclient/index.js @@ -39,6 +39,9 @@ angular.module('app').controller('IndexCtrl', ['$rootScope', '$scope', 'UTCoupe' $scope.stop = function(u) { Client.send(u, 'stop'); }; + $scope.place = function(u) { + Client.send("ia", u + '.place'); + }; $scope.jack = function() { Client.send('ia', 'ia.jack', {}); diff --git a/webclient/index.tpl.html b/webclient/index.tpl.html index 7b4e491..45aa578 100644 --- a/webclient/index.tpl.html +++ b/webclient/index.tpl.html @@ -52,6 +52,7 @@ +

@@ -61,6 +62,7 @@ +