Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
Hsiang-Yu
CHRONOS Simulink Model
Commits
4ddedfdf
Commit
4ddedfdf
authored
Jun 07, 2023
by
Hsiang-Yu
Browse files
pico motor
parent
c4def7dd
Changes
43
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
10725 additions
and
0 deletions
+10725
-0
picomotor_ver2/picomotor_ver2/._pcaspico.py
picomotor_ver2/picomotor_ver2/._pcaspico.py
+0
-0
picomotor_ver2/picomotor_ver2/._pico.log
picomotor_ver2/picomotor_ver2/._pico.log
+0
-0
picomotor_ver2/picomotor_ver2/HAPPY_PICO_CONTROL.adl
picomotor_ver2/picomotor_ver2/HAPPY_PICO_CONTROL.adl
+742
-0
picomotor_ver2/picomotor_ver2/HAPPY_PICO_MASTER.adl
picomotor_ver2/picomotor_ver2/HAPPY_PICO_MASTER.adl
+1030
-0
picomotor_ver2/picomotor_ver2/HAPPY_PICO_MASTER_BAK.adl
picomotor_ver2/picomotor_ver2/HAPPY_PICO_MASTER_BAK.adl
+1025
-0
picomotor_ver2/picomotor_ver2/HAPPY_TEST.adl
picomotor_ver2/picomotor_ver2/HAPPY_TEST.adl
+150
-0
picomotor_ver2/picomotor_ver2/HAPPY_TEST_BAK.adl
picomotor_ver2/picomotor_ver2/HAPPY_TEST_BAK.adl
+150
-0
picomotor_ver2/picomotor_ver2/Trinamic_control6110.py
picomotor_ver2/picomotor_ver2/Trinamic_control6110.py
+212
-0
picomotor_ver2/picomotor_ver2/Trinamic_control6110_edit.py
picomotor_ver2/picomotor_ver2/Trinamic_control6110_edit.py
+212
-0
picomotor_ver2/picomotor_ver2/__init__.py
picomotor_ver2/picomotor_ver2/__init__.py
+10
-0
picomotor_ver2/picomotor_ver2/__init__.pyc
picomotor_ver2/picomotor_ver2/__init__.pyc
+0
-0
picomotor_ver2/picomotor_ver2/__main__.py
picomotor_ver2/picomotor_ver2/__main__.py
+45
-0
picomotor_ver2/picomotor_ver2/config.py
picomotor_ver2/picomotor_ver2/config.py
+61
-0
picomotor_ver2/picomotor_ver2/config.pyc
picomotor_ver2/picomotor_ver2/config.pyc
+0
-0
picomotor_ver2/picomotor_ver2/example.log
picomotor_ver2/picomotor_ver2/example.log
+0
-0
picomotor_ver2/picomotor_ver2/log.txt
picomotor_ver2/picomotor_ver2/log.txt
+6644
-0
picomotor_ver2/picomotor_ver2/logging.conf
picomotor_ver2/picomotor_ver2/logging.conf
+36
-0
picomotor_ver2/picomotor_ver2/newfocus8742.py
picomotor_ver2/picomotor_ver2/newfocus8742.py
+204
-0
picomotor_ver2/picomotor_ver2/newfocus8742.pyc
picomotor_ver2/picomotor_ver2/newfocus8742.pyc
+0
-0
picomotor_ver2/picomotor_ver2/newfocus8742.py~
picomotor_ver2/picomotor_ver2/newfocus8742.py~
+204
-0
No files found.
picomotor_ver2/picomotor_ver2/._pcaspico.py
0 → 100644
View file @
4ddedfdf
File added
picomotor_ver2/picomotor_ver2/._pico.log
0 → 100644
View file @
4ddedfdf
File added
picomotor_ver2/picomotor_ver2/HAPPY_PICO_CONTROL.adl
0 → 100644
View file @
4ddedfdf
file {
name="/opt/rtcds/userapps/release/cds/common/medm/picomotor/HAPPY_PICO_CONTROL.adl"
version=030107
}
display {
object {
x=1944
y=178
width=683
height=202
}
clr=14
bclr=4
cmap=""
gridSpacing=5
gridOn=0
snapToGrid=0
}
"color map" {
ncolors=65
colors {
ffffff,
ececec,
dadada,
c8c8c8,
bbbbbb,
aeaeae,
9e9e9e,
919191,
858585,
787878,
696969,
5a5a5a,
464646,
2d2d2d,
000000,
00d800,
1ebb00,
339900,
2d7f00,
216c00,
fd0000,
de1309,
be190b,
a01207,
820400,
5893ff,
597ee1,
4b6ec7,
3a5eab,
27548d,
fbf34a,
f9da3c,
eeb62b,
e19015,
cd6100,
ffb0ff,
d67fe2,
ae4ebc,
8b1a96,
610a75,
a4aaff,
8793e2,
6a73c1,
4d52a4,
343386,
c7bb6d,
b79d5c,
a47e3c,
7d5627,
58340f,
99ffff,
73dfff,
4ea5f9,
2a63e4,
0a00b8,
ebf1b5,
d4db9d,
bbc187,
a6a462,
8b8239,
73ff6b,
52da3b,
3cb420,
289315,
1a7309,
}
}
rectangle {
object {
x=12
y=49
width=157
height=30
}
"basic attribute" {
clr=56
}
}
text {
object {
x=37
y=58
width=105
height=15
}
"basic attribute" {
clr=14
}
textix="$(PICOID) 1"
align="horiz. centered"
}
"message button" {
object {
x=12
y=135
width=76
height=25
}
control {
chan="$(IFO):PICO-$(PICOID)_1_REV"
clr=14
bclr=4
}
label="<< REV"
press_msg="1"
release_msg="0"
}
"message button" {
object {
x=93
y=135
width=76
height=25
}
control {
chan="$(IFO):PICO-$(PICOID)_1_FWD"
clr=14
bclr=4
}
label="FWD >>"
press_msg="1"
release_msg="0"
}
rectangle {
object {
x=12
y=85
width=76
height=20
}
"basic attribute" {
clr=2
}
}
"text entry" {
object {
x=93
y=105
width=76
height=25
}
control {
chan="$(IFO):PICO-$(PICOID)_1_POSITION"
clr=14
bclr=4
}
format="truncated"
limits {
}
}
text {
object {
x=27
y=88
width=48
height=15
}
"basic attribute" {
clr=14
}
textix="STEP"
align="horiz. centered"
}
"text entry" {
object {
x=12
y=105
width=76
height=25
}
control {
chan="$(IFO):PICO-$(PICOID)_1_STEP"
clr=14
bclr=4
}
format="truncated"
limits {
}
}
rectangle {
object {
x=93
y=85
width=76
height=20
}
"basic attribute" {
clr=2
}
}
text {
object {
x=105
y=88
width=48
height=15
}
"basic attribute" {
clr=14
}
textix="TOTAL "
align="horiz. centered"
}
"message button" {
object {
x=12
y=165
width=26
height=25
}
control {
chan="$(IFO):PICO-$(PICOID)_STATUS"
clr=14
bclr=4
}
label="?"
press_msg="1"
release_msg="0"
}
"text entry" {
object {
x=42
y=165
width=630
height=25
}
control {
chan="$(IFO):PICO-$(PICOID)_ERRORMESSAGE"
clr=14
bclr=4
}
format="string"
limits {
}
}
bar {
object {
x=12
y=195
width=157
height=3
}
monitor {
chan="$(IFO):PICO-$(PICOID)_1_HOGE"
clr=20
bclr=5
}
label="no decorations"
limits {
}
}
rectangle {
object {
x=179
y=49
width=157
height=30
}
"basic attribute" {
clr=56
}
}
text {
object {
x=204
y=58
width=105
height=15
}
"basic attribute" {
clr=14
}
textix="$(PICOID) 2"
align="horiz. centered"
}
"message button" {
object {
x=179
y=135
width=76
height=25
}
control {
chan="$(IFO):PICO-$(PICOID)_2_REV"
clr=14
bclr=4
}
label="<< REV"
press_msg="1"
release_msg="0"
}
"message button" {
object {
x=259
y=135
width=76
height=25
}
control {
chan="$(IFO):PICO-$(PICOID)_2_FWD"
clr=14
bclr=4
}
label="FWD >>"
press_msg="1"
release_msg="0"
}
rectangle {
object {
x=179
y=85
width=76
height=20
}
"basic attribute" {
clr=2
}
}
"text entry" {
object {
x=259
y=105
width=76
height=25
}
control {
chan="$(IFO):PICO-$(PICOID)_2_POSITION"
clr=14
bclr=4
}
format="truncated"
limits {
}
}
text {
object {
x=193
y=88
width=48
height=15
}
"basic attribute" {
clr=14
}
textix="STEP"
align="horiz. centered"
}
"text entry" {
object {
x=179
y=105
width=76
height=25
}
control {
chan="$(IFO):PICO-$(PICOID)_2_STEP"
clr=14
bclr=4
}
format="truncated"
limits {
}
}
rectangle {
object {
x=259
y=85
width=76
height=20
}
"basic attribute" {
clr=2
}
}
text {
object {
x=272
y=88
width=48
height=15
}
"basic attribute" {
clr=14
}
textix="TOTAL "
align="horiz. centered"
}
bar {
object {
x=179
y=195
width=157
height=3
}
monitor {
chan="$(IFO):PICO-$(PICOID)_2_HOGE"
clr=20
bclr=5
}
label="no decorations"
limits {
}
}
rectangle {
object {
x=346
y=49
width=157
height=30
}
"basic attribute" {
clr=56
}
}
text {
object {
x=371
y=58
width=105
height=15
}
"basic attribute" {
clr=14
}
textix="$(PICOID) 3"
align="horiz. centered"
}
"message button" {
object {
x=346
y=135
width=76
height=25
}
control {
chan="$(IFO):PICO-$(PICOID)_3_REV"
clr=14
bclr=4
}
label="<< REV"
press_msg="1"
release_msg="0"
}
"message button" {
object {
x=427
y=135
width=76
height=25
}
control {
chan="$(IFO):PICO-$(PICOID)_3_FWD"
clr=14
bclr=4
}
label="FWD >>"
press_msg="1"
release_msg="0"
}
rectangle {
object {
x=346
y=85
width=76
height=20
}
"basic attribute" {
clr=2
}
}
"text entry" {
object {
x=427
y=105
width=76
height=25
}
control {
chan="$(IFO):PICO-$(PICOID)_3_POSITION"
clr=14
bclr=4
}
format="truncated"
limits {
}
}
text {
object {
x=361
y=88
width=48
height=15
}
"basic attribute" {
clr=14
}
textix="STEP"
align="horiz. centered"
}
"text entry" {
object {
x=346
y=105
width=76
height=25
}
control {
chan="$(IFO):PICO-$(PICOID)_3_STEP"
clr=14
bclr=4
}
format="truncated"
limits {
}
}
rectangle {
object {
x=427
y=85
width=76
height=20
}
"basic attribute" {
clr=2
}
}
text {
object {
x=439
y=88
width=48
height=15
}
"basic attribute" {
clr=14
}
textix="TOTAL "
align="horiz. centered"
}
bar {
object {
x=346
y=195
width=157
height=3
}
monitor {
chan="$(IFO):PICO-$(PICOID)_3_HOGE"
clr=20
bclr=5
}
label="no decorations"
limits {
}
}
rectangle {
object {
x=515
y=49
width=157
height=30
}
"basic attribute" {
clr=56
}
}
text {
object {
x=540
y=58
width=105
height=15
}
"basic attribute" {
clr=14
}
textix="$(PICOID) 4"
align="horiz. centered"
}
"message button" {
object {
x=515
y=135
width=76
height=25
}
control {
chan="$(IFO):PICO-$(PICOID)_4_REV"
clr=14
bclr=4
}
label="<< REV"
press_msg="1"
release_msg="0"
}
"message button" {
object {
x=596
y=135
width=76
height=25
}
control {
chan="$(IFO):PICO-$(PICOID)_4_FWD"
clr=14
bclr=4
}
label="FWD >>"
press_msg="1"
release_msg="0"
}
rectangle {
object {
x=515
y=85
width=76
height=20
}
"basic attribute" {
clr=2
}
}
"text entry" {
object {
x=596
y=105
width=76
height=25
}
control {
chan="$(IFO):PICO-$(PICOID)_4_POSITION"
clr=14
bclr=4
}
format="truncated"
limits {
}
}
text {
object {
x=530
y=88
width=48
height=15
}
"basic attribute" {
clr=14
}
textix="STEP"
align="horiz. centered"
}
"text entry" {
object {
x=515
y=105
width=76
height=25
}
control {
chan="$(IFO):PICO-$(PICOID)_4_STEP"
clr=14
bclr=4
}
format="truncated"
limits {
}
}
rectangle {
object {
x=596
y=85
width=76
height=20
}
"basic attribute" {
clr=2
}
}
text {
object {
x=608
y=88
width=48
height=15
}
"basic attribute" {
clr=14
}
textix="TOTAL "
align="horiz. centered"
}
bar {
object {
x=515
y=195
width=157
height=3
}
monitor {
chan="$(IFO):PICO-$(PICOID)_4_HOGE"
clr=20
bclr=5
}
label="no decorations"
limits {
}
}
text {
object {
x=13
y=14
width=180
height=15
}
"basic attribute" {
clr=14
}
textix="Newfocus 8742 for $(PICOID)"
align="horiz. centered"
}
picomotor_ver2/picomotor_ver2/HAPPY_PICO_MASTER.adl
0 → 100644
View file @
4ddedfdf
This diff is collapsed.
Click to expand it.
picomotor_ver2/picomotor_ver2/HAPPY_PICO_MASTER_BAK.adl
0 → 100644
View file @
4ddedfdf
This diff is collapsed.
Click to expand it.
picomotor_ver2/picomotor_ver2/HAPPY_TEST.adl
0 → 100644
View file @
4ddedfdf
file {
name="/opt/rtcds/userapps/release/cds/common/scripts/picomotor_ver2/picomotor_ver2/HAPPY_TEST.adl"
version=030107
}
display {
object {
x=3051
y=450
width=400
height=400
}
clr=14
bclr=4
cmap=""
gridSpacing=5
gridOn=0
snapToGrid=0
}
"color map" {
ncolors=65
colors {
ffffff,
ececec,
dadada,
c8c8c8,
bbbbbb,
aeaeae,
9e9e9e,
919191,
858585,
787878,
696969,
5a5a5a,
464646,
2d2d2d,
000000,
00d800,
1ebb00,
339900,
2d7f00,
216c00,
fd0000,
de1309,
be190b,
a01207,
820400,
5893ff,
597ee1,
4b6ec7,
3a5eab,
27548d,
fbf34a,
f9da3c,
eeb62b,
e19015,
cd6100,
ffb0ff,
d67fe2,
ae4ebc,
8b1a96,
610a75,
a4aaff,
8793e2,
6a73c1,
4d52a4,
343386,
c7bb6d,
b79d5c,
a47e3c,
7d5627,
58340f,
99ffff,
73dfff,
4ea5f9,
2a63e4,
0a00b8,
ebf1b5,
d4db9d,
bbc187,
a6a462,
8b8239,
73ff6b,
52da3b,
3cb420,
289315,
1a7309,
}
}
"related display" {
object {
x=56
y=95
width=150
height=30
}
display[0] {
label="1"
name="HAPPY_PICO_CONTROL.adl"
args="IFO=K1,PICOID=MCO"
}
clr=14
bclr=55
label="TEST"
}
"shell command" {
object {
x=83
y=154
width=165
height=44
}
command[0] {
label="start pico"
name="/kagra/Dropbox/Personal/miyo/script/newpicomotor/picoepics/pcaspico.py"
}
clr=14
bclr=55
}
"related display" {
object {
x=88
y=258
width=150
height=30
}
display[0] {
label="1"
name="HAPPY_PICO_CONTROL.adl"
args="IFO=K1,PICOID=PRM_IM,DOF=1"
}
display[1] {
label="2"
name="HAPPY_PICO_CONTROL.adl"
args="IFO=K1,PICOID=PRM_IM,DOF=2"
}
display[2] {
label="3"
name="HAPPY_PICO_CONTROL.adl"
args="IFO=K1,PICOID=PRM_IM,DOF=3"
}
display[3] {
label="4"
name="HAPPY_PICO_CONTROL.adl"
args="IFO=K1,PICOID=PRM_IM,DOF=4"
}
clr=14
bclr=55
label="TEST"
}
picomotor_ver2/picomotor_ver2/HAPPY_TEST_BAK.adl
0 → 100644
View file @
4ddedfdf
file {
name="/opt/rtcds/userapps/trunk/cds/common/scripts/picomotor_ver2/picomotor_ver2/HAPPY_TEST.adl"
version=030107
}
display {
object {
x=3051
y=450
width=400
height=400
}
clr=14
bclr=4
cmap=""
gridSpacing=5
gridOn=0
snapToGrid=0
}
"color map" {
ncolors=65
colors {
ffffff,
ececec,
dadada,
c8c8c8,
bbbbbb,
aeaeae,
9e9e9e,
919191,
858585,
787878,
696969,
5a5a5a,
464646,
2d2d2d,
000000,
00d800,
1ebb00,
339900,
2d7f00,
216c00,
fd0000,
de1309,
be190b,
a01207,
820400,
5893ff,
597ee1,
4b6ec7,
3a5eab,
27548d,
fbf34a,
f9da3c,
eeb62b,
e19015,
cd6100,
ffb0ff,
d67fe2,
ae4ebc,
8b1a96,
610a75,
a4aaff,
8793e2,
6a73c1,
4d52a4,
343386,
c7bb6d,
b79d5c,
a47e3c,
7d5627,
58340f,
99ffff,
73dfff,
4ea5f9,
2a63e4,
0a00b8,
ebf1b5,
d4db9d,
bbc187,
a6a462,
8b8239,
73ff6b,
52da3b,
3cb420,
289315,
1a7309,
}
}
"related display" {
object {
x=56
y=95
width=150
height=30
}
display[0] {
label="1"
name="HAPPY_PICO_CONTROL.adl"
args="IFO=K1,PICOID=PR2_IM"
}
clr=14
bclr=55
label="TEST"
}
"shell command" {
object {
x=83
y=154
width=165
height=44
}
command[0] {
label="start pico"
name="/kagra/Dropbox/Personal/miyo/script/newpicomotor/picoepics/pcaspico.py"
}
clr=14
bclr=55
}
"related display" {
object {
x=88
y=258
width=150
height=30
}
display[0] {
label="1"
name="HAPPY_PICO_CONTROL.adl"
args="IFO=K1,PICOID=PRM_IM,DOF=1"
}
display[1] {
label="2"
name="HAPPY_PICO_CONTROL.adl"
args="IFO=K1,PICOID=PRM_IM,DOF=2"
}
display[2] {
label="3"
name="HAPPY_PICO_CONTROL.adl"
args="IFO=K1,PICOID=PRM_IM,DOF=3"
}
display[3] {
label="4"
name="HAPPY_PICO_CONTROL.adl"
args="IFO=K1,PICOID=PRM_IM,DOF=4"
}
clr=14
bclr=55
label="TEST"
}
picomotor_ver2/picomotor_ver2/Trinamic_control6110.py
0 → 100644
View file @
4ddedfdf
#
# -*- coding:utf-8 -*-
import
socket
import
time
import
logging
import
logging.config
from
__init__
import
get_module_logger
logger
=
get_module_logger
(
__name__
)
class
controller
(
object
):
def
init
(
self
,
ipaddr
):
self
.
ipaddr
=
ipaddr
self
.
port
=
23
self
.
BUFFER_SIZE
=
4096
self
.
reply_message
=
None
self
.
connect
()
self
.
maxModuleCurrent
=
1.6
def
__init__
(
self
):
self
.
commandDict
=
{
'ROR'
:
1
,
'ROL'
:
2
,
'MST'
:
3
,
'MVP'
:
4
,
'SAP'
:
5
,
'GAP'
:
6
,
'STAP'
:
7
,
'RSAP'
:
8
,
'SGP'
:
9
,
'GGP'
:
10
,
'RFS'
:
13
,
'SIO'
:
14
,
'GIO'
:
15
,
'WAIT'
:
27
,
'STOP'
:
28
,
'SCO'
:
30
,
'GCO'
:
31
,
'CCO'
:
32
,
'VER'
:
136
,
'RST'
:
255
}
self
.
position
=
0
self
.
speed
=
0.0
self
.
timeout
=
2.
self
.
writeTimeout
=
0.0
self
.
connected
=
None
self
.
port
=
None
self
.
portName
=
None
self
.
errorDict
=
{
1
:
'Wrong checksum'
,
2
:
'Invalid command'
,
3
:
'Wrong type'
,
4
:
'Invalid value'
,
5
:
'Configuration EEPROM locked'
,
6
:
'Command not available'
}
self
.
maxModuleCurrent
=
1.6
def
connect
(
self
):
logger
.
info
(
'Connecting to {0}:{1}'
.
format
(
self
.
ipaddr
,
self
.
port
))
try
:
netAddr
=
(
self
.
ipaddr
,
self
.
port
)
self
.
netsock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
netsock
.
connect
(
netAddr
)
self
.
netsock
.
setblocking
(
1
)
self
.
netsock
.
settimeout
(
5.0
)
except
socket
.
error
as
e
:
logger
.
info
(
e
)
print
e
print
'Could not connect to {0}:{1}. '
\
'Please check network configuration.'
.
format
(
self
.
ipaddr
,
self
.
port
)
print
'exit..'
exit
()
def
__enter__
(
self
):
#self.connect()
return
self
def
sendCommand
(
self
,
cmd
,
type
,
motor
,
value
):
adr
=
1
try
:
command
=
self
.
commandDict
[
cmd
]
except
KeyError
:
return
'Wrong command'
tmp
=
struct
.
pack
(
'BBBBi'
,
adr
,
command
,
type
,
motor
,
value
)
checksum
=
sum
(
struct
.
unpack
(
'BBBBBBBB'
,
tmp
))
%
256
TxBuffer
=
struct
.
pack
(
'>BBBBiB'
,
adr
,
command
,
type
,
motor
,
value
,
checksum
)
if
self
.
connected
==
'RS485'
:
if
self
.
port
.
inWaiting
()
>
0
:
self
.
port
.
flushInput
()
self
.
port
.
flushOutput
()
self
.
port
.
write
(
TxBuffer
)
elif
self
.
connected
==
'TCP'
:
self
.
port
.
send
(
TxBuffer
)
return
TxBuffer
def
read
(
self
):
hoge
=
''
def
reconnect
(
self
):
print
'Reconnecting...'
if
self
.
connected
==
'RS485'
:
self
.
close
()
self
.
connectRS485
(
self
.
portName
,
self
.
baudrate
)
elif
self
.
connected
==
'TCP'
:
self
.
close
()
self
.
connectTCP
(
self
.
portName
[
0
],
self
.
portName
[
1
])
print
'Testing connection:'
self
.
sendCommand
(
'GAP'
,
1
,
0
,
0
)
if
self
.
connected
==
'RS485'
:
RxBuffer
=
self
.
port
.
read
(
9
)
elif
self
.
connected
==
'TCP'
:
RxBuffer
=
self
.
port
.
recv
(
9
)
else
:
RxBuffer
=
''
if
RxBuffer
.
__len__
()
!=
9
:
status
=
0
self
.
close
()
raise
MotorError
(
'Reconnection failed.'
)
else
:
status
=
1
print
'...ok'
return
status
def
connectTCP
(
self
,
ipadr
,
port
):
self
.
port
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
try
:
self
.
port
.
connect
((
ipadr
,
port
))
self
.
port
.
settimeout
(
self
.
timeout
)
self
.
connected
=
'TCP'
self
.
portName
=
[
ipadr
,
port
]
except
Exception
,
e
:
print
'Could not connect to TCP'
,
e
def
send
(
self
,
sendString
):
logger
.
info
(
'Send "{1}" to {0}'
.
format
(
self
.
ipaddr
,
sendString
))
def
close
(
self
):
logger
.
info
(
'Closing controller {0}'
.
format
(
self
.
ipaddr
))
self
.
netsock
.
close
()
logger
.
info
(
'OK. Bye {0}'
.
format
(
self
.
ipaddr
))
def
__exit__
(
self
,
type
,
value
,
traceback
):
self
.
close
()
class
driver
(
controller
):
def
__init__
(
self
,
ipaddr
):
super
(
driver
,
self
).
init
(
ipaddr
)
#super(driver,self).__init__()
#super(driver,self).init(ipaddr)
#print "here"
def
__enter__
(
self
):
super
(
driver
,
self
).
__enter__
()
return
self
def
ask_driver_error
(
self
):
self
.
send
(
'TE?'
)
def
ask_position
(
self
,
driverAddr
,
motorAddr
):
self
.
send
(
'%sTP?'
%
(
motorAddr
))
def
ask_speed
(
self
,
driverAddr
,
motorAddr
):
self
.
send
(
'%sVA?'
%
(
motorAddr
))
def
check_reply_message
(
self
):
self
.
read
()
logger
.
info
(
'Reply message is "{0}"'
.
format
(
self
.
reply_message
))
return
self
.
reply_message
def
check_error_message
(
self
):
self
.
read
()
return
errorMessage
[
int
(
self
.
reply_message
)]
def
set_vel
(
self
,
driverAddr
,
motorAddr
,
vel
):
""" Max velocity
standard motor : 2000[step/sec] maybe..
tiny motor : 1750[step/sec]
"""
self
.
send
(
'%s>%sVA%s'
%
(
driverAddr
,
motorAddr
,
vel
))
def
set_acc
(
self
,
driverAddr
,
motorAddr
,
acc
):
self
.
send
(
'%s>%sAC%s'
%
(
driverAddr
,
motorAddr
,
acc
))
def
move_step
(
self
,
driverAddr
,
motorAddr
,
count
):
self
.
send
(
'%s>%sPR%d'
%
(
driverAddr
,
motorAddr
,
count
))
def
stop_motor
(
self
,
driverAddr
,
motorAddr
):
self
.
send
(
'%s>%sST'
%
(
driverAddr
,
motorAddr
))
def
abort
(
self
):
self
.
send
(
'AB'
)
def
soft_stop
(
self
):
self
.
send
(
'ST'
)
def
restart
(
self
):
self
.
send
(
'RS'
)
def
__exit__
(
self
,
type
,
value
,
traceback
):
#self.stop_motor("1","1") # stop all motor
super
(
driver
,
self
).
__exit__
(
type
,
value
,
traceback
)
def
getTargetPosition
(
self
):
cmd
=
'GAP'
# Get axis parameter
type
=
4
# Target speed... maybe use 4 (max pos speed)?
value
=
0
# don't care
motor
=
1
self
.
sendCommand
(
cmd
,
type
,
motor
,
value
)
data
=
self
.
receiveData
()
if
data
.
status
!=
100
:
if
self
.
errorDict
.
has_key
(
data
.
status
):
raise
MotorError
(
self
.
errorDict
[
data
.
status
])
elif
data
.
status
==
None
:
raise
MotorError
(
'Incorrect controller response, trying to reconnect'
)
else
:
raise
MotorError
(
''
.
join
((
'Unknown error, '
,
str
(
data
.
status
))))
return
data
.
value
if
__name__
==
"__main__"
:
with
driver
(
"172.168.1.60"
)
as
k1stepper
:
#,4001
k1stepper
.
reconnect
()
k1stepper
.
set_vel
(
1
,
1
,
1000
)
k1stepper
.
set_acc
(
1
,
1
,
500
)
k1stepper
.
move_step
(
1
,
1
,
1000
)
k1stepper
.
check_reply_message
()
#print k1stepper.getTargetPosition()
picomotor_ver2/picomotor_ver2/Trinamic_control6110_edit.py
0 → 100644
View file @
4ddedfdf
#
# -*- coding:utf-8 -*-
import
socket
import
time
import
logging
import
logging.config
from
__init__
import
get_module_logger
logger
=
get_module_logger
(
__name__
)
class
controller
(
object
):
def
init
(
self
,
ipaddr
):
self
.
ipaddr
=
ipaddr
self
.
port
=
23
self
.
BUFFER_SIZE
=
4096
self
.
reply_message
=
None
self
.
connect
()
self
.
maxModuleCurrent
=
1.6
def
__init__
(
self
):
self
.
commandDict
=
{
'ROR'
:
1
,
'ROL'
:
2
,
'MST'
:
3
,
'MVP'
:
4
,
'SAP'
:
5
,
'GAP'
:
6
,
'STAP'
:
7
,
'RSAP'
:
8
,
'SGP'
:
9
,
'GGP'
:
10
,
'RFS'
:
13
,
'SIO'
:
14
,
'GIO'
:
15
,
'WAIT'
:
27
,
'STOP'
:
28
,
'SCO'
:
30
,
'GCO'
:
31
,
'CCO'
:
32
,
'VER'
:
136
,
'RST'
:
255
}
self
.
position
=
0
self
.
speed
=
0.0
self
.
timeout
=
2.
self
.
writeTimeout
=
0.0
self
.
connected
=
None
self
.
port
=
None
self
.
portName
=
None
self
.
errorDict
=
{
1
:
'Wrong checksum'
,
2
:
'Invalid command'
,
3
:
'Wrong type'
,
4
:
'Invalid value'
,
5
:
'Configuration EEPROM locked'
,
6
:
'Command not available'
}
self
.
maxModuleCurrent
=
1.6
def
connect
(
self
):
logger
.
info
(
'Connecting to {0}:{1}'
.
format
(
self
.
ipaddr
,
self
.
port
))
try
:
netAddr
=
(
self
.
ipaddr
,
self
.
port
)
self
.
netsock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
netsock
.
connect
(
netAddr
)
self
.
netsock
.
setblocking
(
1
)
self
.
netsock
.
settimeout
(
5.0
)
except
socket
.
error
as
e
:
logger
.
info
(
e
)
print
e
print
'Could not connect to {0}:{1}. '
\
'Please check network configuration.'
.
format
(
self
.
ipaddr
,
self
.
port
)
print
'exit..'
exit
()
def
__enter__
(
self
):
#self.connect()
return
self
def
sendCommand
(
self
,
cmd
,
type
,
motor
,
value
):
adr
=
1
try
:
command
=
self
.
commandDict
[
cmd
]
except
KeyError
:
return
'Wrong command'
tmp
=
struct
.
pack
(
'BBBBi'
,
adr
,
command
,
type
,
motor
,
value
)
checksum
=
sum
(
struct
.
unpack
(
'BBBBBBBB'
,
tmp
))
%
256
TxBuffer
=
struct
.
pack
(
'>BBBBiB'
,
adr
,
command
,
type
,
motor
,
value
,
checksum
)
if
self
.
connected
==
'RS485'
:
if
self
.
port
.
inWaiting
()
>
0
:
self
.
port
.
flushInput
()
self
.
port
.
flushOutput
()
self
.
port
.
write
(
TxBuffer
)
elif
self
.
connected
==
'TCP'
:
self
.
port
.
send
(
TxBuffer
)
return
TxBuffer
def
read
(
self
):
hoge
=
''
def
reconnect
(
self
):
print
'Reconnecting...'
if
self
.
connected
==
'RS485'
:
self
.
close
()
self
.
connectRS485
(
self
.
portName
,
self
.
baudrate
)
elif
self
.
connected
==
'TCP'
:
self
.
close
()
self
.
connectTCP
(
self
.
portName
[
0
],
self
.
portName
[
1
])
print
'Testing connection:'
self
.
sendCommand
(
'GAP'
,
1
,
0
,
0
)
if
self
.
connected
==
'RS485'
:
RxBuffer
=
self
.
port
.
read
(
9
)
elif
self
.
connected
==
'TCP'
:
RxBuffer
=
self
.
port
.
recv
(
9
)
else
:
RxBuffer
=
''
if
RxBuffer
.
__len__
()
!=
9
:
status
=
0
self
.
close
()
raise
MotorError
(
'Reconnection failed.'
)
else
:
status
=
1
print
'...ok'
return
status
def
connectTCP
(
self
,
ipadr
,
port
):
self
.
port
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
try
:
self
.
port
.
connect
((
ipadr
,
port
))
self
.
port
.
settimeout
(
self
.
timeout
)
self
.
connected
=
'TCP'
self
.
portName
=
[
ipadr
,
port
]
except
Exception
,
e
:
print
'Could not connect to TCP'
,
e
def
send
(
self
,
sendString
):
logger
.
info
(
'Send "{1}" to {0}'
.
format
(
self
.
ipaddr
,
sendString
))
def
close
(
self
):
logger
.
info
(
'Closing controller {0}'
.
format
(
self
.
ipaddr
))
self
.
netsock
.
close
()
logger
.
info
(
'OK. Bye {0}'
.
format
(
self
.
ipaddr
))
def
__exit__
(
self
,
type
,
value
,
traceback
):
self
.
close
()
class
driver
(
controller
):
def
__init__
(
self
,
ipaddr
):
super
(
driver
,
self
).
init
(
ipaddr
)
#super(driver,self).__init__()
#super(driver,self).init(ipaddr)
def
__enter__
(
self
):
super
(
driver
,
self
).
__enter__
()
return
self
def
ask_driver_error
(
self
):
self
.
send
(
'TE?'
)
def
ask_position
(
self
,
driverAddr
,
motorAddr
):
self
.
send
(
'%sTP?'
%
(
motorAddr
))
def
ask_speed
(
self
,
driverAddr
,
motorAddr
):
self
.
send
(
'%sVA?'
%
(
motorAddr
))
def
check_reply_message
(
self
):
self
.
read
()
logger
.
info
(
'Reply message is "{0}"'
.
format
(
self
.
reply_message
))
return
self
.
reply_message
def
check_error_message
(
self
):
self
.
read
()
return
errorMessage
[
int
(
self
.
reply_message
)]
def
set_vel
(
self
,
driverAddr
,
motorAddr
,
vel
):
""" Max velocity
standard motor : 2000[step/sec] maybe..
tiny motor : 1750[step/sec]
"""
self
.
send
(
'%s>%sVA%s'
%
(
driverAddr
,
motorAddr
,
vel
))
def
set_acc
(
self
,
driverAddr
,
motorAddr
,
acc
):
self
.
send
(
'%s>%sAC%s'
%
(
driverAddr
,
motorAddr
,
acc
))
def
move_step
(
self
,
driverAddr
,
motorAddr
,
count
):
self
.
send
(
'%s>%sPR%d'
%
(
driverAddr
,
motorAddr
,
count
))
def
stop_motor
(
self
,
driverAddr
,
motorAddr
):
self
.
send
(
'%s>%sST'
%
(
driverAddr
,
motorAddr
))
def
abort
(
self
):
self
.
send
(
'AB'
)
def
soft_stop
(
self
):
self
.
send
(
'ST'
)
def
restart
(
self
):
self
.
send
(
'RS'
)
def
__exit__
(
self
,
type
,
value
,
traceback
):
#self.stop_motor("1","1") # stop all motor
super
(
driver
,
self
).
__exit__
(
type
,
value
,
traceback
)
def
getTargetPosition
(
self
):
cmd
=
'GAP'
# Get axis parameter
type
=
4
# Target speed... maybe use 4 (max pos speed)?
value
=
0
# don't care
motor
=
1
self
.
sendCommand
(
cmd
,
type
,
motor
,
value
)
data
=
self
.
receiveData
()
if
data
.
status
!=
100
:
if
self
.
errorDict
.
has_key
(
data
.
status
):
raise
MotorError
(
self
.
errorDict
[
data
.
status
])
elif
data
.
status
==
None
:
raise
MotorError
(
'Incorrect controller response, trying to reconnect'
)
else
:
raise
MotorError
(
''
.
join
((
'Unknown error, '
,
str
(
data
.
status
))))
return
data
.
value
if
__name__
==
"__main__"
:
with
driver
(
"172.168.1.60"
)
as
k1stepper
:
#,4001
#k1stepper.reconnect()
k1stepper
.
restart
()
k1stepper
.
set_vel
(
1
,
1
,
1750
)
k1stepper
.
set_acc
(
1
,
1
,
10000
)
k1stepper
.
move_step
(
1
,
1
,
1000
)
#print k1stepper.getTargetPosition()
picomotor_ver2/picomotor_ver2/__init__.py
0 → 100644
View file @
4ddedfdf
"""
this is for adl MIYOPICO_ver1.adl.
"""
import
logging
def
get_module_logger
(
modname
):
#logging.config.fileConfig('logging.conf')
logging
.
config
.
fileConfig
(
'/home/controls/Desktop/picomotor_ver2/picomotor_ver2/logging.conf'
)
logger
=
logging
.
getLogger
(
'logExample'
)
return
logger
picomotor_ver2/picomotor_ver2/__init__.pyc
0 → 100644
View file @
4ddedfdf
File added
picomotor_ver2/picomotor_ver2/__main__.py
0 → 100644
View file @
4ddedfdf
import
pcaspico
import
newfocus8742
import
sys
import
time
import
logging
import
logging.config
from
__init__
import
get_module_logger
logger
=
get_module_logger
(
__name__
)
try
:
prefix
=
sys
.
argv
[
1
]
driverIP
=
sys
.
argv
[
2
]
#import subprocess
#pl = subprocess.Popen('ps alx | grep {0}'.format(prefix,driverIP),shell=True,stdout=subprocess.PIPE).communicate()[0]
#print pl
#exit()
except
IndexError
:
sys
.
exit
(
"python2 -m K1:PICO-MCI_IM_ 172.168.1.60."
)
print
prefix
,
driverIP
picoserver
=
pcaspico
.
PcasServer
(
prefix
,
newfocus8742
.
driver
(
driverIP
))
try
:
logger
.
info
(
"Start server!"
)
picoserver
.
run
()
except
KeyboardInterrupt
:
mydriver
.
close
()
print
e
print
'Detect keyboard interrupt. Bye!'
#logger.info("KeyboardInterrupt")
#logger.info("Bye")
exit
()
pass
'''
try:
picoserver.run()
except KeyboardInterrupt as e:
mydriver.close()
print e
print 'Detect keyboard interrupt. Bye!'
exit()
'''
picomotor_ver2/picomotor_ver2/config.py
0 → 100644
View file @
4ddedfdf
def
pvdb_dof
(
i
):
_REV
=
'{0}_REV'
.
format
(
i
)
_FWD
=
'{0}_FWD'
.
format
(
i
)
_POSITION
=
'{0}_POSITION'
.
format
(
i
)
_STEP
=
'{0}_STEP'
.
format
(
i
)
_SPEED
=
'{0}_SPEED'
.
format
(
i
)
pvdb
=
{
_REV
:
{
'prec'
:
4
,
'value'
:
0
,
},
_FWD
:
{
'prec'
:
4
,
'value'
:
0
,
},
_POSITION
:
{
'prec'
:
10
,
'value'
:
0
,
},
_STEP
:
{
'prec'
:
5
,
'value'
:
34
,
},
_SPEED
:
{
'prec'
:
4
,
'value'
:
500
,
},
}
return
pvdb
pvdb
=
pvdb_dof
(
1
)
pvdb
.
update
(
pvdb_dof
(
2
))
pvdb
.
update
(
pvdb_dof
(
3
))
pvdb
.
update
(
pvdb_dof
(
4
))
_ERROR
=
'ERROR'
_ERRORMESSAGE
=
'ERRORMESSAGE'
_STATUS
=
'STATUS'
_COMMAND
=
'COMMAND'
dic
=
{
\
_ERROR
:
{
'prec'
:
3
,
'value'
:
0
,
},
_ERRORMESSAGE
:
{
'type'
:
'string'
,
},
_STATUS
:
{
'prec'
:
3
,
'value'
:
0
,
},
_COMMAND
:
{
'type'
:
'string'
,
},
}
pvdb
.
update
(
dic
)
if
__name__
==
'__main__'
:
print
pvdb
picomotor_ver2/picomotor_ver2/config.pyc
0 → 100644
View file @
4ddedfdf
File added
picomotor_ver2/picomotor_ver2/example.log
0 → 100644
View file @
4ddedfdf
picomotor_ver2/picomotor_ver2/log.txt
0 → 100644
View file @
4ddedfdf
This diff is collapsed.
Click to expand it.
picomotor_ver2/picomotor_ver2/logging.conf
0 → 100644
View file @
4ddedfdf
[
loggers
]
keys
=
root
,
logExample
[
handlers
]
keys
=
consoleHandler
,
fileHandler
[
formatters
]
keys
=
logFormatter
[
logger_root
]
level
=
DEBUG
handlers
=
consoleHandler
[
logger_logExample
]
level
=
DEBUG
handlers
=
consoleHandler
,
fileHandler
qualname
=
logExample
propagate
=
0
[
handler_consoleHandler
]
class
=
StreamHandler
level
=
DEBUG
formatter
=
logFormatter
args
=(
sys
.
stdout
,)
[
handler_fileHandler
]
#class=handlers.RotatingFileHandler
class
=
FileHandler
level
=
DEBUG
formatter
=
logFormatter
args
=(
'pico.log'
,)
#args=('log.log', 'S', 1, 10)
[
formatter_logFormatter
]
format
=%(
asctime
)
s
- %(
name
)
s
- %(
levelname
)
s
- %(
message
)
s
#
datefmt
=
\ No newline at end of file
picomotor_ver2/picomotor_ver2/newfocus8742.py
0 → 100644
View file @
4ddedfdf
#
#!coding:utf-8
import
socket
#import select
import
time
import
logging
import
logging.config
from
__init__
import
get_module_logger
logger
=
get_module_logger
(
__name__
)
errorMessage
=
\
{
-
1
:
"TIMEOUT"
,
0
:
"NO ERROR DETECTED"
,
3
:
"OVER TEMPERATURE SHUTDOWN"
,
6
:
"COMMAND DOES NOT EXIST"
,
7
:
"PARAMETER OUT OF RANGE"
,
9
:
"AXIS NUMBER OUT OF RANGE"
,
10
:
"EEPROM WRITE FAILED"
,
11
:
"EEPROM READ FAILED"
,
37
:
"AXIS NUMBER MISSING"
,
38
:
"COMMAND PARAMETER MISSING"
,
46
:
"RS-485 ETX FAULT DETECTED"
,
47
:
"RS-485 CRC FAULT DETECTED"
,
48
:
"CONTROLLER NUMBER OUT OF RANGE"
,
49
:
"SCAN IN PROGRESS"
,
100
:
"MOTOR_1 TYPE NOT DEFINED"
,
200
:
"MOTOR_2 TYPE NOT DEFINED"
,
300
:
"MOTOR_3 TYPE NOT DEFINED"
,
400
:
"MOTOR_4 TYPE NOT DEFINED"
,
101
:
"MOTOR_1 PARAMETER OUT OF RANGE"
,
102
:
"MOTOR_2 PARAMETER OUT OF RANGE"
,
103
:
"MOTOR_3 PARAMETER OUT OF RANGE"
,
104
:
"MOTOR_4 PARAMETER OUT OF RANGE"
,
108
:
"MOTOR_1 NOT CONNECTED"
,
208
:
"MOTOR_2 NOT CONNECTED"
,
308
:
"MOTOR_3 NOT CONNECTED"
,
408
:
"MOTOR_4 NOT CONNECTED"
,
110
:
"MOTOR_1 MAXIMUM VELOCITY EXCEEDED"
,
210
:
"MOTOR_2 MAXIMUM VELOCITY EXCEEDED"
,
310
:
"MOTOR_3 MAXIMUM VELOCITY EXCEEDED"
,
410
:
"MOTOR_4 MAXIMUM VELOCITY EXCEEDED"
,
111
:
"MOTOR_1 MAXIMUM ACCELERATION EXCEEDED"
,
211
:
"MOTOR_2 MAXIMUM ACCELERATION EXCEEDED"
,
311
:
"MOTOR_3 MAXIMUM ACCELERATION EXCEEDED"
,
411
:
"MOTOR_4 MAXIMUM ACCELERATION EXCEEDED"
,
114
:
"MOTOR_1 MOTION IN PROGRESS"
,
214
:
"MOTOR_2 MOTION IN PROGRESS"
,
314
:
"MOTOR_3 MOTION IN PROGRESS"
,
414
:
"MOTOR_4 MOTION IN PROGRESS"
,
}
class
controller
(
object
):
def
__init__
(
self
,
ipaddr
):
self
.
ipaddr
=
ipaddr
self
.
port
=
23
self
.
BUFFER_SIZE
=
4096
self
.
reply_message
=
None
self
.
connect
()
def
connect
(
self
):
logger
.
info
(
'Connecting to {0}:{1}'
.
format
(
self
.
ipaddr
,
self
.
port
))
try
:
netAddr
=
(
self
.
ipaddr
,
self
.
port
)
self
.
netsock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
netsock
.
connect
(
netAddr
)
self
.
netsock
.
setblocking
(
1
)
self
.
netsock
.
settimeout
(
1.0
)
except
socket
.
error
as
e
:
logger
.
info
(
e
)
print
e
print
'Could not connect to {0}:{1}. '
\
'Please check network configuration.'
.
format
(
self
.
ipaddr
,
self
.
port
)
print
'exit..'
exit
()
except
Exception
as
e
:
logger
.
info
(
e
)
print
e
exit
()
def
__enter__
(
self
):
#self.connect()
return
self
def
read
(
self
):
time
.
sleep
(
0.1
)
#print time.sleep
try
:
data
=
self
.
netsock
.
recv
(
self
.
BUFFER_SIZE
)
data
=
data
.
replace
(
'
\xff\xfb\x01\xff\xfb\x03
'
,
''
)
#print "2",data
data
=
data
.
replace
(
'
\r\n
'
,
''
)
text
=
([
chr
(
ord
(
i
))
for
i
in
data
])
data
=
int
(
''
.
join
(
text
))
#print "3",data
self
.
reply_message
=
data
except
Exception
as
e
:
logger
.
warning
(
e
)
logger
.
warning
(
'failed data receiving'
)
self
.
reply_message
=
-
1
def
send
(
self
,
sendString
):
logger
.
info
(
'Send "{1}" to {0}'
.
format
(
self
.
ipaddr
,
sendString
))
try
:
self
.
netsock
.
send
(
sendString
+
'
\n
'
)
except
socket
.
error
as
e
:
logger
.
info
(
e
)
logger
.
info
(
"Reconnecting.."
)
self
.
connect
()
except
Exception
as
e
:
logger
.
info
(
e
)
print
type
(
e
)
print
dir
(
e
)
logger
.
info
(
"Exit. Bye"
)
exit
()
def
close
(
self
):
logger
.
info
(
'Closing controller {0}'
.
format
(
self
.
ipaddr
))
self
.
netsock
.
close
()
logger
.
info
(
'OK. Bye {0}'
.
format
(
self
.
ipaddr
))
def
__exit__
(
self
,
type
,
value
,
traceback
):
self
.
close
()
class
driver
(
controller
):
def
__init__
(
self
,
ipaddr
):
super
(
driver
,
self
).
__init__
(
ipaddr
)
self
.
ipaddr
=
ipaddr
#self.set_acc(2,1,500)
#self.set_vel(2,1,500)
def
__enter__
(
self
):
super
(
driver
,
self
).
__enter__
()
return
self
def
reconnect
(
self
):
self
.
__init__
(
self
.
ipaddr
)
def
ask_driver_error
(
self
):
self
.
send
(
'TE?'
)
def
ask_position
(
self
,
driverAddr
,
motorAddr
):
self
.
send
(
'%sTP?'
%
(
motorAddr
))
def
ask_speed
(
self
,
driverAddr
,
motorAddr
):
self
.
send
(
'%sVA?'
%
(
motorAddr
))
def
check_reply_message
(
self
):
self
.
read
()
logger
.
info
(
'Reply message is "{0}"'
.
format
(
self
.
reply_message
))
return
self
.
reply_message
def
check_error_message
(
self
):
try
:
logger
.
info
(
'Reply message is "{0}"'
.
format
(
errorMessage
[
int
(
self
.
reply_message
)]))
return
errorMessage
[
int
(
self
.
reply_message
)]
except
:
pass
return
-
34
def
set_vel
(
self
,
driverAddr
,
motorAddr
,
vel
):
""" Max velocity
standard motor : 2000[step/sec] maybe..
tiny motor : 1750[step/sec]
"""
self
.
send
(
'%s>%sVA%s'
%
(
driverAddr
,
motorAddr
,
vel
))
def
set_acc
(
self
,
driverAddr
,
motorAddr
,
acc
):
self
.
send
(
'%s>%sAC%s'
%
(
driverAddr
,
motorAddr
,
acc
))
def
move_step
(
self
,
driverAddr
,
motorAddr
,
count
):
self
.
send
(
'%s>%sPR%d'
%
(
driverAddr
,
motorAddr
,
count
))
def
stop_motor
(
self
,
driverAddr
,
motorAddr
):
self
.
send
(
'%s>%sST'
%
(
driverAddr
,
motorAddr
))
def
abort
(
self
):
self
.
send
(
'AB'
)
def
soft_stop
(
self
):
self
.
send
(
'ST'
)
def
restart
(
self
):
self
.
send
(
'RS'
)
def
__exit__
(
self
,
type
,
value
,
traceback
):
self
.
stop_motor
(
"1"
,
"1"
)
# stop all motor
#super(driver,self).__exit__(type, value, traceback)
if
__name__
==
"__main__"
:
with
driver
(
"172.168.1.60"
)
as
k1pico
:
#10.68.150.22
k1pico
.
ask_position
(
2
,
1
)
k1pico
.
set_acc
(
2
,
1
,
1000
)
k1pico
.
set_vel
(
2
,
1
,
1000
)
k1pico
.
move_step
(
2
,
1
,
50000
)
k1pico
.
check_reply_message
()
#k1pico.stop_motor(2,1)
#k1pico.restart()
#k1pico.ask_driver_error()
#k1pico.check_reply_message()
#k1pico.ask_speed(1,1)
#k1pico.check_reply_message()
picomotor_ver2/picomotor_ver2/newfocus8742.pyc
0 → 100644
View file @
4ddedfdf
File added
picomotor_ver2/picomotor_ver2/newfocus8742.py~
0 → 100644
View file @
4ddedfdf
#
#!coding:utf-8
import socket
#import select
import time
import logging
import logging.config
from __init__ import get_module_logger
logger = get_module_logger(__name__)
errorMessage = \
{
-1 :"TIMEOUT",
0 :"NO ERROR DETECTED",
3 :"OVER TEMPERATURE SHUTDOWN",
6 :"COMMAND DOES NOT EXIST",
7 :"PARAMETER OUT OF RANGE",
9 :"AXIS NUMBER OUT OF RANGE",
10 :"EEPROM WRITE FAILED",
11 :"EEPROM READ FAILED",
37 :"AXIS NUMBER MISSING",
38 :"COMMAND PARAMETER MISSING",
46 :"RS-485 ETX FAULT DETECTED",
47 :"RS-485 CRC FAULT DETECTED",
48 :"CONTROLLER NUMBER OUT OF RANGE",
49 :"SCAN IN PROGRESS",
100:"MOTOR_1 TYPE NOT DEFINED",
200:"MOTOR_2 TYPE NOT DEFINED",
300:"MOTOR_3 TYPE NOT DEFINED",
400:"MOTOR_4 TYPE NOT DEFINED",
101:"MOTOR_1 PARAMETER OUT OF RANGE",
102:"MOTOR_2 PARAMETER OUT OF RANGE",
103:"MOTOR_3 PARAMETER OUT OF RANGE",
104:"MOTOR_4 PARAMETER OUT OF RANGE",
108:"MOTOR_1 NOT CONNECTED",
208:"MOTOR_2 NOT CONNECTED",
308:"MOTOR_3 NOT CONNECTED",
408:"MOTOR_4 NOT CONNECTED",
110:"MOTOR_1 MAXIMUM VELOCITY EXCEEDED",
210:"MOTOR_2 MAXIMUM VELOCITY EXCEEDED",
310:"MOTOR_3 MAXIMUM VELOCITY EXCEEDED",
410:"MOTOR_4 MAXIMUM VELOCITY EXCEEDED",
111:"MOTOR_1 MAXIMUM ACCELERATION EXCEEDED",
211:"MOTOR_2 MAXIMUM ACCELERATION EXCEEDED",
311:"MOTOR_3 MAXIMUM ACCELERATION EXCEEDED",
411:"MOTOR_4 MAXIMUM ACCELERATION EXCEEDED",
114:"MOTOR_1 MOTION IN PROGRESS",
214:"MOTOR_2 MOTION IN PROGRESS",
314:"MOTOR_3 MOTION IN PROGRESS",
414:"MOTOR_4 MOTION IN PROGRESS",
}
class controller(object):
def __init__(self,ipaddr):
self.ipaddr = ipaddr
self.port = 23
self.BUFFER_SIZE = 4096
self.reply_message = None
self.connect()
def connect(self):
logger.info('Connecting to {0}:{1}'.format(self.ipaddr,self.port))
try:
netAddr=(self.ipaddr, self.port)
self.netsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.netsock.connect(netAddr)
self.netsock.setblocking(1)
self.netsock.settimeout(1.0)
except socket.error as e:
logger.info(e)
print e
print 'Could not connect to {0}:{1}. '\
'Please check network configuration.'.format(self.ipaddr,self.port)
print 'exit..'
exit()
except Exception as e:
logger.info(e)
print e
exit()
def __enter__(self):
#self.connect()
return self
def read(self):
time.sleep(0.1)
#print time.sleep
try:
data = self.netsock.recv(self.BUFFER_SIZE)
data = data.replace('\xff\xfb\x01\xff\xfb\x03','')
#print "2",data
data = data.replace('\r\n','')
text = ([chr(ord(i)) for i in data])
data = int(''.join(text))
#print "3",data
self.reply_message = data
except Exception as e:
logger.warning(e)
logger.warning('failed data receiving')
self.reply_message = -1
def send(self, sendString):
logger.info('Send "{1}" to {0}'.format(self.ipaddr,sendString))
try:
self.netsock.send(sendString+'\n')
except socket.error as e:
logger.info(e)
logger.info("Reconnecting..")
self.connect()
except Exception as e:
logger.info(e)
print type(e)
print dir(e)
logger.info("Exit. Bye")
exit()
def close(self):
logger.info('Closing controller {0}'.format(self.ipaddr))
self.netsock.close()
logger.info('OK. Bye {0}'.format(self.ipaddr))
def __exit__(self,type, value, traceback):
self.close()
class driver(controller):
def __init__(self,ipaddr):
super(driver,self).__init__(ipaddr)
self.ipaddr = ipaddr
#self.set_acc(2,1,500)
#self.set_vel(2,1,500)
def __enter__(self):
super(driver,self).__enter__()
return self
def reconnect(self):
self.__init__(self.ipaddr)
def ask_driver_error(self):
self.send('TE?')
def ask_position(self,driverAddr,motorAddr):
self.send('%sTP?'%(motorAddr))
def ask_speed(self,driverAddr,motorAddr):
self.send('%sVA?'%(motorAddr))
def check_reply_message(self):
self.read()
logger.info('Reply message is "{0}"'.format(self.reply_message))
return self.reply_message
def check_error_message(self):
try:
logger.info('Reply message is "{0}"'.format(errorMessage[int(self.reply_message)]))
return errorMessage[int(self.reply_message)]
except:
pass
return -34
def set_vel(self,driverAddr,motorAddr,vel):
""" Max velocity
standard motor : 2000[step/sec] maybe..
tiny motor : 1750[step/sec]
"""
self.send('%s>%sVA%s'%(driverAddr,motorAddr,vel))
def set_acc(self,driverAddr,motorAddr,acc):
self.send('%s>%sAC%s'%(driverAddr,motorAddr,acc))
def move_step(self,driverAddr,motorAddr,count):
self.send('%s>%sPR%d'%(driverAddr,motorAddr,count))
def stop_motor(self,driverAddr,motorAddr):
self.send('%s>%sST'%(driverAddr,motorAddr))
def abort(self):
self.send('AB')
def soft_stop(self):
self.send('ST')
def restart(self):
self.send('RS')
def __exit__(self,type, value, traceback):
self.stop_motor("1","1") # stop all motor
#super(driver,self).__exit__(type, value, traceback)
if __name__ == "__main__":
with driver("172.168.1.60") as k1pico:#10.68.150.22
k1pico.ask_position(2,1)
k1pico.set_acc(2,1,1000)
k1pico.set_vel(2,1,1000)
k1pico.move_step(2,1,-100000)
k1pico.check_reply_message()
#k1pico.stop_motor(2,1)
#k1pico.restart()
#k1pico.ask_driver_error()
#k1pico.check_reply_message()
#k1pico.ask_speed(1,1)
#k1pico.check_reply_message()
Prev
1
2
3
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment