mujoco
mujoco copied to clipboard
How would one program the joints, in C++, to move up and down ever five seconds?
Under the control section of the simulate.cc
file, I would like to modify it to make all joints move -1 and then move 1 every five seconds.
The block of code below is from line 912 in the simulate.cc
. My modification is a while loop commented with // My code here
.
I would like to do this just in order to learn if it is possible for movement of joints / actuators to be controlled in real time with programming in the cc file before it is compiled. I know torque and other forces are determined by the conditions in the XML file, but I want to know if I can have an input of time and direction in the cc file.
If you're curious, I want to do this because I would like to deploy a trained neural network into the model. A neural network model that has been trained on a physical robot. I got somewhat of an answer here, but I don't understand MuJoCo well enough to know where to begin with this. "Define a C function of type [mjfAct](gainprm = "0")
that outputs the torque for a given actuator ID.". Sorry, I don't see anything like this in the samples, so I'm not sure what a function like this would look like.
// make control section of UI
void makecontrol(int oldstate)
{
int i;
mjuiDef defControl[] =
{
{mjITEM_SECTION, "Control", oldstate, NULL, "AC"},
{mjITEM_BUTTON, "Clear all", 2},
{mjITEM_END}
};
mjuiDef defSlider[] =
{
{mjITEM_SLIDERNUM, "", 2, NULL, "0 1"},
{mjITEM_END}
};
// add section
mjui_add(&ui1, defControl);
defSlider[0].state = 2;
// add controls, exit if UI limit reached (Clear button already added)
int itemcnt = 1;
for( i=0; i<m->nu && itemcnt<mjMAXUIITEM; i++ )
{
// skip if actuator group is disabled
if( !vopt.actuatorgroup[mjMAX(0, mjMIN(mjNGROUP-1, m->actuator_group[i]))] )
continue;
// set data and name
defSlider[0].pdata = d->ctrl + i;
if( m->names[m->name_actuatoradr[i]] )
mju_strncpy(defSlider[0].name, m->names+m->name_actuatoradr[i],
mjMAXUINAME);
else
sprintf(defSlider[0].name, "control %d", i);
// My code here
while(1 = 1)
{
defSlider[0].state = -1
Sleep(5000);
defSlider[0].state = 1
}
// set range
if( m->actuator_ctrllimited[i] )
sprintf(defSlider[0].other, "%.4g %.4g",
m->actuator_ctrlrange[2*i], m->actuator_ctrlrange[2*i+1]);
else
strcpy(defSlider[0].other, "-1 1");
// add and count
mjui_add(&ui1, defSlider);
itemcnt++;
}
}