Compare commits

...

13 Commits

Author SHA1 Message Date
80b911dd8d update paths 2023-05-10 19:07:16 -05:00
e261452350 chain 2023-05-10 15:17:56 -05:00
0d84232a56 update code 2023-05-10 13:38:54 -05:00
e329c893d7 add test file 2023-05-09 13:48:12 -05:00
5d0571abfa fix pins of added servos 2023-05-09 13:47:56 -05:00
fc3870c5ba start work with real oliver proto. fix motor driver shim, add very basic motor scaling. 2023-05-08 00:22:33 -05:00
563d82c5f9 Listen on all ips for now 2022-11-02 11:58:58 -05:00
104e7cf0fb Very hacky dark-mode-only compatibility 2022-11-02 11:47:05 -05:00
997cb7cb30 Make app mostly usable in dark mode 2022-11-02 11:34:23 -05:00
565c574e73 update config to include laser XSHUT pins 2022-11-02 10:50:31 -05:00
2c291ed2e6 update android shit 2022-11-02 10:43:57 -05:00
977b922552 add comment 2022-10-21 21:54:50 -05:00
9fb38a8a10 comment adafruit fakelib 2022-10-21 21:46:22 -05:00
17 changed files with 299 additions and 98 deletions

View File

@ -0,0 +1,123 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="XML">
<option name="FORCE_REARRANGE_MODE" value="1" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
<arrangement>
<rules>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:android</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:id</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>style</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>ANDROID_ATTRIBUTE_ORDER</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>.*</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</codeStyleSettings>
</code_scheme>
</component>

View File

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="CompilerConfiguration"> <component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" /> <bytecodeTargetLevel target="17" />
</component> </component>
</project> </project>

View File

@ -7,6 +7,7 @@
<option name="testRunner" value="GRADLE" /> <option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" /> <option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="Embedded JDK" />
<option name="modules"> <option name="modules">
<set> <set>
<option value="$PROJECT_DIR$" /> <option value="$PROJECT_DIR$" />

6
software/android/.idea/kotlinc.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="KotlinJpsPluginSettings">
<option name="version" value="1.6.21" />
</component>
</project>

View File

@ -29,10 +29,13 @@
</map> </map>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Android Studio default JDK" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">
<option name="id" value="Android" /> <option name="id" value="Android" />
</component> </component>
<component name="SuppressKotlinCodeStyleNotification">
<option name="disableForAll" value="true" />
</component>
</project> </project>

View File

@ -13,18 +13,19 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:background="@color/black"
> android:orientation="vertical">
<TextView <TextView
android:id="@+id/title_paired_devices" android:id="@+id/title_paired_devices"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/black"
android:padding="24dp" android:padding="24dp"
android:textAppearance="?attr/textAppearanceHeadline6"
android:text="Select a Device" android:text="Select a Device"
android:visibility="visible" android:textAppearance="?attr/textAppearanceHeadline6"
/> android:textColor="@color/white"
android:visibility="visible" />
<View <View
android:id="@+id/divider" android:id="@+id/divider"
@ -36,8 +37,9 @@
android:id="@+id/paired_devices" android:id="@+id/paired_devices"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:stackFromBottom="false" android:background="@color/black"
/> android:listSelector="@color/grey_800"
android:stackFromBottom="false" />
<View <View
android:id="@+id/divider1" android:id="@+id/divider1"
@ -49,14 +51,13 @@
android:id="@+id/cancel_picker" android:id="@+id/cancel_picker"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="24dp" android:background="?attr/selectableItemBackground"
android:textAppearance="?attr/textAppearanceButton"
android:gravity="center_horizontal"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:background="?attr/selectableItemBackground" android:gravity="center_horizontal"
android:padding="24dp"
android:text="Cancel" android:text="Cancel"
android:visibility="visible" android:textAppearance="?attr/textAppearanceButton"
/> android:visibility="visible" />
</LinearLayout> </LinearLayout>

View File

@ -18,11 +18,12 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/white" android:background="@color/white"
android:elevation="8dp"
android:forceDarkAllowed="false"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:orientation="vertical" android:orientation="vertical"
android:paddingStart="16dp" android:paddingStart="16dp"
android:paddingEnd="16dp" android:paddingEnd="16dp">
android:elevation="8dp">
<ImageView <ImageView
android:id="@+id/hexapod_logo" android:id="@+id/hexapod_logo"
@ -50,12 +51,16 @@
android:id="@+id/wifi_tab" android:id="@+id/wifi_tab"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/white"
android:forceDarkAllowed="false"
android:text="WiFi" /> android:text="WiFi" />
<com.google.android.material.tabs.TabItem <com.google.android.material.tabs.TabItem
android:id="@+id/bluetooth_tab" android:id="@+id/bluetooth_tab"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/white"
android:forceDarkAllowed="false"
android:text="Bluetooth" /> android:text="Bluetooth" />
</com.google.android.material.tabs.TabLayout> </com.google.android.material.tabs.TabLayout>
@ -78,6 +83,8 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/grey_500"
android:forceDarkAllowed="false"
android:orientation="vertical"> android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
@ -85,9 +92,10 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="4dp" android:layout_marginBottom="4dp"
android:background="@color/grey_500"
android:paddingStart="16dp" android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingTop="16dp" android:paddingTop="16dp"
android:paddingEnd="16dp"
android:visibility="visible" android:visibility="visible"
app:errorEnabled="true" app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="@id/port_input_layout" app:layout_constraintBottom_toTopOf="@id/port_input_layout"
@ -99,20 +107,23 @@
android:id="@+id/ip_input" android:id="@+id/ip_input"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/grey_500"
android:digits="0123456789." android:digits="0123456789."
android:backgroundTint="@color/grey_100" android:forceDarkAllowed="false"
android:hint="IP" android:hint="IP"
android:inputType="number|numberDecimal" android:inputType="number|numberDecimal"
android:text="192.168.1.127" /> android:text="192.168.1.127"
android:textColor="@android:color/primary_text_light" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/port_input_layout" android:id="@+id/port_input_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:background="@color/grey_500"
android:paddingStart="16dp" android:paddingStart="16dp"
android:paddingEnd="16dp" android:paddingEnd="16dp"
android:layout_marginBottom="4dp"
android:visibility="visible" android:visibility="visible"
app:errorEnabled="true" app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="@id/paired_devices" app:layout_constraintBottom_toTopOf="@id/paired_devices"
@ -124,10 +135,12 @@
android:id="@+id/port_input" android:id="@+id/port_input"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:backgroundTint="@color/grey_100" android:background="@color/grey_500"
android:forceDarkAllowed="false"
android:hint="Port" android:hint="Port"
android:inputType="number" android:inputType="number"
android:text="1234" /> android:text="1234"
android:textColor="@android:color/primary_text_light" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>

View File

@ -4,9 +4,10 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/grey_500"
android:clickable="true" android:clickable="true"
android:focusable="true" android:focusable="true"
android:background="?android:attr/selectableItemBackground" android:forceDarkAllowed="false"
android:paddingTop="16dp" android:paddingTop="16dp"
android:paddingBottom="16dp"> android:paddingBottom="16dp">
@ -16,17 +17,17 @@
android:layout_height="64dp" android:layout_height="64dp"
android:padding="16dp" android:padding="16dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/textView_device_name"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@+id/textView_device_name"
app:srcCompat="@drawable/ic_baseline_bluetooth_24" /> app:srcCompat="@drawable/ic_baseline_bluetooth_24" />
<TextView <TextView
android:id="@+id/textView_device_name" android:id="@+id/textView_device_name"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?attr/textAppearanceBody1"
android:text="TextView" android:text="TextView"
android:textAppearance="?attr/textAppearanceBody1"
app:layout_constraintBottom_toTopOf="@+id/textView_device_mac" app:layout_constraintBottom_toTopOf="@+id/textView_device_mac"
app:layout_constraintStart_toEndOf="@+id/imageView" app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
@ -36,8 +37,8 @@
android:id="@+id/textView_device_mac" android:id="@+id/textView_device_mac"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?attr/textAppearanceCaption"
android:text="TextView" android:text="TextView"
android:textAppearance="?attr/textAppearanceCaption"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView" app:layout_constraintStart_toEndOf="@+id/imageView"
app:layout_constraintTop_toBottomOf="@+id/textView_device_name" /> app:layout_constraintTop_toBottomOf="@+id/textView_device_name" />

View File

@ -1,10 +1,8 @@
## This file is automatically generated by Android Studio. ## This file must *NOT* be checked into Version Control Systems,
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file should *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration. # as it contains information specific to your local configuration.
# #
# Location of the SDK. This is only used by Gradle. # Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the # For customization when using a Version Control System, please read the
# header note. # header note.
sdk.dir=C\:\\Users\\rooki\\AppData\\Local\\Android\\Sdk #Fri Oct 21 23:04:27 CDT 2022
sdk.dir=/home/cole/Android/Sdk

View File

@ -3,7 +3,8 @@
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
# #
# MODIFIED to use pololu motor drivers, but compatible with adafruit_servokit driver layout # MODIFIED to use pololu motor drivers, but compatible with adafruit_servokit driver layout
# by Cole Deck # by Amelia Deck
# Based on adafruit_motor.py as well
""" """
`adafruit_servokit` `adafruit_servokit`
@ -41,6 +42,7 @@ Implementation Notes
try: try:
from typing import Optional from typing import Optional
import maestro import maestro
import time
#from busio import I2C #from busio import I2C
#from adafruit_motor.servo import Servo, ContinuousServo #from adafruit_motor.servo import Servo, ContinuousServo
except ImportError: except ImportError:
@ -83,7 +85,7 @@ class ServoKit:
#i2c: Optional[I2C] = None, #i2c: Optional[I2C] = None,
address: str = "/dev/ttyACM0", address: str = "/dev/ttyACM0",
reference_clock_speed: int = 25000000, reference_clock_speed: int = 25000000,
frequency: int = 50 # actually, device ID over serial pololu protocol frequency: int = 50 # actually, device ID over serial pololu protocol. using existing var names for full compatibility!
) -> None: ) -> None:
if channels not in [6, 12, 18, 24]: if channels not in [6, 12, 18, 24]:
raise ValueError("servo_channels must be 6, 12, 18, 24!") raise ValueError("servo_channels must be 6, 12, 18, 24!")
@ -134,6 +136,7 @@ class _Servo:
if servo_channel >= num_channels or servo_channel < 0: if servo_channel >= num_channels or servo_channel < 0:
raise ValueError("servo must be 0-{}!".format(num_channels - 1)) raise ValueError("servo must be 0-{}!".format(num_channels - 1))
servo = pololuservo(servo_channel) servo = pololuservo(servo_channel)
return servo return servo
raise ValueError("Channel {} is already in use.".format(servo_channel)) raise ValueError("Channel {} is already in use.".format(servo_channel))
@ -141,13 +144,19 @@ class _Servo:
return len(self.kit._items) return len(self.kit._items)
class pololuservo: class pololuservo:
def __init__(self, ch, actuation_range: int = 180, min_pulse: int = 3000, max_pulse: int = 9000): def __init__(self, ch, actuation_range: int = 180, min_pulse: int = 1600, max_pulse: int = 9900):
self.ch = ch self.ch = ch
self.actuation_range = actuation_range self.actuation_range = actuation_range
self._min_duty = min_pulse self._min_duty = min_pulse
self._max_duty = max_pulse self._max_duty = max_pulse
self._duty_range = max_pulse = min_pulse self._duty_range = max_pulse - min_pulse
self.duty_cycle = 0 self.duty_cycle = 0
print("init servo", ch)
pca.setAccel(ch, 15)
pca.setTarget(ch, int((max_pulse-min_pulse)/2 + min_pulse)) # set midpoint
time.sleep(0.1)
pca.setAccel(ch, 0)
@property @property
def angle(self) -> Optional[float]: def angle(self) -> Optional[float]:
@ -158,7 +167,7 @@ class pololuservo:
return self.actuation_range * self.fraction return self.actuation_range * self.fraction
@angle.setter @angle.setter
def angle(self, new_angle: Optional[int]) -> None: def angle(self, new_angle: Optional[float]) -> None:
if new_angle is None: # disable the servo by sending 0 signal if new_angle is None: # disable the servo by sending 0 signal
self.fraction = None self.fraction = None
return return
@ -184,7 +193,14 @@ class pololuservo:
return return
if not 0.0 <= value <= 1.0: if not 0.0 <= value <= 1.0:
raise ValueError("Must be 0.0 to 1.0") raise ValueError("Must be 0.0 to 1.0")
#if self.ch > 2 and self.ch < 6:
# valuetmp = 1.0 - value
# self.duty_cycle = self._min_duty + int(valuetmp * self._duty_range)
#else:
self.duty_cycle = self._min_duty + int(value * self._duty_range) self.duty_cycle = self._min_duty + int(value * self._duty_range)
#print(self.ch) #print(self.ch)
pca.setTarget(self.ch,self.duty_cycle) #if self.ch == 0:
#print(value)
pca.setTarget(self.ch,int(self.duty_cycle))
time.sleep(0.002)
#self._pwm_out.duty_cycle = duty_cycle #self._pwm_out.duty_cycle = duty_cycle

View File

@ -49,7 +49,7 @@ class BluetoothServer(Thread):
self.cmd_queue = out_cmd_queue self.cmd_queue = out_cmd_queue
with open('/home/cole/Downloads/hexapod/software/raspberry pi/config.json', 'r') as read_file: with open('config.json', 'r') as read_file:
self.config = json.load(read_file) self.config = json.load(read_file)
try: try:

View File

@ -38,39 +38,39 @@
"movementInterval": 5, "movementInterval": 5,
"movementSwitchDuration": 150, "movementSwitchDuration": 150,
"leg0Offset": [ "leg0Offset": [
4.0, 10,
6.0, 10,
2 30
], ],
"leg0Scale": [ "leg0Scale": [
1, 1,
1, -1,
1 -1
], ],
"leg1Offset": [ "leg1Offset": [
-1.0, 15,
8, -20,
-6 35
], ],
"leg1Scale": [ "leg1Scale": [
1, 1,
1, -1,
1 -1
], ],
"leg2Offset": [ "leg2Offset": [
1.0, -3,
12.0, 10,
1.0 20
], ],
"leg2Scale": [ "leg2Scale": [
1, 1,
1, -1,
1 -1
], ],
"leg3Offset": [ "leg3Offset": [
-3, 7,
12.0, 15,
-6.0 -10
], ],
"leg3Scale": [ "leg3Scale": [
1, 1,
@ -78,9 +78,9 @@
1 1
], ],
"leg4Offset": [ "leg4Offset": [
-6, 15,
2, 10,
-6.0 5
], ],
"leg4Scale": [ "leg4Scale": [
1, 1,
@ -88,13 +88,20 @@
1 1
], ],
"leg5Offset": [ "leg5Offset": [
0, -7,
4.0, 10,
-10 -30
], ],
"leg5Scale": [ "leg5Scale": [
1, 1,
1, 1,
1 1
] ],
"leg0Laser": 17,
"leg1Laser": 27,
"leg2Laser": 22,
"leg3Laser": 10,
"leg4Laser": 9,
"leg5Laser": 11
} }

View File

@ -1,4 +1,4 @@
#!python #!/usr/bin/python3
# #
# 2021 - PRESENT Zhengyu Peng # 2021 - PRESENT Zhengyu Peng
# Website: https://zpeng.me # Website: https://zpeng.me
@ -93,7 +93,7 @@ class Hexapod(Thread):
self.calibration_mode = False self.calibration_mode = False
with open('/home/cole/Downloads/hexapod/software/raspberry pi/config.json', 'r') as read_file: with open('config.json', 'r') as read_file:
self.config = json.load(read_file) self.config = json.load(read_file)
# legs' coordinates # legs' coordinates
@ -116,40 +116,40 @@ class Hexapod(Thread):
self.mount_position[:, 1] = self.mount_y self.mount_position[:, 1] = self.mount_y
# Objects # Objects
self.pca_right = ServoKit(channels=18, address="/dev/ttyUSB0", frequency=0x0c) self.pca_right = ServoKit(channels=18, address="/dev/serial/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.4:1.0", frequency=0x0c)
self.pca_left = ServoKit(channels=18, address="/dev/ttyUSB0", frequency=0x0d) self.pca_left = ServoKit(channels=18, address="/dev/serial/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.3:1.0", frequency=0x0d)
#self.pca_left = self.pca_right
self.legs = [ self.legs = [
# front right # front right
Leg(0, Leg(0,
[self.pca_left.servo[15], self.pca_left.servo[14],
self.pca_left.servo[13]],
correction=self.config.get('leg0Offset', [0, 0, 0])),
# center right
Leg(1,
[self.pca_left.servo[8], self.pca_left.servo[4],
self.pca_left.servo[11]],
correction=self.config.get('leg1Offset', [0, 0, 0])),
# rear right
Leg(2,
[self.pca_left.servo[0], self.pca_left.servo[1], [self.pca_left.servo[0], self.pca_left.servo[1],
self.pca_left.servo[2]], self.pca_left.servo[2]],
correction=self.config.get('leg2Offset', [0, 0, 0])), correction=self.config.get('leg0Offset', [0, 0, 0]), scale=self.config.get('leg0Scale', [1, 1, 1])),
# center right
Leg(1,
[self.pca_left.servo[3], self.pca_left.servo[4],
self.pca_left.servo[5]],
correction=self.config.get('leg1Offset', [0, 0, 0]), scale=self.config.get('leg1Scale', [1, 1, 1])),
# rear right
Leg(2,
[self.pca_left.servo[6], self.pca_left.servo[7],
self.pca_left.servo[8]],
correction=self.config.get('leg2Offset', [0, 0, 0]), scale=self.config.get('leg2Scale', [1, 1, 1])),
# rear left # rear left
Leg(3, Leg(3,
[self.pca_right.servo[15], self.pca_right.servo[14], [self.pca_right.servo[6], self.pca_right.servo[7],
self.pca_right.servo[13]], self.pca_right.servo[8]],
correction=self.config.get('leg3Offset', [0, 0, 0])), correction=self.config.get('leg3Offset', [0, 0, 0]), scale=self.config.get('leg3Scale', [1, 1, 1])),
# center left # center left
Leg(4, Leg(4,
[self.pca_right.servo[7], self.pca_right.servo[11], [self.pca_right.servo[3], self.pca_right.servo[4],
self.pca_right.servo[6]], self.pca_right.servo[5]],
correction=self.config.get('leg4Offset', [0, 0, 0])), correction=self.config.get('leg4Offset', [0, 0, 0]), scale=self.config.get('leg4Scale', [1, 1, 1])),
# front left # front left
Leg(5, Leg(5,
[self.pca_right.servo[0], self.pca_right.servo[2], [self.pca_right.servo[0], self.pca_right.servo[1],
self.pca_right.servo[5]], self.pca_right.servo[2]],
correction=self.config.get('leg5Offset', [0, 0, 0]))] correction=self.config.get('leg5Offset', [0, 0, 0]), scale=self.config.get('leg5Scale', [1, 1, 1]))]
# self.leg_0.reset(True) # self.leg_0.reset(True)
# self.leg_1.reset(True) # self.leg_1.reset(True)
@ -263,7 +263,7 @@ class Hexapod(Thread):
try: try:
cmd_string = self.cmd_queue.get(block=False) cmd_string = self.cmd_queue.get(block=False)
print('interrput') print('interrupt')
except Empty: except Empty:
# time.sleep(self.interval) # time.sleep(self.interval)
pass pass
@ -300,7 +300,6 @@ class Hexapod(Thread):
angles[:, 1] = 90-((ar + a1) * 180 / np.pi) angles[:, 1] = 90-((ar + a1) * 180 / np.pi)
angles[:, 2] = (90 - ((a1 + a2) * 180 / np.pi))+90 angles[:, 2] = (90 - ((a1 + a2) * 180 / np.pi))+90
return angles return angles
def cmd_handler(self, cmd_string): def cmd_handler(self, cmd_string):
@ -352,7 +351,7 @@ class Hexapod(Thread):
def save_config(self): def save_config(self):
try: try:
json.dump(self.config, open( json.dump(self.config, open(
'/home/pi/hexapod/software/raspberry pi/config.json', 'w+'), indent=4) '/home/amelia/hexapod/software/raspberry pi/config2.json', 'w+'), indent=4)
except PermissionError as err: except PermissionError as err:
pass pass

View File

@ -38,6 +38,7 @@ class Leg:
self.junction_servos = junction_servos self.junction_servos = junction_servos
self.correction = correction self.correction = correction
self.constraint = constraint self.constraint = constraint
self.scale = scale
def set_angle(self, junction, angle): def set_angle(self, junction, angle):
set_angle = np.min( set_angle = np.min(
@ -50,8 +51,19 @@ class Leg:
self.junction_servos[junction].angle = angle self.junction_servos[junction].angle = angle
def move_junctions(self, angles): def move_junctions(self, angles):
if self.scale[0] < 0:
self.set_angle(0, self.constraint[0][1] + self.constraint[0][0] - angles[0])
#print(self.scale, self.constraint[0][1] + self.constraint[0][0] - angles[0])
else:
self.set_angle(0, angles[0]) self.set_angle(0, angles[0])
#print(self.scale, angles[0])
if self.scale[1] < 0:
self.set_angle(1, self.constraint[1][1] + self.constraint[1][0] - angles[1])
else:
self.set_angle(1, angles[1]) self.set_angle(1, angles[1])
if self.scale[2] < 0:
self.set_angle(2, self.constraint[2][1] + self.constraint[2][0] - angles[2])
else:
self.set_angle(2, angles[2]) self.set_angle(2, angles[2])
def reset(self, calibrated=False): def reset(self, calibrated=False):

View File

@ -47,10 +47,10 @@ class TCPServer(Thread):
self.cmd_queue = out_cmd_queue self.cmd_queue = out_cmd_queue
with open('/home/cole/Downloads/hexapod/software/raspberry pi/config.json', 'r') as read_file: with open('config.json', 'r') as read_file:
self.config = json.load(read_file) self.config = json.load(read_file)
self.ip = '192.168.1.127' self.ip = '0.0.0.0'
self.port = 1234 self.port = 1234
self.tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

View File

@ -0,0 +1,16 @@
import maestro
servo = maestro.Controller()
import time
print("1")
for i in range(18):
servo.setAccel(i,10) #set servo 0 acceleration to 4
servo.setSpeed(i,50) #set speed of servo 1
servo.setTarget(i,6000) #set servo to move to center position
time.sleep(1)
#servo.setTarget(0,6000)
#x = servo.getPosition(1) #get the current position of servo 1
print("5")
#servo.close()
print("6")