機(jī)器人工程專業(yè)實(shí)踐鏡像2021版-功能擴(kuò)展-coppeliasim+webots

      網(wǎng)友投稿 1013 2022-05-29

      鏡像雖然提供了大部分課程所需功能,但同樣支持?jǐn)U展。這里以兩款仿真軟件為例

      coppeliasim

      webots

      其實(shí)就是在官網(wǎng)下載,解壓到硬盤(pán)就可以使用的。

      分別解壓就行。

      啟動(dòng)V-Rep(新版為coppeliasim) :

      ./vrep.sh

      啟動(dòng)webots:

      ./webots

      等待啟動(dòng)完成,即可愉快玩耍。忽略更新。

      缺少的功能包依據(jù)上學(xué)期課程講解,或者依據(jù)提示補(bǔ)充安裝即可。

      現(xiàn)在打開(kāi)一個(gè)cpp案例:

      嘗試一下編譯:

      完全可以正常使用。

      void Driver::displayHelp() {

      string s("Commands:\n"

      " 這只是一個(gè)測(cè)試^_^\n"

      " I for displaying the commands\n"

      " A for avoid obstacles\n"

      " F for move forward\n"

      " S for stop\n"

      " T for turn\n"

      " R for positioning ROBOT1 at (0.1,0.3)\n"

      " G for knowing the (x,z) position of ROBOT1");

      cout << s << endl;

      }

      webots中C++的案例都可以直接編譯后使用,非常方便。

      更多案例自主學(xué)習(xí)即可。

      // Copyright 1996-2020 Cyberbotics Ltd.

      //

      // Licensed under the Apache License, Version 2.0 (the "License");

      // you may not use this file except in compliance with the License.

      // You may obtain a copy of the License at

      //

      // http://www.apache.org/licenses/LICENSE-2.0

      //

      // Unless required by applicable law or agreed to in writing, software

      // distributed under the License is distributed on an "AS IS" BASIS,

      // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

      // See the License for the specific language governing permissions and

      // limitations under the License.

      /*

      * Description: This controller gives to its node the following behavior:

      * Listen the keyboard. According to the pressed key, send a

      * message through an emitter or handle the position of Robot1

      */

      #include

      #include

      #include

      #include

      #include

      #include

      #include

      #include

      #include

      using namespace std;

      using namespace webots;

      class Driver : public Supervisor {

      public:

      Driver();

      void run();

      private:

      static void displayHelp();

      int timeStep;

      Emitter *emitter;

      Field *translationField;

      Keyboard *keyboard;

      double x;

      double z;

      double translation[3];

      };

      Driver::Driver() {

      timeStep = 128;

      x = 0.1f;

      z = 0.3f;

      translation[0] = x;

      translation[1] = 0;

      translation[2] = z;

      emitter = getEmitter("emitter");

      Node *robot = getFromDef("ROBOT1");

      if (!robot)

      // robot might be NULL if the controller is about to quit

      exit(1);

      translationField = robot->getField("translation");

      keyboard = getKeyboard();

      keyboard->enable(timeStep);

      }

      void Driver::run() {

      string previous_message("");

      string message("");

      displayHelp();

      // main loop

      while (step(timeStep) != -1) {

      // Read sensors; update message according to the pressed keyboard key

      int k = keyboard->getKey();

      switch (k) {

      case 'A':

      message.assign("avoid obstacles");

      break;

      case 'F':

      message.assign("move forward");

      break;

      case 'S':

      message.assign("stop");

      break;

      case 'T':

      message.assign("turn");

      break;

      case 'I':

      displayHelp();

      break;

      case 'G': {

      const double *translationValues = translationField->getSFVec3f();

      cout << "ROBOT1 is located at (" << translationValues[0] << "," << translationValues[2] << ")" << endl;

      break;

      }

      case 'R':

      cout << "Teleport ROBOT1 at (" << x << "," << z << ")" << endl;

      translationField->setSFVec3f(translation);

      break;

      default:

      message.clear();

      }

      // send actuators commands; send a new message through the emitter device

      if (!message.empty() && message.compare(previous_message)) {

      previous_message.assign(message);

      cout << "Please, " << message.c_str() << endl;

      emitter->send(message.c_str(), (int)strlen(message.c_str()) + 1);

      }

      }

      }

      void Driver::displayHelp() {

      string s("Commands:\n"

      " 這只是一個(gè)測(cè)試^_^\n"

      " I for displaying the commands\n"

      " A for avoid obstacles\n"

      " F for move forward\n"

      " S for stop\n"

      " T for turn\n"

      " R for positioning ROBOT1 at (0.1,0.3)\n"

      " G for knowing the (x,z) position of ROBOT1");

      cout << s << endl;

      }

      int main() {

      Driver *controller = new Driver();

      controller->run();

      delete controller;

      return 0;

      }

      // Copyright 1996-2020 Cyberbotics Ltd.

      //

      // Licensed under the Apache License, Version 2.0 (the "License");

      // you may not use this file except in compliance with the License.

      // You may obtain a copy of the License at

      //

      // http://www.apache.org/licenses/LICENSE-2.0

      //

      // Unless required by applicable law or agreed to in writing, software

      // distributed under the License is distributed on an "AS IS" BASIS,

      // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

      // See the License for the specific language governing permissions and

      // limitations under the License.

      /*

      * Description: This controller gives to its robot the following behavior:

      * According to the messages it receives, the robot change its

      * behavior.

      */

      #include

      #include

      #include

      #include

      #include

      #include

      #include

      #include

      #include

      #include

      using namespace std;

      using namespace webots;

      static const double maxSpeed = 10.0;

      class Slave : public Robot {

      public:

      Slave();

      void run();

      private:

      enum Mode { STOP, MOVE_FORWARD, AVOID_OBSTACLES, TURN };

      static double boundSpeed(double speed);

      int timeStep;

      Mode mode;

      Receiver *receiver;

      Camera *camera;

      DistanceSensor *distanceSensors[2];

      Motor *motors[2];

      };

      Slave::Slave() {

      timeStep = 32;

      mode = AVOID_OBSTACLES;

      camera = getCamera("camera");

      camera->enable(4 * timeStep);

      receiver = getReceiver("receiver");

      receiver->enable(timeStep);

      motors[0] = getMotor("left wheel motor");

      motors[1] = getMotor("right wheel motor");

      motors[0]->setPosition(std::numeric_limits::infinity());

      motors[1]->setPosition(std::numeric_limits::infinity());

      motors[0]->setVelocity(0.0);

      motors[1]->setVelocity(0.0);

      string distanceSensorNames("ds0");

      for (int i = 0; i < 2; i++) {

      distanceSensors[i] = getDistanceSensor(distanceSensorNames);

      distanceSensors[i]->enable(timeStep);

      distanceSensorNames[2]++; // for getting "ds1","ds2",...

      }

      }

      double Slave::boundSpeed(double speed) {

      return std::min(maxSpeed, std::max(-maxSpeed, speed));

      }

      void Slave::run() {

      // main loop

      while (step(timeStep) != -1) {

      // Read sensors, particularly the order of the supervisor

      if (receiver->getQueueLength() > 0) {

      string message((const char *)receiver->getData());

      receiver->nextPacket();

      cout << "I should " << AnsiCodes::RED_FOREGROUND << message << AnsiCodes::RESET << "!" << endl;

      if (message.compare("avoid obstacles") == 0)

      mode = AVOID_OBSTACLES;

      else if (message.compare("move forward") == 0)

      mode = MOVE_FORWARD;

      else if (message.compare("stop") == 0)

      mode = STOP;

      else if (message.compare("turn") == 0)

      mode = TURN;

      }

      機(jī)器人工程專業(yè)實(shí)踐鏡像2021版-功能擴(kuò)展-coppeliasim+webots

      double delta = distanceSensors[0]->getValue() - distanceSensors[1]->getValue();

      double speeds[2] = {0.0, 0.0};

      // send actuators commands according to the mode

      switch (mode) {

      case AVOID_OBSTACLES:

      speeds[0] = boundSpeed(maxSpeed / 2.0 + 0.1 * delta);

      speeds[1] = boundSpeed(maxSpeed / 2.0 - 0.1 * delta);

      break;

      case MOVE_FORWARD:

      speeds[0] = maxSpeed;

      speeds[1] = maxSpeed;

      break;

      case TURN:

      speeds[0] = maxSpeed / 2.0;

      speeds[1] = -maxSpeed / 2.0;

      break;

      default:

      break;

      }

      motors[0]->setVelocity(speeds[0]);

      motors[1]->setVelocity(speeds[1]);

      }

      }

      int main() {

      Slave *controller = new Slave();

      controller->run();

      delete controller;

      return 0;

      }

      -End-

      機(jī)器人 鏡像服務(wù)

      版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請(qǐng)聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時(shí)內(nèi)刪除侵權(quán)內(nèi)容。

      上一篇:TL6748-EVM開(kāi)發(fā)板介紹
      下一篇:【有獎(jiǎng)?wù)魑摹烤`放吧!花開(kāi)遇晨露,邂逅數(shù)據(jù)庫(kù)
      相關(guān)文章
      亚洲国产精华液网站w| 亚洲?v无码国产在丝袜线观看| 处破女第一次亚洲18分钟| 亚洲国产精品综合福利专区| 亚洲AV第一页国产精品| 亚洲乱码国产一区三区| 久久精品国产精品亚洲下载| 亚洲精品麻豆av| 亚洲一区视频在线播放| 亚洲一区二区三区乱码A| 亚洲AⅤ永久无码精品AA| 亚洲第一页日韩专区| 亚洲国产精品一区二区九九| 亚洲精品国产va在线观看蜜芽| 国产99久久亚洲综合精品| 一区国严二区亚洲三区| 另类小说亚洲色图| 亚洲黄黄黄网站在线观看| 亚洲一本大道无码av天堂| 国产成人综合亚洲AV第一页| 亚洲夜夜欢A∨一区二区三区| 亚洲日韩精品一区二区三区无码| 亚洲国产另类久久久精品黑人| 亚洲另类激情综合偷自拍图| 亚洲AV无码一区东京热| 久久亚洲私人国产精品vA| 亚洲精品视频免费在线观看| 亚洲国产av美女网站| 亚洲人成77777在线播放网站不卡| 亚洲综合一区二区三区四区五区| 亚洲欧美日韩一区二区三区| 久久久久亚洲AV无码去区首| 亚洲а∨天堂久久精品| 中文字幕专区在线亚洲| 亚洲成色WWW久久网站| 中文字幕亚洲综合精品一区| 亚洲一区二区久久| 国产亚洲精品bv在线观看| 亚洲va无码专区国产乱码| 久久亚洲综合色一区二区三区| 久久亚洲AV无码精品色午夜麻|