Skip to content

Commit f402b7f

Browse files
committed
将相机初始化分开,并发现不能同时打开两个相机的bug
1 parent 4d643c1 commit f402b7f

File tree

4 files changed

+47
-25
lines changed

4 files changed

+47
-25
lines changed

include/D5Robot.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class D5Robot {
4040
~D5Robot();
4141
void InitNator(std::string natorID = NatorId);
4242
void InitRMD(const char *portName, uint8_t topRMDID = 1, uint8_t botRMDID = 2);
43-
void InitCamera(std::string topCameraId = TopCameraId, std::string botCameraId = BotCameraId);
43+
void InitTopCamera(std::string topCameraId = TopCameraId);
44+
void InitBotCamera(std::string botCameraId = BotCameraId);
4445
void SetZero();
4546
void Stop();
4647
void JointsMoveAbsolute(const Joints j);

src/D5Robot.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ D5Robot::D5Robot(
2525
std::string topCameraID) {
2626
InitNator(natorID);
2727
InitRMD(serialPort, topRMDID, botRMDID);
28-
InitCamera(topCameraID);
28+
// InitCamera(topCameraID);
2929
}
3030
D5Robot::~D5Robot() {
3131
if (topCamera != nullptr) {
@@ -58,8 +58,11 @@ void D5Robot::InitRMD(const char *portName, uint8_t topRMDID, uint8_t botRMDID)
5858
botRMDMotor = new RMDMotor(_port->GetHandle(), botRMDID);
5959
}
6060

61-
void D5Robot::InitCamera(std::string topCameraId, std::string botCameraId) {
61+
void D5Robot::InitTopCamera(std::string topCameraId) {
6262
topCamera = new CameraTop(topCameraId);
63+
}
64+
65+
void D5Robot::InitBotCamera(std::string botCameraId) {
6366
botCamera = new CameraBot(botCameraId);
6467
}
6568

test.cpp

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,37 @@ int main() {
1818
// D5R::D5Robot robot(port.c_str());
1919
D5R::D5Robot robot;
2020

21-
// try {
22-
// robot.InitNator();
23-
// } catch (D5R::RobotException &e) {
24-
// std::cout << e.what() << std::endl;
25-
// }
26-
27-
// try {
28-
// robot.InitRMD(port.c_str());
29-
// } catch (D5R::RobotException &e) {
30-
// std::cout << e.what() << std::endl;
31-
// }
32-
3321
try {
34-
robot.InitRMD(port.c_str());
22+
robot.InitNator();
3523
} catch (D5R::RobotException &e) {
3624
std::cout << e.what() << std::endl;
3725
}
3826

3927
try {
40-
robot.InitCamera();
28+
robot.InitRMD(port.c_str());
4129
} catch (D5R::RobotException &e) {
4230
std::cout << e.what() << std::endl;
4331
}
32+
4433
// try {
45-
// robot.InitCamera();
34+
// robot.InitTopCamera();
4635
// } catch (D5R::RobotException &e) {
4736
// std::cout << e.what() << std::endl;
4837
// }
4938

50-
// robot.JointsMoveAbsolute({300, 4000000, 5000000, -10000000, 0});
39+
try {
40+
robot.InitBotCamera();
41+
} catch (D5R::RobotException &e) {
42+
std::cout << e.what() << std::endl;
43+
}
44+
45+
// robot.JointsMoveAbsolute({0, 0, 10000000, 0, 0});
46+
// robot.Stop();
47+
// robot.topRMDMotor->GoAngleAbsolute(-17700);
48+
// robot.topRMDMotor->SetZero();
49+
// robot.Stop();
50+
// robot.Stop();
51+
// robot.SetZero();
5152
// robot.JointsMoveAbsolute({300, -3650000, 1800000, -10000000, 0}); // 别动
5253

5354
// robot.Stop();
@@ -80,22 +81,40 @@ int main() {
8081
// cv::waitKey(0);
8182

8283
// 测试相机
83-
cv::Mat img;
84+
cv::Mat img_top;
8485
std::string winname = "test";
8586
cv::namedWindow(winname, cv::WINDOW_NORMAL);
8687
cv::resizeWindow(winname, cv::Size(1295, 1024));
8788
int count = 0;
88-
while (robot.topCamera->Read(img)) {
89+
// while (robot.topCamera->Read(img_top)) {
90+
91+
// cv::imshow(winname, img_top);
92+
// if (cv::waitKey(1) == 27) {
93+
// break;
94+
// }
95+
// if (cv::waitKey(1) == 32) {
96+
// // robot.topCamera.GetMapParam(img_top);
97+
// std::string filename =
98+
// "../image/11_24/topC_clamp_rang_" + std::to_string(count++) + ".png";
99+
// cv::imwrite(filename, img_top);
100+
// // std::cout << count++ << std::endl;
101+
// continue;
102+
// }
103+
// }
104+
// cv::waitKey(0);
105+
cv::Mat img_bot;
106+
count = 0;
107+
while (robot.botCamera->Read(img_bot)) {
89108

90-
cv::imshow(winname, img);
109+
cv::imshow(winname, img_bot);
91110
if (cv::waitKey(1) == 27) {
92111
break;
93112
}
94113
if (cv::waitKey(1) == 32) {
95-
// robot.topCamera.GetMapParam(img);
114+
// robot.topCamera.GetMapParam(img_bot);
96115
std::string filename =
97116
"../image/11_24/topC_clamp_rang_" + std::to_string(count++) + ".png";
98-
cv::imwrite(filename, img);
117+
cv::imwrite(filename, img_bot);
99118
// std::cout << count++ << std::endl;
100119
continue;
101120
}

todolist.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
调试dev代码
2-
设置电机旋转零点
32
获取bot相机的视图,主要是钳口库的,更改直线获取函数
43

54

0 commit comments

Comments
 (0)