這裏的小社區,但希望有人看到這一點。我正在嘗試爲E-puck做一個純粹的C++實現。 C++文檔非常缺乏,而且我似乎無法找到解決此問題的辦法(C實現非常好,但所有函數調用都針對C++進行了更改)。在Webots C++中將速度設置爲DifferentialWheels的問題
基本上,我只是試圖讓一個簡單的應用程序運行起來......我想讓電子冰球前進。我會在下面發佈我的代碼的全部內容......我所做的只是實例化一個Robot實體,打印出所有IR傳感器值,並嘗試向前移動它。
問題是它不會移動。我認爲會有一些電話將DifferentialWheel對象連接到E-puck(類似於camera = getCamera("camera")
調用)。
如果我將我的電話註釋到setSpeed,程序完美工作(不移動,但打印值)。如果我放下它,一旦它接到該呼叫,模擬會在一步之後凍結。說實話,我不確定我做錯了什麼。現在
// webots
#include <webots/Robot.hpp>
#include <webots/Camera.hpp>
#include <webots/DistanceSensor.hpp>
#include <webots/DifferentialWheels.hpp>
#include <webots/LED.hpp>
// standard
#include <iostream>
using namespace webots;
#define TIME_STEP 16
class MyRobot : public Robot
{
private:
Camera *camera;
DistanceSensor *distanceSensors[8];
LED *leds[8];
DifferentialWheels *diffWheels;
public:
MyRobot() : Robot()
{
// camera
camera = getCamera("camera");
// sensors
distanceSensors[0] = getDistanceSensor("ps0");
distanceSensors[1] = getDistanceSensor("ps1");
distanceSensors[2] = getDistanceSensor("ps2");
distanceSensors[3] = getDistanceSensor("ps3");
distanceSensors[4] = getDistanceSensor("ps4");
distanceSensors[5] = getDistanceSensor("ps5");
distanceSensors[6] = getDistanceSensor("ps6");
distanceSensors[7] = getDistanceSensor("ps7");
for (unsigned int i = 0; i < 8; ++i)
distanceSensors[i]->enable(TIME_STEP);
// leds
leds[0] = getLED("led0");
leds[1] = getLED("led1");
leds[2] = getLED("led2");
leds[3] = getLED("led3");
leds[4] = getLED("led4");
leds[5] = getLED("led5");
leds[6] = getLED("led6");
leds[7] = getLED("led7");
}
virtual ~MyRobot()
{
// cleanup
}
void run()
{
double speed[2] = {20.0, 0.0};
// main loop
while (step(TIME_STEP) != -1)
{
// read sensor values
for (unsigned int i = 0; i < 8; ++i)
std::cout << " [" << distanceSensors[i]->getValue() << "]";
std::cout << std::endl;
// process data
// send actuator commands
// this call kills the simulation
// diffWheels->setSpeed(1000, 1000);
}
}
};
int main(int argc, char* argv[])
{
MyRobot *robot = new MyRobot();
robot->run();
delete robot;
return 0;
}
,如果這是C語言實現,我會打電話wb_differential_wheels_set_speed(1000, 1000);
然而,這一呼籲是不是在C++頭文件可用。
那......會做。謝謝! – espais 2012-08-10 00:53:37