Skip to content

Commit 72d16e8

Browse files
authored
Pr test print (#161)
* remove errors * cleanup of file * Remove some unnecessary leftovers * fix warnings * reduce timeout values * add mrc_print * Add Mechanisms and OpModes to translation * Add super to derived methods * remove update from default block for robot * Update methods for mechanism and robot * Update base classes * Base classes for running * Get robot code to generate correctly * Fix needing annotations * Changes needed for opmode to work * Changed because components wasn't taken out of Blockly in the translation files * change if( to if ( * Changed to put all decorations on one import * Change from annotations to decorations (annotations are something different in python)
1 parent ee34d3a commit 72d16e8

29 files changed

+401
-102
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
# production
1212
/build
1313

14+
# python stuff
15+
__pycache__
16+
*.egg-info
17+
1418
# misc
1519
.DS_Store
1620
.env.local
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
"""Base classes for SystemCore blocks interface."""
2+
3+
from .opmode import OpMode, Teleop, Auto, Test, Name, Group
4+
from .mechanism import Mechanism
5+
from .robot_base import RobotBase
6+
7+
__all__ = ['OpMode', 'Teleop', 'Auto', 'Test', 'Name', 'Group'
8+
'Mechanism', 'RobotBase']
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This is the class all mechanisms derive from
2+
3+
class Mechanism:
4+
def __init__(self):
5+
self.hardware = []
6+
def start(self):
7+
for hardware in self.hardware:
8+
hardware.start()
9+
def update(self):
10+
for hardware in self.hardware:
11+
hardware.update()
12+
def stop(self):
13+
for hardware in self.hardware:
14+
hardware.stop()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This is the base class that all OpModes derive from
2+
class OpMode:
3+
def __init__(self, robot):
4+
self.robot = robot
5+
def start(self):
6+
self.robot.start()
7+
def loop(self):
8+
self.robot.update()
9+
def stop(self):
10+
self.robot.stop()
11+
12+
# For now this does nothing but it lets the decorator work
13+
def Teleop(OpMode):
14+
return OpMode
15+
16+
def Auto(OpMode):
17+
return OpMode
18+
19+
def Test(OpMode):
20+
return OpMode
21+
22+
def Name(OpMode, str):
23+
return OpMode
24+
25+
def Group(OpMode, str):
26+
return OpMode
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "blocks_base_classes"
7+
version = "0.1.0"
8+
description = "Base classes for SystemCore blocks interface"
9+
requires-python = ">=3.8"
10+
license = {text = "Apache-2.0"}
11+
authors = [
12+
{name = "Alan Smith", email = "[email protected]"}
13+
]
14+
dependencies = []
15+
16+
[tool.setuptools.packages.find]
17+
where = ["."]
18+
include = ["blocks_base_classes*"]
19+
20+
[tool.setuptools.package-dir]
21+
"blocks_base_classes" = "."
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This is the class all robots derive from
2+
3+
class RobotBase:
4+
def __init__(self):
5+
self.hardware = []
6+
def start(self):
7+
for hardware in self.hardware:
8+
hardware.start()
9+
def update(self):
10+
for hardware in self.hardware:
11+
hardware.update()
12+
def stop(self):
13+
for hardware in self.hardware:
14+
hardware.stop()

server_python_scripts/opmode.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

server_python_scripts/run_opmode.py

100644100755
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
import argparse
1616
from pathlib import Path
1717

18-
# Add the current directory to Python path to import local modules
19-
sys.path.insert(0, str(Path(__file__).parent))
18+
from blocks_base_classes import OpMode
2019

21-
from opmode import OpMode
2220
from robot import Robot
2321

2422

src/blocks/mrc_call_python_function.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ const CALL_PYTHON_FUNCTION = {
626626
break;
627627
}
628628
case FunctionKind.INSTANCE_COMPONENT: {
629-
const componentNameChoices = [];
629+
const componentNameChoices : string[] = [];
630630
this.mrcComponents.forEach(component => componentNameChoices.push(component.name));
631631
if (!componentNameChoices.includes(this.mrcComponentName)) {
632632
componentNameChoices.push(this.mrcComponentName);
@@ -723,7 +723,7 @@ const CALL_PYTHON_FUNCTION = {
723723
}
724724
}
725725
if (indexOfComponentName != -1) {
726-
const componentNameChoices = [];
726+
const componentNameChoices : string[] = [];
727727
this.mrcComponents.forEach(component => componentNameChoices.push(component.name));
728728
titleInput.removeField(FIELD_COMPONENT_NAME);
729729
titleInput.insertFieldAt(indexOfComponentName,

src/blocks/mrc_class_method_def.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ const CLASS_METHOD_DEF = {
214214
mrcRenameParameter: function (this: ClassMethodDefBlock, oldName: string, newName: string) {
215215
let nextBlock = this.getInputTargetBlock('STACK');
216216

217-
if(nextBlock){
217+
if (nextBlock){
218218
findConnectedBlocksOfType(nextBlock, MRC_GET_PARAMETER_BLOCK_NAME).forEach((block) => {
219219
if (block.getFieldValue('PARAMETER_NAME') === oldName) {
220220
block.setFieldValue(newName, 'PARAMETER_NAME');
@@ -362,12 +362,12 @@ export const pythonFromBlock = function (
362362
}
363363
if (block.mrcPythonMethodName == '__init__') {
364364
let class_specific = generator.getClassSpecificForInit();
365-
branch = generator.INDENT + 'super.__init__(' + class_specific + ')\n' +
365+
branch = generator.INDENT + 'super().__init__(' + class_specific + ')\n' +
366366
generator.defineClassVariables() + branch;
367367
}
368-
else if (funcName == 'update'){
368+
else if (generator.inBaseClassMethod(blocklyName)){
369369
// Special case for update, to also call the update method of the base class
370-
branch = generator.INDENT + 'super.update()\n' + branch;
370+
branch = generator.INDENT + 'super().' + blocklyName + '()\n' + branch;
371371
}
372372
if (returnValue) {
373373
returnValue = generator.INDENT + 'return ' + returnValue + '\n';

0 commit comments

Comments
 (0)