Welcome to DOFBOT SE repository
8.DOFBOT memory action
DOFBOT Memory Action
1. API Introduction
- API for entering/exiting learning mode:
Arm_Button_Mode(enable)
Function: Set whether the DOFBOT enters learning mode.
Parameters:
enable: enable=0: exit learning mode, enable=1: enter learning mode.
After entering learning mode, the RGB light on the DOFBOT expansion board will show a breathing light effect, and the DOFBOT will automatically disable torque, allowing you to freely move the arm. Each press of the K1 button on the expansion board switches the breathing light to another color, indicating that the current DOFBOT posture has been recorded. Up to 20 groups of actions can be recorded. When the number of recorded action groups exceeds 20, pressing K1 will no longer record actions, and the breathing light will turn red. After exiting learning mode, the DOFBOT will automatically enable torque and turn off the RGB light.
Return value: None.
- API for reading the current number of action groups:
Arm_Read_Action_Num()
Function: Read the number of currently recorded action groups.
Parameters:
Return value: Returns the number of currently recorded action groups.
- API for running action groups:
Arm_Action_Mode(mode)
Function: Run the recorded action groups.
Parameters:
mode: mode=0: stop running action groups, mode=1: run action groups once, mode=2: loop run action groups.
Return value: None.
- API for clearing action groups:
Arm_Clear_Action()
Function: Clear the recorded action groups. Once cleared, it cannot be recovered.
Parameters:
Return value: None.
- API for learning actions in learning mode:
Arm_Action_Study()
Function: In learning mode, send a command to the expansion board to record the current DOFBOT posture as an action group. When learning is successful, the RGB breathing light effect will change color.
Parameters:
Return value: None.
2. Code Content
Code path: /home/yahboom/Dofbot/3.ctrl_Arm/8.study_mode.ipynb
The following code needs to be executed step by step. Do not run all at once.
#!/usr/bin/env python3#coding=utf-8import timefrom Arm_Lib import Arm_Devicexxxxxxxxxx# Create DOFBOT objectArm = Arm_Device()time.sleep(.1)xxxxxxxxxx# Open learning mode. The RGB light on the expansion board shows breathing light effect, and all DOFBOT servos enter torque-off state.# This means you can freely move the DOFBOT to the position you want to remember.Arm.Arm_Button_Mode(1)xxxxxxxxxx# In learning mode, each time this cell runs, the current action is saved to the expansion board, and the RGB light on the expansion board switches color.# If a red breathing light appears, it means the number of learned action groups is full (20 groups).# This command can also be replaced by pressing the K1 button on the expansion board. Both have the same function.Arm.Arm_Action_Study()xxxxxxxxxx# Close learning mode. Turn off breathing light.Arm.Arm_Button_Mode(0)xxxxxxxxxx# Read current number of action groupsnum = Arm.Arm_Read_Action_Num()print(num)xxxxxxxxxx# Run action groups onceArm.Arm_Action_Mode(1)xxxxxxxxxx# Loop run action groupsArm.Arm_Action_Mode(2)xxxxxxxxxx# Stop action groupsArm.Arm_Action_Mode(0)xxxxxxxxxx# Clear action groups. After clearing, the RGB light on the expansion board will light up green.# Note: Once the recorded action groups are cleared, they cannot be recovered.Arm.Arm_Clear_Action()xxxxxxxxxxdel Arm # Release Arm objectOpen the program from jupyter lab and click the "Run Cell" button on the toolbar to run the program step by step.

After opening learning mode, you can move the DOFBOT's posture, then run Arm.Arm_Action_Study() or press the K1 button on the expansion board to record the current DOFBOT posture. Repeat this operation several times, then close the learning mode. Next, you can run the learned action groups to see the effect. The specific operations are explained in the comments in the code above.