How to use Reduced Mode in C# or CPP

Hi All,

I’m developing an app in C# using a class based on the C# Wrapper (XArmAPI.cs).
I want to demonstrate the reduced mode for my students so my computer setup is :

  • Detection sensor on serial => in C# event DataReceived
  • Loop (x5) Motion between 2 poses where arm should go in reduced mode

I want to see the speed change when the sensor is activated and the flag HumanIn is set to true.

Some pieces of code:
- xARM reset and Max Speed definition

  xARM.Reset();
 xARM.SetReducedMaxTCPSpeed(500.0F);

- Serial event code

// Cobot RS232 Interrupt
if (rs232.StartsWith(“E”))
{
HumanIn = !HumanIn;
if (xARM.IsCreated() && xARM.IsEnableMotion())
{
if (HumanIn)
xARM.ActivateReducedMode(true);
else
xARM.ActivateReducedMode(false);
}
}

As I can’t see the speed changes then I modify my code to test the HumanIn flag state toggle with the code below:

// Loop
if (xARM.IsCreated() && xARM.IsEnableMotion())
{
for (int i = 0; i < 5; i++)
{
if (HumanIn)
i = 5;
xARM.MoveBase(pose1, radius, speed, acc, mvtime, wait, timeout, relative, motion_type);
// Update GUI
buttonGetJoint_Click(sender, e);
buttonGetPosition_Click(sender, e);
xARM.MoveBase(pose2, radius, speed, acc, mvtime, wait, timeout, relative, motion_type);
// Update GUI
buttonGetJoint_Click(sender, e);
buttonGetPosition_Click(sender, e);
}
if (HumanIn)
{
xARM.MoveHome(0, 0, 0, true);
// Update GUI
buttonGetJoint_Click(sender, e);
buttonGetPosition_Click(sender, e);
}
else
{
xARM.MoveBase(pose1, true);
// Update GUI
buttonGetJoint_Click(sender, e);
buttonGetPosition_Click(sender, e);
}
}

The result is OK => the flag goes to true => the loop is stopped => Robot goes to Home

Now to setup the reduced mode, some questions:

Q1) How the setup the “normal” TCP Speed for all “MoveBase” (same as setPosition in XArmAPI )?
In most of the code sample, in setPosition, speed is set to default value = 0.

Q2) Is it possible to enable or disable the Reduced Mode while arm is in motion ?

Regards.
Olivier.

UFACTORY Website
Official Store
uArm User Facebook Group

Feedback:
English Channel
中文通道

Hi Olivier,

Q1: you can set a global speed, for example, set the speed in if{humanIn}. If you set a speed greater than the max reduced mode speed, the max reduced mode speed will be used by default after the reduced mode is turned on, we use arm->last_used_tcp_speed.
Q2: No, Reduced mode takes effect for the next command and will not affect the current running movement.

Best regards,
Minna

Hi Minna,

Ok the reduced mode will be effective for the next move.

I’ve designed my own c# class but basically the same as the wrapper or the C¨++ api.
Below, the setup instructions in the C++ sample for reduced Mode:

XArmAPI *arm = new XArmAPI(port);
sleep_milliseconds(500);
if (arm->error_code != 0) arm->clean_error();
if (arm->warn_code != 0) arm->clean_warn();
arm->motion_enable(true);
arm->set_mode(0);
arm->set_state(0);
sleep_milliseconds(500);

ret = arm->set_reduced_max_tcp_speed(500);
printf(“set_reduced_max_tcp_speed, ret=%d\n”, ret);
ret = arm->set_reduced_max_joint_speed(100);
printf(“set_reduced_max_tcp_speed, ret=%d\n”, ret);

The “normal” speed is not defined in the code.
To demonstrate the reduced mode to my students, I want to setup (in the code) the speed at 1000mm/s and the reduced mode speed is 500mm/s.

Question: should I use the min - max variable to setup the “normal” velocity:

fp32 *tcp_speed_limit; // fp32[2]{min, max}

More testing and results
I’ve put a set_position with speed at 1000mm/s before my loop so arm->last_used_tcp_speed should be at this value.
I’ve reduced the max speed as follow:

ret = arm->set_reduced_max_tcp_speed(100);
ret = arm->set_reduced_max_joint_speed(80);

Now I can visually see the velocity change when the reduced Mode is activate.

But question above is still pending :grinning:

Regards.

Olivier.

Hi Oliver,

Not quite understand what is the current problem, can you explain more?

I try to explain the logic of speed. When you call set_position, if the defined speed is greater than 0, then it will use the speed you defined. If not, it will use the speed in last_used_tcp_speed.
The initial value of last_used_tcp_speed is 100, and it will be updated if you define speed in set_position, it has nothing to do with tcp_speed_limit.

When you enable and set reduced mode, if you don’t define speed in set_position, and last_used_tcp_speed > reduced_max_tcp_speed, it will use reduced max tcp speed.

Minna

Hi Minna,

I’ll try to be more precise.
In blockly or in python, you can explicitly define:

  • TCP speed and acceleration
  • Joint speed and acceleration

I understand that:

  • Initial speed value is 100mm/s (default value in the CPP API)
  • In set_position if speed = 0 then last_used_tcp_speed is used
  • In set_position if speed > 0 then the move will be with the specified velocity (if possible) and last_used_tcp_speed is updated.

Question : I’m looking to do default value initialization in C++or in C# => which variable or function should I change or call ?

With this settings in my code below:

  • set_reduced_max_tcp_speed(100)
  • set_reduced_max_joint_speed(80)
  • set_position to pose0 with speed = 1000mm/s before the loop
  • looping pose1 and pose2 with speed = 0 in set_position (to use last_used_tcp_speed)

I could see the TCP speed changes (10 times slower) when entering reduced mode.

The C++ sample with reduced mode is setup with 500mm/s and this value is above the default one of 100mm/s maybe this is why I could not see the velocity changes.

Regards.
Olivier.

        speed = 1000.0F;
        if (xARM.IsCreated() && xARM.IsEnableMotion())
        {
            xARM.MoveBase(pose0, radius, speed, acc, mvtime, wait, timeout, relative, motion_type);
            for (int i = 0; i < 5; i++)
            {
                //if HumanIn is true => Activate Reduced Mode
                xARM.ActivateReducedMode(HumanIn);
                xARM.MoveBase(pose1, radius, 0.0F, acc, mvtime, wait, timeout, relative, motion_type);
                xARM.MoveBase(pose2, radius, 0.0F, acc, mvtime, wait, timeout, relative, motion_type);
            }
            if (HumanIn)
                xARM.MoveHome(0.0F, 0.0F, 0.0F, true);
            else
                xARM.MoveBase(pose1, true);
        }

Hi Olivier,

The C++ sample with reduced mode is setup with 500mm/s and this value is above the default one of 100mm/s maybe this is why I could not see the velocity changes.
→ Yes, I think so.

Actually, for Blockly, we pass the speed ourselves.

For C++, you can initialize via arm->last_used_tcp_speed = xxx; or store the speed in your program and pass it into set_position yourself.

Best,

Hi Minna,

Yes this is what I’ve seen in Blockly or Python.

I’ll try to initialize last_used_tcp_speed at beginning of my code to force tcp speed above 100mm/s.

Now my program enters in reduced mode when the event is raised for the first time but does not goes back to normal when the event is raised a second time.
I think this is more windows programming and not linked to xARM code.

I’ll report my results.

Thanks for your feedback.

Regards.
Olivier.