-
Notifications
You must be signed in to change notification settings - Fork 4
Understand The Source Code
Ks Tan edited this page Feb 3, 2021
·
7 revisions
If you wish to make some changes in this web service, you need to understand how it work.
/-
|-route.py # manage incoming traffic and map to specific function in function.py
|-function.py #maintain logical operation, it won't directly access into physical device IO/variables to avoid break something
|-images #no use at the moment
|-program #no use at the moment, hope future web service allow user customise own movement routine, and store here
|-tools/*.sh # store all the sh executable file for mac/linux users. It allow us auto QC, or become alternative training method to AR3
|-include/-
|- armparameters.py # keep all permanent parameter, like max/min degree, stepper motor limit, rest positions degree and etc
|- calculation.py # i plan future linear movement will store all calculation inside here. to avoid messy in main programming file
|- database.py # reserve future we store some runtime values into database, now this web service after quit some data just gone, like current travel track position (no encoder)
|- Hardware.py # code using OOP, so capital file. The actual hardware execution control by here
|- log.py # simple log function to console output. nothing much
|- setting.py # no use at the moment, may not need this
|- values.py # i define some important run time variable here. It give default value, when program execute it all change in memory. However, it is good if you want to know the pattern of data
All webservice we return in json data format. You need to ensure your output match the pattern to maintain consistency.
you shall make sure when you run your service, your hand standby at emergency stop button, so you can e-stop it to prevent break something
- Edit
route.py
, add something similar as below:
@app.route('/myaction/<jointname>')
def myaction(jointname):
result = f.runMyAction(jointname)
#do something you want
return result
- Edit
function.py
, addrunMyAction
:
# add your function at bottom of code
def runMyAction(jointname):
#do what you want to do, like
rotateJoint("J1",0,"absolute")
rotateJoint("J2",10,"move")
moveTrack("t1", 20, "move"):
# you can access hardware layer like below too
hardware.goAllJointLimit([1,1,0,0,0,0])
return log.getMsg("OK","Done")
- quit and restart your flask, then you can try browse to
http://localhost:5000/myaction
Add hardware layer function break into 2 scenario:
- Add function already and supported by ARCS/Teensy (Add Missing Function)
- Add function doesn't exists, mean you wish to create your own (Add New Function)
It is tricky work but not that difficult to make it. Below is how I do:
- open ARCS.py source code, search keyword at ARCS button, like
Calibrate @ Rest Position
, it bring me to line 6651 - the
command
attribute tell mecalRobotMid
is the function name to run when user press the button. - search
def calRobotMid
, it bring me to line 5005 - read the source code, find actual executable serial command. Something like
command = "LM"...
. I tried extract value
command = "LM"+"A"+str(J1StepCur)+"B"+str(J2StepCur)+"C"+str(J3StepCur)+"D"+str(J4StepCur)+"E"+str(J5StepCur)+"F"+str(J6StepCur)+"\n"
print(command)
- save and execute ARCS.py from command line, then I can see what is the serial command.
- then we need understand each variable it coming from, where to store it and how to calculate it.
- once you proper understand it, you may change Hardware.py, please take note it is OOP file, so you need to familiar how python implement OOP, like Hardware.py use alot of
self
, but function.py not use any
edit Hardware.py, add the last line of code add below code to send dummy command to teensy
def doMyWork(self,arg1,arg1):
command="ZZ01010101" #it not support by teensy, i just give example
board = self.ser_teensy # arduino port use self.ser_arduino
return self.writeIO(board,command)
Edit function.py, add following function:
def myWork():
result = hardware.doMyWork("J1",30)
return log.showMsg(result,"do my work done")
edit route.py, add this.
@app.route('/mywork')
def runMyWork():
result = f.runMyWork()
return result
- restart Flask
- browse to http://localhost:5000/mywork
- it require you to write your code into Teensy, you can refer teensy source code ARCS_teensy_sketch.ino in repository
- add the processor you want, something like:
if(function == "ZZ")
{
//do something you want
}
- Use Teensy IDE, burn new code into your teensy (Take your own risk)
- Do something similar according "Add Missing Function"
-
function.py
accept jointname (j1/j2/j3/j4/j5/j6) from route.py,Hardware.py
accept join_no (0,1,2,3,4,5) from function.py - all jointsvalue, servovalues, trackvalue store in Hardware.py attribute, function.py not direct manipulate this value
- at the moment, arm speed is hard coded in armsparameter.py, future may change at run time (not now)
- I notice firmware in teensy doesn't not block any movement beyond limit switch. It is python side responsibility to validate value whether acceptable range. The limit switch only function under calibration, no more than that. (I not so satisfy firmware not control it, but I not confident to changes Teensy cause I worry it break something)