MCPcopy Create free account
hub / github.com/botbotrobotics/BotBrain / executeBlock

Function executeBlock

frontend/src/hooks/useBlockProgramExecution.tsx:631–684  ·  view source on GitHub ↗
(block: BlockCommand)

Source from the content-addressed store, hash-verified

629
630 // Execute a single block
631 const executeBlock = async (block: BlockCommand): Promise<void> => {
632 setExecutionState(prev => ({
633 ...prev,
634 currentBlockId: block.instanceId,
635 progress: 0
636 }));
637
638 switch (block.type) {
639 case 'move':
640 const distance = block.value || 0;
641 const distanceInMeters = block.unit === 'cm' ? distance / 100 : distance;
642 // Apply calibration factor to compensate for systematic errors
643 const calibratedDistance = distanceInMeters * MOVEMENT_CALIBRATION_FACTOR;
644 console.log(`Move block: ${distance}${block.unit || 'm'} -> ${calibratedDistance.toFixed(3)}m (calibration: ${MOVEMENT_CALIBRATION_FACTOR})`);
645 await executeMove(calibratedDistance, block.direction || 'forward');
646 break;
647
648 case 'turn_left':
649 case 'turn_right':
650 const degrees = block.value || 0;
651 // Apply calibration factor to compensate for systematic errors
652 const calibratedDegrees = degrees * ROTATION_CALIBRATION_FACTOR;
653 console.log(`Turn block: ${degrees}° -> ${calibratedDegrees.toFixed(1)}° (calibration: ${ROTATION_CALIBRATION_FACTOR})`);
654 await executeTurn(calibratedDegrees, block.type === 'turn_left' ? 'left' : 'right');
655 break;
656
657 case 'wait':
658 await executeWait(block.value || 1);
659 break;
660
661 case 'stand_up':
662 console.log('Executing stand up command');
663 await executeRobotAction('mode', { mode: 'stand_up' }, 'Stand up');
664 break;
665
666 case 'stand_down':
667 console.log('Executing stand down command');
668 await executeRobotAction('mode', { mode: 'stand_down' }, 'Stand down');
669 break;
670
671 case 'lock':
672 console.log('Executing joint lock command');
673 await executeRobotAction('mode', { mode: 'joint_lock' }, 'Joint lock');
674 break;
675
676 case 'unlock':
677 console.log('Executing balance stand (unlock) command');
678 await executeRobotAction('mode', { mode: 'balance_stand' }, 'Balance stand');
679 break;
680
681 default:
682 console.warn(`Unknown block type: ${block.type}`);
683 }
684 };
685
686 // Build flat sequence of blocks to execute
687 const buildBlockSequence = (blocks: BlockCommand[], startBlockId?: string): BlockCommand[] => {

Callers 1

useBlockProgramExecutionFunction · 0.85

Calls 5

executeMoveFunction · 0.85
executeTurnFunction · 0.85
executeWaitFunction · 0.85
executeRobotActionFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected