Force Mode¶
In this tutorial we will demonstrate use of the force control mode of ORCA motors.
Prerequisites¶
We’ll start with the following code, which is a modified example from the command stream tutorial displaying force instead of position. We recommend using command streaming when controlling the motor via force mode.
#include <iostream>
#include "actuator.h"
using namespace orcaSDK;
int main() {
Actuator motor;
int serial_port;
std::cout << "Please input the serial port number of your connected motor. ";
std::cin >> serial_port;
motor.open_serial_port(serial_port);
motor.enable_stream();
while (true) {
motor.run();
std::cout << "Current Force: " << motor.stream_cache.force << " \r";
}
return 0;
}
from pyorcasdk import Actuator
motor = Actuator()
serial_port = int(input("Please input the serial port number of your connected motor. "))
motor.open_serial_port(serial_port)
motor.enable_stream()
while True:
motor.run()
print("Current Force: " + str(motor.get_stream_data().force), end=" \r")
Command a Force¶
To begin, let’s set the motor into force mode.
...
motor.enable_stream();
motor.set_mode(MotorMode::ForceMode);
...
from pyorcasdk import MotorMode
...
motor.enable_stream()
motor.set_mode(MotorMode.ForceMode)
...
At this point the motor is ready to receive force commands. Let’s give it one.
...
motor.enable_stream();
motor.set_mode(MotorMode::ForceMode);
motor.set_streamed_force_mN(10000);
...
...
motor.enable_stream()
motor.set_mode(MotorMode.ForceMode)
motor.set_streamed_force_mN(10000)
...
Try running the program, you should notice that the shaft moves. Try opening IrisControls. It should display that you are in force mode, and that it’s detecting a force of around 10 newtons.
Timeout Error¶
Now close your program and run it again. This time you may notice that the shaft does not move. Take a look again at IrisControls. It should be displaying that an error has occurred, particularly a “comms timeout”. Some ORCA modes, including force mode, require that regular communication happens with the motor, else it will stop exerting force. This is a safety feature. When actively giving a motor commands, any stops in communication are interpreted as a failure or shutdown of the system at large.
In order to resolve this issue, lets clear errors before beginning. This will allow the program to run again.
...
motor.set_mode(MotorMode::SleepMode);
motor.set_mode(MotorMode::ForceMode);
...
...
motor.set_mode(MotorMode.SleepMode)
motor.set_mode(MotorMode.ForceMode)
...
After adding this command in, your program should run as normal again.
Complete Example¶
#include <iostream>
#include "actuator.h"
using namespace orcaSDK;
int main() {
Actuator motor;
int serial_port;
std::cout << "Please input the serial port number of your connected motor. ";
std::cin >> serial_port;
motor.open_serial_port(serial_port);
motor.enable_stream();
motor.set_mode(MotorMode::SleepMode); // ORCA motors raise an error when communication stops during force mode
motor.set_mode(MotorMode::ForceMode);
motor.set_streamed_force_mN(10000);
while (true) {
motor.run();
std::cout << "Current Force: " << motor.stream_cache.force << " \r";
}
return 0;
}
from pyorcasdk import Actuator, MotorMode
motor = Actuator()
serial_port = int(input("Please input the serial port number of your connected motor. "))
motor.open_serial_port(serial_port)
motor.enable_stream()
motor.set_mode(MotorMode.SleepMode)
motor.set_mode(MotorMode.ForceMode)
motor.set_streamed_force_mN(10000)
while True:
motor.run()
print("Current Force: " + str(motor.get_stream_data().force), end=" \r")