robot_controller.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 # FSRobo-R Package BSDL
5 # ---------
6 # Copyright (C) 2019 FUJISOFT. All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without modification,
9 # are permitted provided that the following conditions are met:
10 # 1. Redistributions of source code must retain the above copyright notice,
11 # this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright notice,
13 # this list of conditions and the following disclaimer in the documentation and/or
14 # other materials provided with the distribution.
15 # 3. Neither the name of the copyright holder nor the names of its contributors
16 # may be used to endorse or promote products derived from this software without
17 # specific prior written permission.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 # ---------
30 
31 from cc_client import CCClient
32 
34  def __init__(self, permission = True):
35  self._api = CCClient()
36  if permission:
37  self._api.get_operation_permission()
38 
39  def exec_program(self, path, param=''):
40  return self._api.exec_program(path, param) == 0
41 
42  def set_speed(self, speed):
43  return self._api.set_jspeed(speed) == 0
44 
45  def set_posture(self, posture):
46  return self._api.set_posture(posture) == 0
47 
48  def get_posture(self):
49  data = {}
50  result = self._api.get_posture(data)
51  if result == 0:
52  return data['DA']['P']
53  else:
54  return None
55 
56  def move(self, joint, speed=None):
57  if speed is None:
58  params = joint
59  else:
60  params = joint + [speed]
61  return self._api.qjmove(*params) == 0
62 
63  def abort(self):
64  return self._api.abortm() == 0
65 
66  def sys_stat(self, stat_type):
67  data = {}
68  result = self._api.syssts(stat_type, data)
69  if result == 0:
70  return data['DA']['RE']
71  else:
72  return None
73 
74  def set_tool_offset(self, x, y, z, rz, ry, rx):
75  result = self._api.set_tool(x, y, z, rz, ry, rx)
76 
77  return result == 0
78 
79  def set_dio(self, addr, data):
80  def to_char(x):
81  if x == -1:
82  return '*'
83  else:
84  return str(x)
85  io_list = map(to_char, data)
86  io_list.reverse()
87  io_str = ''.join(io_list)
88  return self._api.set_io(addr, io_str) == 0
89 
90  def get_dio(self, start_addr, end_addr):
91  data = {}
92  result = self._api.get_io(start_addr, end_addr, data)
93  if result == 0:
94  io_str = data['DA']['SL']
95  io_list = list(io_str)
96  io_list.reverse()
97  return io_list
98  else:
99  return []
100 
101  def set_adc_mode(self, ch, mode):
102  return self._api.set_adc(ch, mode) == 0
103 
104  def close(self):
105  self._api.close()
106 
107 if __name__ == '__main__':
109  print ctl.set_speed(100)
110  print ctl.move([0, 0, 0, 0, 0, 0])
111  print ctl.move([22, 23, 24, 30, 33, 10])
112  print ctl.set_dio(0, [0, 0, 0, 0, 0])
113  print ctl.get_dio(0, 31)
114  print ctl.set_dio(0, [1, -1, 1, 0, 0])
115  print ctl.get_dio(0, 31)
116  print ctl.get_posture()
117  print ctl.set_posture(4)
118  print ctl.get_posture()
def move(self, joint, speed=None)
def __init__(self, permission=True)
def get_dio(self, start_addr, end_addr)
def set_tool_offset(self, x, y, z, rz, ry, rx)
def exec_program(self, path, param='')


fsrobo_r_driver
Author(s): F-ROSROBO
autogenerated on Sun Feb 9 2020 03:58:29