Question
Asked 12th Apr, 2015
  • Faculty of Electronic Engineering Menouf - Menoufia University

Can anyone help with sending each value in a vector to a robot not only the last value in C++?

For C++ Experts
==============
I have two vectors vx and w saved in a text file with size of (3000)
- I have read those two text files and generate two vectors
- I will use each value in those two vectors to send a command to a robot using these commands
robot.setVel(*i);
robot.setRotVel(*j);
As shown in the Figure
However
=======
The Program use the last value only in the two vectors
Can any one help to send each value in the vectors to the robot.?

Most recent answer

15th Apr, 2015
Shawn M. Freeman
Weather Source
The robot IS responding to all the commands. The problem here is that your code does nothing to wait for a response. Your overwriting commands faster than the robot can respond to them. The only reason why the last command appears to work is because you're not overwriting it after it's submitted.
To verify this, add a time delay in the loop of a few seconds. This should be plenty of time for the robot to respond to each command.
Ideally you'd establish a callback or a response handler so that each command wouldn't trigger until the previous command is complete.
6 Recommendations

Popular answers (1)

15th Apr, 2015
Shawn M. Freeman
Weather Source
The robot IS responding to all the commands. The problem here is that your code does nothing to wait for a response. Your overwriting commands faster than the robot can respond to them. The only reason why the last command appears to work is because you're not overwriting it after it's submitted.
To verify this, add a time delay in the loop of a few seconds. This should be plenty of time for the robot to respond to each command.
Ideally you'd establish a callback or a response handler so that each command wouldn't trigger until the previous command is complete.
6 Recommendations

All Answers (6)

12th Apr, 2015
Rashid AL Marri
Multimedia University
it depends on how did you format the data in the text file, I suggest you to try printing "val" instead of pushing it back. if it's printing the same value (last value) every time means (>>) operation may not read your data format. Moreover, data which come thru TXT file would be strings, so you will need to convert it as doubles before assign it to double variable or pushing it back in a double vector.
2 Recommendations
12th Apr, 2015
Amine Hadj-Abdelkader
Abou Bakr Belkaid University of Tlemcen
Does it print the right values when you uncomment the lines std::cout<<*i<<std::endl; or only the last ones in the vectors ?
I agree with Rashid that the values coming from the TXT file would be strings.  
2 Recommendations
The operator>> will do the conversion to double as expected. However, should something be wrong with your input, the tests in your loops will simply fail and fall through to the next line. So, you may not actually read the whole vector if there is something wrong with the input file. 
But, you are not using the vector. By using the dereferenced iterator *i, you are actually just sending the component doubles one at a time to the function. Without seeing the "robot" functions you are calling it is not clear why you are only seeing the last value, but, if you are able to change their prototype, you probably want to pass the vector<double> instead of the individual doubles. Something like
void Robot::setVel(const std::vector<double>&);
for class Robot
1 Recommendation
14th Apr, 2015
Haitham El-Hussieny
Egypt-Japan University of Science and Technology
I think you should set a delay in the for loop after .setvel method to give the robot the chance to change its velocity. Otherwise the .setvel function it self should have a feedback teeling you that the commanded velocity is sent successfuly
1 Recommendation
15th Apr, 2015
Shawn M. Freeman
Weather Source
The robot IS responding to all the commands. The problem here is that your code does nothing to wait for a response. Your overwriting commands faster than the robot can respond to them. The only reason why the last command appears to work is because you're not overwriting it after it's submitted.
To verify this, add a time delay in the loop of a few seconds. This should be plenty of time for the robot to respond to each command.
Ideally you'd establish a callback or a response handler so that each command wouldn't trigger until the previous command is complete.
6 Recommendations

Similar questions and discussions

Call For Joining Computer Vision Project: ToxTrac
Discussion
2 replies
  • Alvaro RodriguezAlvaro Rodriguez
ToxTrac is a free Windows program optimized for tracking animals. It uses a Computer Vision tracking algorithm that is robust; very fast; and that can handle one or several animals in one or several environments. The program provides useful statistics as output. ToxTrac can be used for fish, insects, rodents, etc.
ToxTrac is currently being used in dozens of institutions and is one of the best available tracking software for animal studies.
The Project is currently being developed by only one person, but there is a large amount of work to be done. So a call for collaboration is open.
What I need, is people with knowledge in C++ with expertise in some of the following areas:
• Computer Vision and programming in OpenCV
• Machine Learning (with knowledge of TensorFlow)
• User interface design with QT
Authorship in all related scientific contributions will be shared.
Thank you for your support and patience.
Instruction video: https://youtu.be/RaVTsQ1JwfM
Citations:
• Rodriguez, A., Zhang, H., Klaminder, J., Brodin, T., Andersson, P. L. and Andersson, M. (2018). ToxTrac: a fast and robust software for tracking organisms. Methods in Ecology and Evolution. 9(3):460–464.
• Rodriguez, A., Zhang, H., Klaminder, J., Brodin, T., and Andersson, M. (2017). ToxId: an algorithm to track the identity of multiple animals. Scientific Reports. 7(1):14774.
ToxTrac is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

Related Publications

Article
Full-text available
The efficiency of object-oriented programs has become a point of great interest. One necessary factor for program efficiency is the optimization techniques involved. This paper presents the performance of several variations of a given C++ program and compares them with a version that uses no object-oriented features. Our result indicates that some...
Chapter
In the five previous chapters, you learned how to code functions that exploited the computational capabilities of AVX and AVX2 using C++ SIMD intrinsic functions. The chapter you are about to read introduces AVX-512 SIMD programming. It begins with a brief overview of AVX-512 and its various instruction set extensions. This is followed by a section...
Got a technical question?
Get high-quality answers from experts.