I am trying to add a distance sensor to a kuka robot in webots software KUKA robot that has no field called children but I added the distance sensor in bodyslot field now the sensor is reading nan all the time
#include <webots/keyboard.h>
#include <webots/robot.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <webots/distance_sensor.h>
#define TIME_STEP 32
int main(int argc, char **argv) {
wb_robot_init();
//////////////////////////////
WbDeviceTag ps[1];
char ps_names[1][3] = {"DS"};
ps[0] = wb_robot_get_device(ps_names[0]);
wb_distance_sensor_enable(ps[0], TIME_STEP);
////////////////////////////////
// read sensors outputs
double ps_values;
ps_values = wb_distance_sensor_get_value(ps[0]);
//////////////////////////////////////////////////////////
while (true) {
step();
printf ("\n %f \n", ps_values);
//while (ps_values > 80){
base_forwards_increment();
//}
// base_backwards_increment();
}
wb_robot_cleanup();
return 0;
}
enter image description here
To find a way to add a distance sensor to kuka robot
Related
Client server must pass to the Server process a filename and the Server process must return the number of lines in the file. My problem is that the received variable only contains 6 characters of the filename and it ends up by throwing segmentation fault dump core error. Do you know why this happens? This is my code:
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
int main(){
int fd1,fd2;
const char *fifo1="./fifo1Channel";
const char *fifo2="./fifo2Channel";
mkfifo(fifo1,0666);
mkfifo(fifo2,0666);
char filename[30];
printf("Give me a filename:\n");
fgets(filename,30,stdin);
strtok(filename,"\n");
int pid=fork();
if(pid>0){
char received[30], ch;
FILE *fp;
fd1=open(fifo1, O_RDONLY);
read(fd1,received,strlen(received));
close(fd1);
printf("From server process:%s\n",received);
fp=fopen(received,"r");
int nrOfLines=0;
for(ch=getc(fp);ch!=EOF;ch=getc(fp))
if(ch=='\n')
nrOfLines++;
fd2=open(fifo2, O_WRONLY);
write(fd2,&nrOfLines,sizeof(nrOfLines));
close(fd2);
return 0;
}
if(pid==0){
int receivedNumber;
fd1=open(fifo1,O_WRONLY);
write(fd1,filename,strlen(filename));
close(fd1);
fd2=open(fifo2,O_RDONLY);
read(fd2,&receivedNumber,sizeof(receivedNumber));
close(fd2);
printf("From client process: %d\n",receivedNumber);
return 0;
}
return 0;
}
I think the problem was in server process. I replaced strlen(received) with 30, the maximum number of characters of filename, in function read and it works now!
Based on this bug i'm trying to write an entry in /var/run/utmp to simulate the problem http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=528060 , i tryed with this code taken from manpages, but didn't work
#include <string.h>
#include <stdlib.h>
#include <pwd.h>
#include <unistd.h>
#include <utmp.h>
int
main(int argc, char *argv[])
{
struct utmp entry;
system("echo before adding entry:;who");
entry.ut_type = USER_PROCESS;
entry.ut_pid = getpid();
strcpy(entry.ut_line, ttyname(STDIN_FILENO) + strlen("/dev/"));
/* only correct for ptys named /dev/tty[pqr][0-9a-z] */
strcpy(entry.ut_id, ttyname(STDIN_FILENO) + strlen("/dev/tty"));
time(&entry.ut_time);
strcpy(entry.ut_user, getpwuid(getuid())->pw_name);
memset(entry.ut_host, 0, UT_HOSTSIZE);
entry.ut_addr = 0;
setutent();
pututline(&entry);
system("echo after adding entry:;who");
exit(EXIT_SUCCESS);
}
I solved my problem with this code
#include <string.h>
#include <stdlib.h>
#include <pwd.h>
#include <unistd.h>
#include <utmp.h>
int
main(int argc, char *argv[])
{
struct utmp entry;
system("echo before adding entry:;who");
entry.ut_type = USER_PROCESS;
entry.ut_pid = getpid();
strcpy(entry.ut_line, ttyname(STDIN_FILENO) + strlen("/dev/"));
/* only correct for ptys named /dev/tty[pqr][0-9a-z] */
strcpy(entry.ut_id, ttyname(STDIN_FILENO) + strlen("/dev/tty"));
time(&entry.ut_time);
//strcpy(entry.ut_user, getpwuid(getuid())->pw_name);
strcpy(entry.ut_user, "pippo");
memset(entry.ut_host, 0, UT_HOSTSIZE);
entry.ut_addr = 0;
setutent();
pututline(&entry);
system("echo after adding entry:;who");
exit(EXIT_SUCCESS);
}
I generated C++ shared library in MATLAB and integrated it in Win32 console application in C++. I have to call this console application from PHP.It has 5 inputs which should be passed from php. When I run the application giving the input parameters it runs. The code which runs properly is as below:
#include "stdafx.h"
#include "shoes_sharedlibrary.h"
#include <iostream>
#include <string.h>
#include "mex.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
/* Call the MCR and library initialization functions */
if( !mclInitializeApplication(NULL,0) )
{
exit(1);
}
if (!shoes_sharedlibraryInitialize())
{
exit(1);
}
mwArray img= "C:/Users/aadbi.a/Desktop/dressimages/T1k5aHXjNqXXc4MOI3_050416.jpg";
double wt1 = 0;
mwArray C(wt1);
double wt2=0;
mwArray F(wt2);
double wt3=0;
mwArray T(wt3);
double wt4=1;
mwArray S(wt4);
test_shoes(img,C,F,T,S);
shoes_sharedlibraryTerminate();
mclTerminateApplication();
return 0;
}
The C,F,T,S are value between 0 and 1. How can I pass the input arguments as it is in _TCHAR*?How can I convert the _TCHAR* into decimal or double and again converting that into mwArray to pass into test_shoes. The test_shoes only takes mwArray as input.
The test_shoes function definition is:
void MW_CALL_CONV test_shoes(const mwArray& img_path, const mwArray& Wcoarse_colors,
const mwArray& Wfine_colors, const mwArray& Wtexture, const
mwArray& Wshape)
{
mclcppMlfFeval(_mcr_inst, "test_shoes", 0, 0, 5, &img_path, &Wcoarse_colors, &Wfine_colors, &Wtexture, &Wshape);
}
You can convert the command line string arguments to double using the atof() function from stdlib.h. As I see you are using the TCHAR equivalents, there is a macro that wraps the correct call for UNICODE and ANSI builds, so you can do something like this (assuming your command line arguments are in the correct order)
#include "stdafx.h"
#include "shoes_sharedlibrary.h"
#include <iostream>
#include <string.h>
#include "mex.h"
#include <stdlib.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
// ... initial code
// convert command line arguments to doubles ...
double wt1 = _tstof(argv[1]);
mwArray C(wt1);
double wt2 = _tstof(argv[2]);
mwArray F(wt2);
double wt3 = _tstof(argv[3]);
mwArray T(wt3);
// ... and so on ....
}
Note that argv[0] will contain the name of your program as specified on the command line, so the arguments begin at argv[1]. Then your command line can be something like:
yourprog.exe 0.123 0.246 0.567 etc.
Here is a pruned version of a problem I have using QT/linux. The program runs, but the size of the displayed widget is wrong (the contents, frame + labels, does not fit).
I understood that the size of a windows should be computed fron its contents (children). Why is that not happening properly here?
So the first question is, of course why this is happening.
The real program actually updates the contents of the widget at run-time. I have tried to simulate that behavior by the insertion of the main_window->show() (commented //SHOW1). If this first show() call is made, then the second show() does not show the new contents the widget. I have tried with update without success...
#include <QApplication>
#include <QtCore>
#include <QMainWindow>
#include <QTabWidget>
#include <QWidget>
#include <QGroupBox>
#include <QVBoxLayout>
#include <QLabel>
#include <stdlib.h>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow* main_window = new(QMainWindow);
main_window->setObjectName("main_window");
main_window->resize(800, 600);
main_window->setWindowTitle("Hello");
QTabWidget* node_tab_widget = new QTabWidget(main_window);
// node_tab_widget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
// node_tab_widget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
node_tab_widget->setObjectName(QString::fromUtf8("tab_widget"));
node_tab_widget->resize(500, 400);
QWidget* w= new QWidget(node_tab_widget);
node_tab_widget->addTab(w, "TAB");
//main_window->show(); //SHOW1
QGroupBox* group_widget = new QGroupBox("GROUPNAME", w);
QVBoxLayout* group_layout = new QVBoxLayout;
group_widget->setLayout(group_layout);
group_layout->addWidget((QLabel*)new QLabel(">>>>>>>>>>>>>>>>>>>>>>>>>here1"));
group_layout->addWidget((QLabel*)new QLabel("here2"));
// group_widget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
main_window->update();
main_window->show();
return app.exec();
}
I don't really understand what is the result you expect, can be something like what you get from this code:
#include <QApplication>
#include <QtCore>
#include <QMainWindow>
#include <QTabWidget>
#include <QWidget>
#include <QGroupBox>
#include <QVBoxLayout>
#include <QLabel>
#include <stdlib.h>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QMainWindow* main_window = new(QMainWindow);
main_window->setObjectName("main_window");
main_window->resize(800, 600);
main_window->setWindowTitle("Hello");
QTabWidget* node_tab_widget = new QTabWidget();
node_tab_widget->setObjectName(QString::fromUtf8("tab_widget"));
node_tab_widget->resize(500, 400);
QWidget* w= new QWidget();
node_tab_widget->addTab(w, "TAB");
QGroupBox* group_widget = new QGroupBox("GROUPNAME", w);
QVBoxLayout* group_layout = new QVBoxLayout;
group_widget->setLayout(group_layout);
group_layout->addWidget((QLabel*)new QLabel(">>>>>>>>>>>>>>>>>>>>>>>>>here1"));
group_layout->addWidget((QLabel*)new QLabel("here2"));
QVBoxLayout* gl = new QVBoxLayout;
gl->addWidget(group_widget);
main_window->setCentralWidget(node_tab_widget);
main_window->show();
return app.exec();
}
which add the QTabWidget node_tab_widget as central widget, with a tab TAB.
The tab contain the QGroupBox GROUPNAME with the two labels (vertical aligned)
i am trying to make a webserver in C which can handle request to dynamic contents.
the webserver part is finish already. i'm trying to execute the following command:
http://localhost:1601/cgi-bin/test?3&7
with the code of program test is as follow:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
#include <fcntl.h>
#include <errno.h>
#include <wordexp.h>
#define MAXLINE 300
int main(int narg, char * arg[]) {
char *buf, *p;
char arg1[MAXLINE], arg2[MAXLINE], content[MAXLINE];
int n1=0, n2=0;
/* Extract the two arguments */
if ((buf = getenv("QUERY_STRING")) != NULL) {
p = strchr(buf, '&');
*p = '\0';
strcpy(arg1, buf);
strcpy(arg2, p+1);
n1 = atoi(arg1);
n2 = atoi(arg2);
}
/* Make the response body */
sprintf(content, "Welcome to add.com: ");
sprintf(content, "%sTHE Internet addition portal.\r\n<p>", content);
sprintf(content, "%sThe answer is: %d + %d = %d\r\n<p>",
content, n1, n2, n1 + n2);
sprintf(content, "%sThanks for visiting!\r\n", content);
/* Generate the HTTP response */
printf("Content-length: %d\r\n", (int)strlen(content));
printf("Content-type: text/html\r\n\r\n");
printf("%s", content);
if (fork()==0) {
printf("asdfagloiauergauhfgaiudfhg");
execvp("ls",arg);
printf("child of adder error");
}
printf("%s", content);
fflush(stdout);
exit(0);
}
/* $end adder */
It run well. However, i wonder why the child code (the line printf("asdfagloiauergauhfgaiudfhg"); and execvp) didn't print out to the webserver's output. although everything else in test output correctly.
For starters you set the Content-length header to the length of the content, then sent the content, then sent more data in both threads. The browser is within its rights to ignore everything after content-length bytes in the output stream.